@@ -211,7 +211,6 @@ impl ExternalCrate {
211211/// directly to the AST's concept of an item; it's a strict superset.
212212#[ derive( Clone ) ]
213213crate struct Item {
214- crate span : Span ,
215214 /// The name of this item.
216215 /// Optional because not every item has a name, e.g. impls.
217216 crate name : Option < Symbol > ,
@@ -225,14 +224,13 @@ crate struct Item {
225224
226225// `Item` is used a lot. Make sure it doesn't unintentionally get bigger.
227226#[ 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 ) ;
229228
230229impl fmt:: Debug for Item {
231230 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
232231 let def_id: & dyn fmt:: Debug = if self . is_fake ( ) { & "**FAKE**" } else { & self . def_id } ;
233232
234233 fmt. debug_struct ( "Item" )
235- . field ( "source" , & self . span ( ) )
236234 . field ( "name" , & self . name )
237235 . field ( "attrs" , & self . attrs )
238236 . field ( "kind" , & self . kind )
@@ -242,6 +240,16 @@ impl fmt::Debug for Item {
242240 }
243241}
244242
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+
245253impl Item {
246254 crate fn stability < ' tcx > ( & self , tcx : TyCtxt < ' tcx > ) -> Option < & ' tcx Stability > {
247255 if self . is_fake ( ) { None } else { tcx. lookup_stability ( self . def_id ) }
@@ -255,12 +263,20 @@ impl Item {
255263 if self . is_fake ( ) { None } else { tcx. lookup_deprecation ( self . def_id ) }
256264 }
257265
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+ }
260276 }
261277
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 ( ) )
264280 }
265281
266282 /// Finds the `doc` attribute as a NameValue and returns the corresponding
@@ -304,20 +320,10 @@ impl Item {
304320 ) -> Item {
305321 debug ! ( "name={:?}, def_id={:?}" , name, def_id) ;
306322
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-
316323 Item {
317324 def_id,
318325 kind : box kind,
319326 name,
320- span : span. clean ( cx) ,
321327 attrs,
322328 visibility : cx. tcx . visibility ( def_id) . clean ( cx) ,
323329 }
@@ -2117,6 +2123,7 @@ impl Constant {
21172123
21182124#[ derive( Clone , Debug ) ]
21192125crate struct Impl {
2126+ crate span : Span ,
21202127 crate unsafety : hir:: Unsafety ,
21212128 crate generics : Generics ,
21222129 crate provided_trait_methods : FxHashSet < Symbol > ,
0 commit comments