]> git.lizzy.rs Git - rust.git/blob - src/librustc_hir/stable_hash_impls.rs
doc(librustc_error_codes): add long error explanation for E0719
[rust.git] / src / librustc_hir / stable_hash_impls.rs
1 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2
3 use crate::hir::{BodyId, Expr, ImplItemId, ItemId, Mod, TraitItemId, Ty, VisibilityKind};
4 use crate::hir_id::HirId;
5
6 /// Requirements for a `StableHashingContext` to be used in this crate.
7 /// This is a hack to allow using the `HashStable_Generic` derive macro
8 /// instead of implementing everything in librustc.
9 pub trait HashStableContext: syntax::HashStableContext + rustc_target::HashStableContext {
10     fn hash_hir_id(&mut self, _: HirId, hasher: &mut StableHasher);
11     fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
12     fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
13     fn hash_hir_mod(&mut self, _: &Mod<'_>, hasher: &mut StableHasher);
14     fn hash_hir_expr(&mut self, _: &Expr<'_>, hasher: &mut StableHasher);
15     fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
16     fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
17 }
18
19 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
20     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
21         hcx.hash_hir_id(*self, hasher)
22     }
23 }
24
25 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
26     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
27         hcx.hash_body_id(*self, hasher)
28     }
29 }
30
31 // The following implementations of HashStable for `ItemId`, `TraitItemId`, and
32 // `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
33 // the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
34 // are used when another item in the HIR is *referenced* and we certainly
35 // want to pick up on a reference changing its target, so we hash the NodeIds
36 // in "DefPath Mode".
37
38 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
39     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
40         hcx.hash_reference_to_item(self.id, hasher)
41     }
42 }
43
44 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
45     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
46         hcx.hash_reference_to_item(self.hir_id, hasher)
47     }
48 }
49
50 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId {
51     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
52         hcx.hash_reference_to_item(self.hir_id, hasher)
53     }
54 }
55
56 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Mod<'_> {
57     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
58         hcx.hash_hir_mod(self, hasher)
59     }
60 }
61
62 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Expr<'_> {
63     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
64         hcx.hash_hir_expr(self, hasher)
65     }
66 }
67
68 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Ty<'_> {
69     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
70         hcx.hash_hir_ty(self, hasher)
71     }
72 }
73
74 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_> {
75     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
76         hcx.hash_hir_visibility_kind(self, hasher)
77     }
78 }