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