@@ -19,7 +19,6 @@ use rustc_middle::mir::mono::MonoItem;
1919use rustc_middle:: ty:: { self , Instance , Ty } ;
2020use rustc_middle:: { bug, span_bug} ;
2121use rustc_span:: symbol:: sym;
22- use rustc_span:: Span ;
2322use rustc_target:: abi:: { AddressSpace , Align , HasDataLayout , LayoutOf , Primitive , Scalar , Size } ;
2423use tracing:: debug;
2524
@@ -110,7 +109,7 @@ fn check_and_apply_linkage(
110109 attrs : & CodegenFnAttrs ,
111110 ty : Ty < ' tcx > ,
112111 sym : & str ,
113- span : Span ,
112+ span_def_id : DefId ,
114113) -> & ' ll Value {
115114 let llty = cx. layout_of ( ty) . llvm_type ( cx) ;
116115 if let Some ( linkage) = attrs. linkage {
@@ -125,7 +124,7 @@ fn check_and_apply_linkage(
125124 cx. layout_of ( mt. ty ) . llvm_type ( cx)
126125 } else {
127126 cx. sess ( ) . span_fatal (
128- span ,
127+ cx . tcx . def_span ( span_def_id ) ,
129128 "must have type `*const T` or `*mut T` due to `#[linkage]` attribute" ,
130129 )
131130 } ;
@@ -143,7 +142,10 @@ fn check_and_apply_linkage(
143142 let mut real_name = "_rust_extern_with_linkage_" . to_string ( ) ;
144143 real_name. push_str ( & sym) ;
145144 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+ )
147149 } ) ;
148150 llvm:: LLVMRustSetLinkage ( g2, llvm:: Linkage :: InternalLinkage ) ;
149151 llvm:: LLVMSetInitializer ( g2, g1) ;
@@ -210,21 +212,21 @@ impl CodegenCx<'ll, 'tcx> {
210212
211213 debug ! ( "get_static: sym={} instance={:?}" , sym, instance) ;
212214
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 ) ;
215217 let llty = self . layout_of ( ty) . llvm_type ( self ) ;
216218 // FIXME: refactor this to work without accessing the HIR
217219 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 ( ..) , .. } ) => {
219221 if let Some ( g) = self . get_declared_value ( sym) {
220222 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" ) ;
222224 }
223225 }
224226
225227 let g = self . declare_global ( sym, llty) ;
226228
227- if !self . tcx . is_reachable_non_generic ( def_id ) {
229+ if !self . tcx . is_reachable_non_generic ( local_def_id ) {
228230 unsafe {
229231 llvm:: LLVMRustSetVisibility ( g, llvm:: Visibility :: Hidden ) ;
230232 }
@@ -235,12 +237,11 @@ impl CodegenCx<'ll, 'tcx> {
235237
236238 Node :: ForeignItem ( & hir:: ForeignItem {
237239 ref attrs,
238- span,
239240 kind : hir:: ForeignItemKind :: Static ( ..) ,
240241 ..
241242 } ) => {
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)
244245 }
245246
246247 item => bug ! ( "get_static: expected static, found {:?}" , item) ,
@@ -260,8 +261,7 @@ impl CodegenCx<'ll, 'tcx> {
260261 debug ! ( "get_static: sym={} item_attr={:?}" , sym, self . tcx. item_attrs( def_id) ) ;
261262
262263 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) ;
265265
266266 // Thread-local statics in some other crate need to *always* be linked
267267 // against in a thread-local fashion, so we need to be sure to apply the
0 commit comments