Rollup merge of #125046 - bjorn3:no_mutable_static_linkage, r=cjgillot
Only allow immutable statics with #[linkage]
This commit is contained in:
commit
5860d43af3
4 changed files with 37 additions and 3 deletions
|
@ -327,6 +327,18 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
|||
} else {
|
||||
codegen_fn_attrs.linkage = linkage;
|
||||
}
|
||||
if tcx.is_mutable_static(did.into()) {
|
||||
let mut diag = tcx.dcx().struct_span_err(
|
||||
attr.span,
|
||||
"mutable statics are not allowed with `#[linkage]`",
|
||||
);
|
||||
diag.note(
|
||||
"making the static mutable would allow changing which symbol the \
|
||||
static references rather than make the target of the symbol \
|
||||
mutable",
|
||||
);
|
||||
diag.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
sym::link_section => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue