about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-05-12 14:22:12 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-05-13 14:34:32 +0000
commit531dae1cdfaea537f7f1d5ff7db6bd2adb4d414a (patch)
treec82c72d6881e57e7cf110824f83e8a9fe247e444 /compiler/rustc_codegen_ssa/src
parentb71fa82d786ae1b5866510f1b3a7e5b7e1890e4c (diff)
downloadrust-531dae1cdfaea537f7f1d5ff7db6bd2adb4d414a.tar.gz
rust-531dae1cdfaea537f7f1d5ff7db6bd2adb4d414a.zip
Only allow immutable statics with #[linkage]
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-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 c28b0d644e6..b479b037668 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 => {