@@ -211,7 +211,6 @@ impl ExternalCrate {
211
211
/// directly to the AST's concept of an item; it's a strict superset.
212
212
#[ derive( Clone ) ]
213
213
crate struct Item {
214
- crate span : Span ,
215
214
/// The name of this item.
216
215
/// Optional because not every item has a name, e.g. impls.
217
216
crate name : Option < Symbol > ,
@@ -225,14 +224,13 @@ crate struct Item {
225
224
226
225
// `Item` is used a lot. Make sure it doesn't unintentionally get bigger.
227
226
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
228
- rustc_data_structures:: static_assert_size!( Item , 48 ) ;
227
+ rustc_data_structures:: static_assert_size!( Item , 40 ) ;
229
228
230
229
impl fmt:: Debug for Item {
231
230
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
232
231
let def_id: & dyn fmt:: Debug = if self . is_fake ( ) { & "**FAKE**" } else { & self . def_id } ;
233
232
234
233
fmt. debug_struct ( "Item" )
235
- . field ( "source" , & self . span ( ) )
236
234
. field ( "name" , & self . name )
237
235
. field ( "attrs" , & self . attrs )
238
236
. field ( "kind" , & self . kind )
@@ -242,6 +240,16 @@ impl fmt::Debug for Item {
242
240
}
243
241
}
244
242
243
+ crate fn rustc_span ( def_id : DefId , tcx : TyCtxt < ' _ > ) -> Span {
244
+ Span :: from_rustc_span ( def_id. as_local ( ) . map_or_else (
245
+ || tcx. def_span ( def_id) ,
246
+ |local| {
247
+ let hir = tcx. hir ( ) ;
248
+ hir. span_with_body ( hir. local_def_id_to_hir_id ( local) )
249
+ } ,
250
+ ) )
251
+ }
252
+
245
253
impl Item {
246
254
crate fn stability < ' tcx > ( & self , tcx : TyCtxt < ' tcx > ) -> Option < & ' tcx Stability > {
247
255
if self . is_fake ( ) { None } else { tcx. lookup_stability ( self . def_id ) }
@@ -255,12 +263,20 @@ impl Item {
255
263
if self . is_fake ( ) { None } else { tcx. lookup_deprecation ( self . def_id ) }
256
264
}
257
265
258
- crate fn span ( & self ) -> Span {
259
- if let ItemKind :: ModuleItem ( Module { span, .. } ) = & * self . kind { * span } else { self . span }
266
+ crate fn span ( & self , tcx : TyCtxt < ' _ > ) -> Span {
267
+ if let ItemKind :: ModuleItem ( Module { span, .. } ) | ItemKind :: ImplItem ( Impl { span, .. } ) =
268
+ & * self . kind
269
+ {
270
+ * span
271
+ } else if self . is_fake ( ) {
272
+ Span :: dummy ( )
273
+ } else {
274
+ rustc_span ( self . def_id , tcx)
275
+ }
260
276
}
261
277
262
- crate fn attr_span ( & self , _tcx : TyCtxt < ' _ > ) -> rustc_span:: Span {
263
- crate :: passes:: span_of_attrs ( & self . attrs ) . unwrap_or_else ( || self . span ( ) . inner ( ) )
278
+ crate fn attr_span ( & self , tcx : TyCtxt < ' _ > ) -> rustc_span:: Span {
279
+ crate :: passes:: span_of_attrs ( & self . attrs ) . unwrap_or_else ( || self . span ( tcx ) . inner ( ) )
264
280
}
265
281
266
282
/// Finds the `doc` attribute as a NameValue and returns the corresponding
@@ -304,20 +320,10 @@ impl Item {
304
320
) -> Item {
305
321
debug ! ( "name={:?}, def_id={:?}" , name, def_id) ;
306
322
307
- // `span_if_local()` lies about functions and only gives the span of the function signature
308
- let span = def_id. as_local ( ) . map_or_else (
309
- || cx. tcx . def_span ( def_id) ,
310
- |local| {
311
- let hir = cx. tcx . hir ( ) ;
312
- hir. span_with_body ( hir. local_def_id_to_hir_id ( local) )
313
- } ,
314
- ) ;
315
-
316
323
Item {
317
324
def_id,
318
325
kind : box kind,
319
326
name,
320
- span : span. clean ( cx) ,
321
327
attrs,
322
328
visibility : cx. tcx . visibility ( def_id) . clean ( cx) ,
323
329
}
@@ -2117,6 +2123,7 @@ impl Constant {
2117
2123
2118
2124
#[ derive( Clone , Debug ) ]
2119
2125
crate struct Impl {
2126
+ crate span : Span ,
2120
2127
crate unsafety : hir:: Unsafety ,
2121
2128
crate generics : Generics ,
2122
2129
crate provided_trait_methods : FxHashSet < Symbol > ,
0 commit comments