rustc_hir/
stable_hash_impls.rs1use rustc_data_structures::stable_hasher::{
2 StableHash, StableHashCtxt, StableHasher, ToStableHashKey,
3};
4use rustc_span::def_id::DefPathHash;
5
6use crate::HashIgnoredAttrId;
7use crate::hir::{
8 AttributeMap, BodyId, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId,
9};
10use crate::hir_id::ItemLocalId;
11
12impl ToStableHashKey for BodyId {
13 type KeyType = (DefPathHash, ItemLocalId);
14
15 #[inline]
16 fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) {
17 let BodyId { hir_id } = *self;
18 hir_id.to_stable_hash_key(hcx)
19 }
20}
21
22impl ToStableHashKey for ItemId {
23 type KeyType = DefPathHash;
24
25 #[inline]
26 fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
27 self.owner_id.def_id.to_stable_hash_key(hcx)
28 }
29}
30
31impl ToStableHashKey for TraitItemId {
32 type KeyType = DefPathHash;
33
34 #[inline]
35 fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
36 self.owner_id.def_id.to_stable_hash_key(hcx)
37 }
38}
39
40impl ToStableHashKey for ImplItemId {
41 type KeyType = DefPathHash;
42
43 #[inline]
44 fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
45 self.owner_id.def_id.to_stable_hash_key(hcx)
46 }
47}
48
49impl ToStableHashKey for ForeignItemId {
50 type KeyType = DefPathHash;
51
52 #[inline]
53 fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
54 self.owner_id.def_id.to_stable_hash_key(hcx)
55 }
56}
57
58impl<'tcx> StableHash for OwnerNodes<'tcx> {
66 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
67 let OwnerNodes { opt_hash_including_bodies, nodes: _, bodies: _ } = *self;
73 opt_hash_including_bodies.unwrap().stable_hash(hcx, hasher);
74 }
75}
76
77impl<'tcx> StableHash for AttributeMap<'tcx> {
78 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
79 let AttributeMap { opt_hash, define_opaque: _, map: _ } = *self;
82 opt_hash.unwrap().stable_hash(hcx, hasher);
83 }
84}
85
86impl StableHash for HashIgnoredAttrId {
87 fn stable_hash<Hcx: StableHashCtxt>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
88 }
90}