rustc_hir/
stable_hash_impls.rs1use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
2use rustc_span::def_id::DefPathHash;
3
4use crate::HashIgnoredAttrId;
5use crate::hir::{
6 AttributeMap, BodyId, Crate, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId,
7};
8use crate::hir_id::ItemLocalId;
9use crate::lints::DelayedLints;
10
11pub trait HashStableContext: rustc_ast::HashStableContext + rustc_abi::HashStableContext {}
15
16impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for BodyId {
17 type KeyType = (DefPathHash, ItemLocalId);
18
19 #[inline]
20 fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
21 let BodyId { hir_id } = *self;
22 hir_id.to_stable_hash_key(hcx)
23 }
24}
25
26impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId {
27 type KeyType = DefPathHash;
28
29 #[inline]
30 fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
31 self.owner_id.def_id.to_stable_hash_key(hcx)
32 }
33}
34
35impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
36 type KeyType = DefPathHash;
37
38 #[inline]
39 fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
40 self.owner_id.def_id.to_stable_hash_key(hcx)
41 }
42}
43
44impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
45 type KeyType = DefPathHash;
46
47 #[inline]
48 fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
49 self.owner_id.def_id.to_stable_hash_key(hcx)
50 }
51}
52
53impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId {
54 type KeyType = DefPathHash;
55
56 #[inline]
57 fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
58 self.owner_id.def_id.to_stable_hash_key(hcx)
59 }
60}
61
62impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
70 fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
71 let OwnerNodes { opt_hash_including_bodies, nodes: _, bodies: _ } = *self;
77 opt_hash_including_bodies.unwrap().hash_stable(hcx, hasher);
78 }
79}
80
81impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DelayedLints {
82 fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
83 let DelayedLints { opt_hash, .. } = *self;
84 opt_hash.unwrap().hash_stable(hcx, hasher);
85 }
86}
87
88impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap<'tcx> {
89 fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
90 let AttributeMap { opt_hash, define_opaque: _, map: _ } = *self;
93 opt_hash.unwrap().hash_stable(hcx, hasher);
94 }
95}
96
97impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Crate<'_> {
98 fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
99 let Crate { owners: _, opt_hir_hash } = self;
100 opt_hir_hash.unwrap().hash_stable(hcx, hasher)
101 }
102}
103
104impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HashIgnoredAttrId {
105 fn hash_stable(&self, _hcx: &mut HirCtx, _hasher: &mut StableHasher) {
106 }
108}