]> git.lizzy.rs Git - rust.git/blob - src/librustc_hir/stable_hash_impls.rs
merge item id stable hashing functions
[rust.git] / src / librustc_hir / stable_hash_impls.rs
1 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2
3 use crate::def_id::DefId;
4 use crate::hir::{BodyId, Expr, ImplItemId, ItemId, Mod, TraitItemId, Ty, VisibilityKind};
5 use crate::hir_id::HirId;
6
7 /// Requirements for a `StableHashingContext` to be used in this crate.
8 /// This is a hack to allow using the `HashStable_Generic` derive macro
9 /// instead of implementing everything in librustc.
10 pub trait HashStableContext: syntax::HashStableContext + rustc_target::HashStableContext {
11     fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher);
12     fn hash_hir_id(&mut self, _: HirId, hasher: &mut StableHasher);
13     fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
14     fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
15     fn hash_hir_mod(&mut self, _: &Mod<'_>, hasher: &mut StableHasher);
16     fn hash_hir_expr(&mut self, _: &Expr<'_>, hasher: &mut StableHasher);
17     fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
18     fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
19 }
20
21 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
22     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
23         hcx.hash_hir_id(*self, hasher)
24     }
25 }
26
27 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DefId {
28     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
29         hcx.hash_def_id(*self, hasher)
30     }
31 }
32
33 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
34     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
35         hcx.hash_body_id(*self, hasher)
36     }
37 }
38
39 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
40     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
41         hcx.hash_reference_to_item(self.id, hasher)
42     }
43 }
44
45 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
46     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
47         hcx.hash_reference_to_item(self.hir_id, hasher)
48     }
49 }
50
51 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId {
52     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
53         hcx.hash_reference_to_item(self.hir_id, hasher)
54     }
55 }
56
57 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Mod<'_> {
58     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
59         hcx.hash_hir_mod(self, hasher)
60     }
61 }
62
63 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Expr<'_> {
64     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
65         hcx.hash_hir_expr(self, hasher)
66     }
67 }
68
69 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Ty<'_> {
70     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
71         hcx.hash_hir_ty(self, hasher)
72     }
73 }
74
75 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_> {
76     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
77         hcx.hash_hir_visibility_kind(self, hasher)
78     }
79 }