@@ -19,7 +19,6 @@ use rustc_middle::mir::mono::MonoItem;
19
19
use rustc_middle:: ty:: { self , Instance , Ty } ;
20
20
use rustc_middle:: { bug, span_bug} ;
21
21
use rustc_span:: symbol:: sym;
22
- use rustc_span:: Span ;
23
22
use rustc_target:: abi:: { AddressSpace , Align , HasDataLayout , LayoutOf , Primitive , Scalar , Size } ;
24
23
use tracing:: debug;
25
24
@@ -110,7 +109,7 @@ fn check_and_apply_linkage(
110
109
attrs : & CodegenFnAttrs ,
111
110
ty : Ty < ' tcx > ,
112
111
sym : & str ,
113
- span : Span ,
112
+ span_def_id : DefId ,
114
113
) -> & ' ll Value {
115
114
let llty = cx. layout_of ( ty) . llvm_type ( cx) ;
116
115
if let Some ( linkage) = attrs. linkage {
@@ -125,7 +124,7 @@ fn check_and_apply_linkage(
125
124
cx. layout_of ( mt. ty ) . llvm_type ( cx)
126
125
} else {
127
126
cx. sess ( ) . span_fatal (
128
- span ,
127
+ cx . tcx . def_span ( span_def_id ) ,
129
128
"must have type `*const T` or `*mut T` due to `#[linkage]` attribute" ,
130
129
)
131
130
} ;
@@ -143,7 +142,10 @@ fn check_and_apply_linkage(
143
142
let mut real_name = "_rust_extern_with_linkage_" . to_string ( ) ;
144
143
real_name. push_str ( & sym) ;
145
144
let g2 = cx. define_global ( & real_name, llty) . unwrap_or_else ( || {
146
- cx. sess ( ) . span_fatal ( span, & format ! ( "symbol `{}` is already defined" , & sym) )
145
+ cx. sess ( ) . span_fatal (
146
+ cx. tcx . def_span ( span_def_id) ,
147
+ & format ! ( "symbol `{}` is already defined" , & sym) ,
148
+ )
147
149
} ) ;
148
150
llvm:: LLVMRustSetLinkage ( g2, llvm:: Linkage :: InternalLinkage ) ;
149
151
llvm:: LLVMSetInitializer ( g2, g1) ;
@@ -210,21 +212,21 @@ impl CodegenCx<'ll, 'tcx> {
210
212
211
213
debug ! ( "get_static: sym={} instance={:?}" , sym, instance) ;
212
214
213
- let g = if let Some ( def_id ) = def_id. as_local ( ) {
214
- let id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id ) ;
215
+ let g = if let Some ( local_def_id ) = def_id. as_local ( ) {
216
+ let id = self . tcx . hir ( ) . local_def_id_to_hir_id ( local_def_id ) ;
215
217
let llty = self . layout_of ( ty) . llvm_type ( self ) ;
216
218
// FIXME: refactor this to work without accessing the HIR
217
219
let ( g, attrs) = match self . tcx . hir ( ) . get ( id) {
218
- Node :: Item ( & hir:: Item { attrs, span , kind : hir:: ItemKind :: Static ( ..) , .. } ) => {
220
+ Node :: Item ( & hir:: Item { attrs, kind : hir:: ItemKind :: Static ( ..) , .. } ) => {
219
221
if let Some ( g) = self . get_declared_value ( sym) {
220
222
if self . val_ty ( g) != self . type_ptr_to ( llty) {
221
- span_bug ! ( span , "Conflicting types for static" ) ;
223
+ span_bug ! ( self . tcx . def_span ( def_id ) , "Conflicting types for static" ) ;
222
224
}
223
225
}
224
226
225
227
let g = self . declare_global ( sym, llty) ;
226
228
227
- if !self . tcx . is_reachable_non_generic ( def_id ) {
229
+ if !self . tcx . is_reachable_non_generic ( local_def_id ) {
228
230
unsafe {
229
231
llvm:: LLVMRustSetVisibility ( g, llvm:: Visibility :: Hidden ) ;
230
232
}
@@ -235,12 +237,11 @@ impl CodegenCx<'ll, 'tcx> {
235
237
236
238
Node :: ForeignItem ( & hir:: ForeignItem {
237
239
ref attrs,
238
- span,
239
240
kind : hir:: ForeignItemKind :: Static ( ..) ,
240
241
..
241
242
} ) => {
242
- let fn_attrs = self . tcx . codegen_fn_attrs ( def_id ) ;
243
- ( check_and_apply_linkage ( & self , & fn_attrs, ty, sym, span ) , & * * attrs)
243
+ let fn_attrs = self . tcx . codegen_fn_attrs ( local_def_id ) ;
244
+ ( check_and_apply_linkage ( & self , & fn_attrs, ty, sym, def_id ) , & * * attrs)
244
245
}
245
246
246
247
item => bug ! ( "get_static: expected static, found {:?}" , item) ,
@@ -260,8 +261,7 @@ impl CodegenCx<'ll, 'tcx> {
260
261
debug ! ( "get_static: sym={} item_attr={:?}" , sym, self . tcx. item_attrs( def_id) ) ;
261
262
262
263
let attrs = self . tcx . codegen_fn_attrs ( def_id) ;
263
- let span = self . tcx . def_span ( def_id) ;
264
- let g = check_and_apply_linkage ( & self , & attrs, ty, sym, span) ;
264
+ let g = check_and_apply_linkage ( & self , & attrs, ty, sym, def_id) ;
265
265
266
266
// Thread-local statics in some other crate need to *always* be linked
267
267
// against in a thread-local fashion, so we need to be sure to apply the
0 commit comments