rustc_hir/
stable_hash_impls.rs1use rustc_data_structures::stable_hasher::{
2 HashStable, HashStableContext, 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: HashStableContext>(
17 &self,
18 hcx: &mut Hcx,
19 ) -> (DefPathHash, ItemLocalId) {
20 let BodyId { hir_id } = *self;
21 hir_id.to_stable_hash_key(hcx)
22 }
23}
24
25impl ToStableHashKey for ItemId {
26 type KeyType = DefPathHash;
27
28 #[inline]
29 fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
30 self.owner_id.def_id.to_stable_hash_key(hcx)
31 }
32}
33
34impl ToStableHashKey for TraitItemId {
35 type KeyType = DefPathHash;
36
37 #[inline]
38 fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
39 self.owner_id.def_id.to_stable_hash_key(hcx)
40 }
41}
42
43impl ToStableHashKey for ImplItemId {
44 type KeyType = DefPathHash;
45
46 #[inline]
47 fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
48 self.owner_id.def_id.to_stable_hash_key(hcx)
49 }
50}
51
52impl ToStableHashKey for ForeignItemId {
53 type KeyType = DefPathHash;
54
55 #[inline]
56 fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
57 self.owner_id.def_id.to_stable_hash_key(hcx)
58 }
59}
60
61impl<'tcx> HashStable for OwnerNodes<'tcx> {
69 fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
70 let OwnerNodes { opt_hash_including_bodies, nodes: _, bodies: _ } = *self;
76 opt_hash_including_bodies.unwrap().hash_stable(hcx, hasher);
77 }
78}
79
80impl<'tcx> HashStable for AttributeMap<'tcx> {
81 fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
82 let AttributeMap { opt_hash, define_opaque: _, map: _ } = *self;
85 opt_hash.unwrap().hash_stable(hcx, hasher);
86 }
87}
88
89impl HashStable for HashIgnoredAttrId {
90 fn hash_stable<Hcx: HashStableContext>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
91 }
93}