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