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 fn hash_attr_id(&mut self, id: &HashIgnoredAttrId, hasher: &mut StableHasher);
16}
17
18impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for BodyId {
19 type KeyType = (DefPathHash, ItemLocalId);
20
21 #[inline]
22 fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
23 let BodyId { hir_id } = *self;
24 hir_id.to_stable_hash_key(hcx)
25 }
26}
27
28impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId {
29 type KeyType = DefPathHash;
30
31 #[inline]
32 fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
33 self.owner_id.def_id.to_stable_hash_key(hcx)
34 }
35}
36
37impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
38 type KeyType = DefPathHash;
39
40 #[inline]
41 fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
42 self.owner_id.def_id.to_stable_hash_key(hcx)
43 }
44}
45
46impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
47 type KeyType = DefPathHash;
48
49 #[inline]
50 fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
51 self.owner_id.def_id.to_stable_hash_key(hcx)
52 }
53}
54
55impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId {
56 type KeyType = DefPathHash;
57
58 #[inline]
59 fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
60 self.owner_id.def_id.to_stable_hash_key(hcx)
61 }
62}
63
64impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
72 fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
73 let OwnerNodes { opt_hash_including_bodies, nodes: _, bodies: _ } = *self;
79 opt_hash_including_bodies.unwrap().hash_stable(hcx, hasher);
80 }
81}
82
83impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DelayedLints {
84 fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
85 let DelayedLints { opt_hash, .. } = *self;
86 opt_hash.unwrap().hash_stable(hcx, hasher);
87 }
88}
89
90impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap<'tcx> {
91 fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
92 let AttributeMap { opt_hash, define_opaque: _, map: _ } = *self;
95 opt_hash.unwrap().hash_stable(hcx, hasher);
96 }
97}
98
99impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Crate<'_> {
100 fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
101 let Crate { owners: _, opt_hir_hash } = self;
102 opt_hir_hash.unwrap().hash_stable(hcx, hasher)
103 }
104}
105
106impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HashIgnoredAttrId {
107 fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
108 hcx.hash_attr_id(self, hasher)
109 }
110}