rustc_hir/stable_hash_impls.rs
1use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};
2
3use crate::HashIgnoredAttrId;
4use crate::hir::{AttributeMap, 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 `nodes` and `bodies` fields since these refer to information included in
16 // `hash` which is hashed in the collector and used for the crate hash.
17 // `local_id_to_def_id` is also ignored because is dependent on the body, then just hashing
18 // the body satisfies the condition of two nodes being different have different
19 // `stable_hash` results.
20 let OwnerNodes { opt_hash_including_bodies, nodes: _, bodies: _ } = *self;
21 opt_hash_including_bodies.unwrap().stable_hash(hcx, hasher);
22 }
23}
24
25impl<'tcx> StableHash for AttributeMap<'tcx> {
26 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
27 // We ignore the `map` since it refers to information included in `opt_hash` which is
28 // hashed in the collector and used for the crate hash.
29 let AttributeMap { opt_hash, define_opaque: _, map: _ } = *self;
30 opt_hash.unwrap().stable_hash(hcx, hasher);
31 }
32}
33
34impl StableHash for HashIgnoredAttrId {
35 fn stable_hash<Hcx: StableHashCtxt>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
36 /* we don't hash HashIgnoredAttrId, we ignore them */
37 }
38}