@@ -1907,7 +1907,14 @@ pub struct FnSig<'hir> {
19071907// so it can fetched later.
19081908#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Encodable , Debug ) ]
19091909pub struct TraitItemId {
1910- pub hir_id : HirId ,
1910+ pub def_id : LocalDefId ,
1911+ }
1912+
1913+ impl TraitItemId {
1914+ pub fn hir_id ( & self ) -> HirId {
1915+ // Items are always HIR owners.
1916+ HirId :: make_owner ( self . def_id )
1917+ }
19111918}
19121919
19131920/// Represents an item declaration within a trait declaration,
@@ -1917,13 +1924,24 @@ pub struct TraitItemId {
19171924#[ derive( Debug ) ]
19181925pub struct TraitItem < ' hir > {
19191926 pub ident : Ident ,
1920- pub hir_id : HirId ,
1927+ pub def_id : LocalDefId ,
19211928 pub attrs : & ' hir [ Attribute ] ,
19221929 pub generics : Generics < ' hir > ,
19231930 pub kind : TraitItemKind < ' hir > ,
19241931 pub span : Span ,
19251932}
19261933
1934+ impl TraitItem < ' _ > {
1935+ pub fn hir_id ( & self ) -> HirId {
1936+ // Items are always HIR owners.
1937+ HirId :: make_owner ( self . def_id )
1938+ }
1939+
1940+ pub fn trait_item_id ( & self ) -> TraitItemId {
1941+ TraitItemId { def_id : self . def_id }
1942+ }
1943+ }
1944+
19271945/// Represents a trait method's body (or just argument names).
19281946#[ derive( Encodable , Debug , HashStable_Generic ) ]
19291947pub enum TraitFn < ' hir > {
@@ -2885,9 +2903,10 @@ impl<'hir> Node<'hir> {
28852903
28862904 pub fn hir_id ( & self ) -> Option < HirId > {
28872905 match self {
2888- Node :: Item ( Item { def_id, .. } ) => Some ( HirId :: make_owner ( * def_id) ) ,
2906+ Node :: Item ( Item { def_id, .. } ) | Node :: TraitItem ( TraitItem { def_id, .. } ) => {
2907+ Some ( HirId :: make_owner ( * def_id) )
2908+ }
28892909 Node :: ForeignItem ( ForeignItem { hir_id, .. } )
2890- | Node :: TraitItem ( TraitItem { hir_id, .. } )
28912910 | Node :: ImplItem ( ImplItem { hir_id, .. } )
28922911 | Node :: Field ( StructField { hir_id, .. } )
28932912 | Node :: AnonConst ( AnonConst { hir_id, .. } )
@@ -2922,7 +2941,7 @@ mod size_asserts {
29222941 rustc_data_structures:: static_assert_size!( super :: Ty <' static >, 72 ) ;
29232942
29242943 rustc_data_structures:: static_assert_size!( super :: Item <' static >, 200 ) ;
2925- rustc_data_structures:: static_assert_size!( super :: TraitItem <' static >, 152 ) ;
2944+ rustc_data_structures:: static_assert_size!( super :: TraitItem <' static >, 144 ) ;
29262945 rustc_data_structures:: static_assert_size!( super :: ImplItem <' static >, 168 ) ;
29272946 rustc_data_structures:: static_assert_size!( super :: ForeignItem <' static >, 160 ) ;
29282947}
0 commit comments