This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
compiler/rustc_const_eval/src/interpret Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ use rustc_ast::Mutability;
1818use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
1919use rustc_errors:: ErrorGuaranteed ;
2020use rustc_hir as hir;
21+ use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
2122use rustc_middle:: mir:: interpret:: { ConstAllocation , CtfeProvenance , InterpResult } ;
2223use rustc_middle:: query:: TyCtxtAt ;
2324use rustc_middle:: ty:: layout:: TyAndLayout ;
@@ -106,13 +107,17 @@ fn intern_as_new_static<'tcx>(
106107 DefKind :: Static { mutability : alloc. 0 . mutability , nested : true } ,
107108 ) ;
108109 tcx. set_nested_alloc_id_static ( alloc_id, feed. def_id ( ) ) ;
109- feed. codegen_fn_attrs ( tcx. codegen_fn_attrs ( static_id) . clone ( ) ) ;
110+
111+ // These do not inherit the codegen attrs of the parent static allocation, since
112+ // it doesn't make sense for them to inherit their `#[no_mangle]` and `#[link_name = ..]`
113+ // and the like.
114+ feed. codegen_fn_attrs ( CodegenFnAttrs :: new ( ) ) ;
115+
110116 feed. eval_static_initializer ( Ok ( alloc) ) ;
111117 feed. generics_of ( tcx. generics_of ( static_id) . clone ( ) ) ;
112118 feed. def_ident_span ( tcx. def_ident_span ( static_id) ) ;
113119 feed. explicit_predicates_of ( tcx. explicit_predicates_of ( static_id) ) ;
114-
115- feed. feed_hir ( )
120+ feed. feed_hir ( ) ;
116121}
117122
118123/// How a constant value should be interned.
Original file line number Diff line number Diff line change 1+ //@ build-pass
2+
3+ // Make sure that the nested static allocation for `FOO` doesn't inherit `no_mangle`.
4+ #[ no_mangle]
5+ pub static mut FOO : & mut [ i32 ] = & mut [ 42 ] ;
6+
7+ // Make sure that the nested static allocation for `BAR` doesn't inherit `export_name`.
8+ #[ export_name = "BAR_" ]
9+ pub static mut BAR : & mut [ i32 ] = & mut [ 42 ] ;
10+
11+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments