11use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
22
33use crate :: def_id:: DefId ;
4- use crate :: hir:: { BodyId , Expr , ImplItemId , ItemId , Mod , TraitItemId , Ty , VisibilityKind } ;
4+ use crate :: hir:: {
5+ BodyId , Expr , ImplItem , ImplItemId , Item , ItemId , Mod , TraitItem , TraitItemId , Ty ,
6+ VisibilityKind ,
7+ } ;
58use crate :: hir_id:: HirId ;
69
710/// Requirements for a `StableHashingContext` to be used in this crate.
@@ -16,6 +19,7 @@ pub trait HashStableContext: syntax::HashStableContext + rustc_target::HashStabl
1619 fn hash_hir_expr ( & mut self , _: & Expr < ' _ > , hasher : & mut StableHasher ) ;
1720 fn hash_hir_ty ( & mut self , _: & Ty < ' _ > , hasher : & mut StableHasher ) ;
1821 fn hash_hir_visibility_kind ( & mut self , _: & VisibilityKind < ' _ > , hasher : & mut StableHasher ) ;
22+ fn hash_hir_item_like < F : FnOnce ( & mut Self ) > ( & mut self , f : F ) ;
1923}
2024
2125impl < HirCtx : crate :: HashStableContext > HashStable < HirCtx > for HirId {
@@ -84,3 +88,56 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_>
8488 hcx. hash_hir_visibility_kind ( self , hasher)
8589 }
8690}
91+
92+ impl < HirCtx : crate :: HashStableContext > HashStable < HirCtx > for TraitItem < ' _ > {
93+ fn hash_stable ( & self , hcx : & mut HirCtx , hasher : & mut StableHasher ) {
94+ let TraitItem { hir_id : _, ident, ref attrs, ref generics, ref kind, span } = * self ;
95+
96+ hcx. hash_hir_item_like ( |hcx| {
97+ ident. name . hash_stable ( hcx, hasher) ;
98+ attrs. hash_stable ( hcx, hasher) ;
99+ generics. hash_stable ( hcx, hasher) ;
100+ kind. hash_stable ( hcx, hasher) ;
101+ span. hash_stable ( hcx, hasher) ;
102+ } ) ;
103+ }
104+ }
105+
106+ impl < HirCtx : crate :: HashStableContext > HashStable < HirCtx > for ImplItem < ' _ > {
107+ fn hash_stable ( & self , hcx : & mut HirCtx , hasher : & mut StableHasher ) {
108+ let ImplItem {
109+ hir_id : _,
110+ ident,
111+ ref vis,
112+ defaultness,
113+ ref attrs,
114+ ref generics,
115+ ref kind,
116+ span,
117+ } = * self ;
118+
119+ hcx. hash_hir_item_like ( |hcx| {
120+ ident. name . hash_stable ( hcx, hasher) ;
121+ vis. hash_stable ( hcx, hasher) ;
122+ defaultness. hash_stable ( hcx, hasher) ;
123+ attrs. hash_stable ( hcx, hasher) ;
124+ generics. hash_stable ( hcx, hasher) ;
125+ kind. hash_stable ( hcx, hasher) ;
126+ span. hash_stable ( hcx, hasher) ;
127+ } ) ;
128+ }
129+ }
130+
131+ impl < HirCtx : crate :: HashStableContext > HashStable < HirCtx > for Item < ' _ > {
132+ fn hash_stable ( & self , hcx : & mut HirCtx , hasher : & mut StableHasher ) {
133+ let Item { ident, ref attrs, hir_id : _, ref kind, ref vis, span } = * self ;
134+
135+ hcx. hash_hir_item_like ( |hcx| {
136+ ident. name . hash_stable ( hcx, hasher) ;
137+ attrs. hash_stable ( hcx, hasher) ;
138+ kind. hash_stable ( hcx, hasher) ;
139+ vis. hash_stable ( hcx, hasher) ;
140+ span. hash_stable ( hcx, hasher) ;
141+ } ) ;
142+ }
143+ }
0 commit comments