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;
10use crate::lints::DelayedLints;
11
12impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for BodyId {
13 type KeyType = (DefPathHash, ItemLocalId);
14
15 #[inline]
16 fn to_stable_hash_key(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) {
17 let BodyId { hir_id } = *self;
18 hir_id.to_stable_hash_key(hcx)
19 }
20}
21
22impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ItemId {
23 type KeyType = DefPathHash;
24
25 #[inline]
26 fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
27 self.owner_id.def_id.to_stable_hash_key(hcx)
28 }
29}
30
31impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for TraitItemId {
32 type KeyType = DefPathHash;
33
34 #[inline]
35 fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
36 self.owner_id.def_id.to_stable_hash_key(hcx)
37 }
38}
39
40impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ImplItemId {
41 type KeyType = DefPathHash;
42
43 #[inline]
44 fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
45 self.owner_id.def_id.to_stable_hash_key(hcx)
46 }
47}
48
49impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ForeignItemId {
50 type KeyType = DefPathHash;
51
52 #[inline]
53 fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
54 self.owner_id.def_id.to_stable_hash_key(hcx)
55 }
56}
57
58impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for OwnerNodes<'tcx> {
66 fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
67 let OwnerNodes { opt_hash_including_bodies, nodes: _, bodies: _ } = *self;
73 opt_hash_including_bodies.unwrap().hash_stable(hcx, hasher);
74 }
75}
76
77impl<Hcx: HashStableContext> HashStable<Hcx> for DelayedLints {
78 fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
79 let DelayedLints { opt_hash, .. } = *self;
80 opt_hash.unwrap().hash_stable(hcx, hasher);
81 }
82}
83
84impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for AttributeMap<'tcx> {
85 fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
86 let AttributeMap { opt_hash, define_opaque: _, map: _ } = *self;
89 opt_hash.unwrap().hash_stable(hcx, hasher);
90 }
91}
92
93impl<Hcx: HashStableContext> HashStable<Hcx> for HashIgnoredAttrId {
94 fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
95 }
97}