@@ -102,7 +102,7 @@ fn check_and_apply_linkage(
102
102
attrs : & CodegenFnAttrs ,
103
103
ty : Ty < ' tcx > ,
104
104
sym : LocalInternedString ,
105
- span : Option < Span >
105
+ span : Span
106
106
) -> & ' ll Value {
107
107
let llty = cx. layout_of ( ty) . llvm_type ( cx) ;
108
108
if let Some ( linkage) = attrs. linkage {
@@ -116,11 +116,8 @@ fn check_and_apply_linkage(
116
116
let llty2 = if let ty:: RawPtr ( ref mt) = ty. sty {
117
117
cx. layout_of ( mt. ty ) . llvm_type ( cx)
118
118
} else {
119
- if let Some ( span) = span {
120
- cx. sess ( ) . span_fatal ( span, "must have type `*const T` or `*mut T`" )
121
- } else {
122
- bug ! ( "must have type `*const T` or `*mut T`" )
123
- }
119
+ cx. sess ( ) . span_fatal (
120
+ span, "must have type `*const T` or `*mut T` due to `#[linkage]` attribute" )
124
121
} ;
125
122
unsafe {
126
123
// Declare a symbol `foo` with the desired linkage.
@@ -136,14 +133,7 @@ fn check_and_apply_linkage(
136
133
let mut real_name = "_rust_extern_with_linkage_" . to_string ( ) ;
137
134
real_name. push_str ( & sym) ;
138
135
let g2 = cx. define_global ( & real_name, llty) . unwrap_or_else ( ||{
139
- if let Some ( span) = span {
140
- cx. sess ( ) . span_fatal (
141
- span,
142
- & format ! ( "symbol `{}` is already defined" , & sym)
143
- )
144
- } else {
145
- bug ! ( "symbol `{}` is already defined" , & sym)
146
- }
136
+ cx. sess ( ) . span_fatal ( span, & format ! ( "symbol `{}` is already defined" , & sym) )
147
137
} ) ;
148
138
llvm:: LLVMRustSetLinkage ( g2, llvm:: Linkage :: InternalLinkage ) ;
149
139
llvm:: LLVMSetInitializer ( g2, g1) ;
@@ -240,7 +230,7 @@ impl CodegenCx<'ll, 'tcx> {
240
230
ref attrs, span, node : hir:: ForeignItemKind :: Static ( ..) , ..
241
231
} ) => {
242
232
let fn_attrs = self . tcx . codegen_fn_attrs ( def_id) ;
243
- ( check_and_apply_linkage ( & self , & fn_attrs, ty, sym, Some ( span) ) , attrs)
233
+ ( check_and_apply_linkage ( & self , & fn_attrs, ty, sym, span) , attrs)
244
234
}
245
235
246
236
item => bug ! ( "get_static: expected static, found {:?}" , item)
@@ -260,7 +250,8 @@ impl CodegenCx<'ll, 'tcx> {
260
250
debug ! ( "get_static: sym={} item_attr={:?}" , sym, self . tcx. item_attrs( def_id) ) ;
261
251
262
252
let attrs = self . tcx . codegen_fn_attrs ( def_id) ;
263
- let g = check_and_apply_linkage ( & self , & attrs, ty, sym, None ) ;
253
+ let span = self . tcx . def_span ( def_id) ;
254
+ let g = check_and_apply_linkage ( & self , & attrs, ty, sym, span) ;
264
255
265
256
// Thread-local statics in some other crate need to *always* be linked
266
257
// against in a thread-local fashion, so we need to be sure to apply the
0 commit comments