about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-05 11:32:18 +0000
committerbors <bors@rust-lang.org>2024-06-05 11:32:18 +0000
commitdb8aca48129d86b2623e3ac8cbcf2902d4d313ad (patch)
tree637294c8b1a43817f408a70a5da24d9b64d672a4 /compiler/rustc_codegen_ssa/src/codegen_attrs.rs
parent5ee2dfd2bcbb66a69a46aaa342204e0dfdb70516 (diff)
parentf12fe3a33e5e94f1f49cd6d4a785d1cf7a0a02b9 (diff)
downloadrust-db8aca48129d86b2623e3ac8cbcf2902d4d313ad.tar.gz
rust-db8aca48129d86b2623e3ac8cbcf2902d4d313ad.zip
Auto merge of #126016 - workingjubilee:rollup-nh6ehbz, r=workingjubilee
Rollup of 12 pull requests

Successful merges:

 - #123168 (Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude)
 - #125273 (bootstrap: implement new feature `bootstrap-self-test`)
 - #125683 (Rewrite `suspicious-library`, `resolve-rename` and `incr-prev-body-beyond-eof` `run-make` tests in `rmake.rs` format)
 - #125815 (`rustc_parse` top-level cleanups)
 - #125903 (rustc_span: Inline some hot functions)
 - #125906 (Remove a bunch of redundant args from `report_method_error`)
 - #125920 (Allow static mut definitions with #[linkage])
 - #125982 (Make deleting on LinkedList aware of the allocator)
 - #125995 (Use inline const blocks to create arrays of `MaybeUninit`.)
 - #125996 (Closures are recursively reachable)
 - #126003 (Add a co-maintainer for the two ARMv4T targets)
 - #126004 (Add another test for hidden types capturing lifetimes that outlive but arent mentioned in substs)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/codegen_attrs.rs')
-rw-r--r--compiler/rustc_codegen_ssa/src/codegen_attrs.rs25
1 files changed, 13 insertions, 12 deletions
diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
index 5d7257b15c4..15955170e87 100644
--- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
+++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
@@ -324,21 +324,22 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
                     let linkage = Some(linkage_by_name(tcx, did, val.as_str()));
                     if tcx.is_foreign_item(did) {
                         codegen_fn_attrs.import_linkage = linkage;
+
+                        if tcx.is_mutable_static(did.into()) {
+                            let mut diag = tcx.dcx().struct_span_err(
+                                attr.span,
+                                "extern mutable statics are not allowed with `#[linkage]`",
+                            );
+                            diag.note(
+                                "marking the extern static mutable would allow changing which symbol \
+                                 the static references rather than make the target of the symbol \
+                                 mutable",
+                            );
+                            diag.emit();
+                        }
                     } 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 => {