@@ -8,6 +8,9 @@ pub mod place;
88
99use crate :: query:: Providers ;
1010use crate :: ty:: { EarlyBinder , ImplSubject , TyCtxt } ;
11+ use rustc_data_structures:: fingerprint:: Fingerprint ;
12+ use rustc_data_structures:: sorted_map:: SortedMap ;
13+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
1114use rustc_data_structures:: sync:: { try_par_for_each_in, DynSend , DynSync } ;
1215use rustc_hir:: def:: DefKind ;
1316use rustc_hir:: def_id:: { DefId , LocalDefId , LocalModDefId } ;
@@ -121,6 +124,30 @@ impl<'tcx> TyCtxt<'tcx> {
121124 self . opt_parent ( def_id. into ( ) )
122125 . is_some_and ( |parent| matches ! ( self . def_kind( parent) , DefKind :: ForeignMod ) )
123126 }
127+
128+ pub fn hash_owner_nodes (
129+ self ,
130+ node : OwnerNode < ' _ > ,
131+ bodies : & SortedMap < ItemLocalId , & Body < ' _ > > ,
132+ attrs : & SortedMap < ItemLocalId , & [ rustc_ast:: Attribute ] > ,
133+ ) -> ( Option < Fingerprint > , Option < Fingerprint > ) {
134+ if self . needs_crate_hash ( ) {
135+ self . with_stable_hashing_context ( |mut hcx| {
136+ let mut stable_hasher = StableHasher :: new ( ) ;
137+ node. hash_stable ( & mut hcx, & mut stable_hasher) ;
138+ // Bodies are stored out of line, so we need to pull them explicitly in the hash.
139+ bodies. hash_stable ( & mut hcx, & mut stable_hasher) ;
140+ let h1 = stable_hasher. finish ( ) ;
141+
142+ let mut stable_hasher = StableHasher :: new ( ) ;
143+ attrs. hash_stable ( & mut hcx, & mut stable_hasher) ;
144+ let h2 = stable_hasher. finish ( ) ;
145+ ( Some ( h1) , Some ( h2) )
146+ } )
147+ } else {
148+ ( None , None )
149+ }
150+ }
124151}
125152
126153pub fn provide ( providers : & mut Providers ) {
0 commit comments