rustc_hir/stable_hash_impls.rs
1use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};
2
3use crate::hir::{AttributeMap, OwnerInfo, OwnerNodes};
4
5// The following implementations of StableHash for `ItemId`, `TraitItemId`, and
6// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
7// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
8// are used when another item in the HIR is *referenced* and we certainly
9// want to pick up on a reference changing its target, so we hash the NodeIds
10// in "DefPath Mode".
11
12impl<'tcx> StableHash for OwnerNodes<'tcx> {
13 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
14 // We ignore the other fields since these refer to information included in
15 // `opt_hash` which is hashed in the collector and used for the crate hash.
16 let OwnerNodes { opt_hash, .. } = *self;
17 opt_hash.unwrap().stable_hash(hcx, hasher);
18 }
19}
20
21impl<'tcx> StableHash for AttributeMap<'tcx> {
22 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
23 // We ignore the `map` since it refers to information included in `opt_hash` which is
24 // hashed in the collector and used for the crate hash.
25 let AttributeMap { opt_hash, define_opaque: _, map: _ } = *self;
26 opt_hash.unwrap().stable_hash(hcx, hasher);
27 }
28}
29
30impl<'tcx> StableHash for OwnerInfo<'tcx> {
31 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
32 // We ignore the other fields since these refer to information included in
33 // `opt_hash` which is hashed in the collector and used for the crate hash.
34 let OwnerInfo { opt_hash, .. } = *self;
35 opt_hash.unwrap().stable_hash(hcx, hasher);
36 }
37}