about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
diff options
context:
space:
mode:
authorJubilee <46493976+workingjubilee@users.noreply.github.com>2024-05-26 15:28:26 -0700
committerGitHub <noreply@github.com>2024-05-26 15:28:26 -0700
commit5860d43af38fe1160835d72874fd35e0186be10e (patch)
treed2ac0612249d92618e5d259531d8a601edbd0f93 /compiler/rustc_codegen_ssa
parent866630d0041f35269836e59481acaacba28a8f41 (diff)
parent531dae1cdfaea537f7f1d5ff7db6bd2adb4d414a (diff)
downloadrust-5860d43af38fe1160835d72874fd35e0186be10e.tar.gz
rust-5860d43af38fe1160835d72874fd35e0186be10e.zip
Rollup merge of #125046 - bjorn3:no_mutable_static_linkage, r=cjgillot
Only allow immutable statics with #[linkage]
Diffstat (limited to 'compiler/rustc_codegen_ssa')
-rw-r--r--compiler/rustc_codegen_ssa/src/codegen_attrs.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
index 9bf055b1739..e3e513084ea 100644
--- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
+++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
@@ -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 => {