]> git.lizzy.rs Git - rust.git/blob - src/librustc_hir/stable_hash_impls.rs
Rollup merge of #68509 - GuillaumeGomez:clean-up-err-codes-e0223-e0225, r=Dylan-DPC
[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_item_id(&mut self, _: ItemId, hasher: &mut StableHasher);
15     fn hash_impl_item_id(&mut self, _: ImplItemId, hasher: &mut StableHasher);
16     fn hash_trait_item_id(&mut self, _: TraitItemId, hasher: &mut StableHasher);
17     fn hash_hir_mod(&mut self, _: &Mod<'_>, hasher: &mut StableHasher);
18     fn hash_hir_expr(&mut self, _: &Expr<'_>, hasher: &mut StableHasher);
19     fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
20     fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
21 }
22
23 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
24     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
25         hcx.hash_hir_id(*self, hasher)
26     }
27 }
28
29 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DefId {
30     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
31         hcx.hash_def_id(*self, hasher)
32     }
33 }
34
35 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
36     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
37         hcx.hash_body_id(*self, hasher)
38     }
39 }
40
41 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
42     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
43         hcx.hash_item_id(*self, hasher)
44     }
45 }
46
47 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
48     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
49         hcx.hash_impl_item_id(*self, hasher)
50     }
51 }
52
53 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId {
54     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
55         hcx.hash_trait_item_id(*self, hasher)
56     }
57 }
58
59 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Mod<'_> {
60     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
61         hcx.hash_hir_mod(self, hasher)
62     }
63 }
64
65 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Expr<'_> {
66     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
67         hcx.hash_hir_expr(self, hasher)
68     }
69 }
70
71 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Ty<'_> {
72     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
73         hcx.hash_hir_ty(self, hasher)
74     }
75 }
76
77 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_> {
78     fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
79         hcx.hash_hir_visibility_kind(self, hasher)
80     }
81 }