Skip to content

Commit b37f968

Browse files
authored
Rollup merge of #68858 - ljedrz:collapse_stable_hash_foos, r=michaelwoerister
Merge item id stable hashing functions Supersedes #67999 splitting out the pure cleanup bits, i.e. merging `hash_item_id`, `hash_impl_item_id` and `hash_trait_item_id` into a common `hash_reference_to_item`. r? @michaelwoerister
2 parents cf32b71 + e8b72f4 commit b37f968

File tree

2 files changed

+12
-33
lines changed

2 files changed

+12
-33
lines changed

src/librustc/ich/impls_hir.rs

+1-27
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,14 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
4040
}
4141
}
4242

43-
// The following implementations of HashStable for `ItemId`, `TraitItemId`, and
44-
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
45-
// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
46-
// are used when another item in the HIR is *referenced* and we certainly
47-
// want to pick up on a reference changing its target, so we hash the NodeIds
48-
// in "DefPath Mode".
49-
50-
fn hash_item_id(&mut self, id: hir::ItemId, hasher: &mut StableHasher) {
43+
fn hash_reference_to_item(&mut self, id: hir::HirId, hasher: &mut StableHasher) {
5144
let hcx = self;
52-
let hir::ItemId { id } = id;
5345

5446
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
5547
id.hash_stable(hcx, hasher);
5648
})
5749
}
5850

59-
fn hash_impl_item_id(&mut self, id: hir::ImplItemId, hasher: &mut StableHasher) {
60-
let hcx = self;
61-
let hir::ImplItemId { hir_id } = id;
62-
63-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
64-
hir_id.hash_stable(hcx, hasher);
65-
})
66-
}
67-
68-
fn hash_trait_item_id(&mut self, id: hir::TraitItemId, hasher: &mut StableHasher) {
69-
let hcx = self;
70-
let hir::TraitItemId { hir_id } = id;
71-
72-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
73-
hir_id.hash_stable(hcx, hasher);
74-
})
75-
}
76-
7751
fn hash_hir_mod(&mut self, module: &hir::Mod<'_>, hasher: &mut StableHasher) {
7852
let hcx = self;
7953
let hir::Mod { inner: ref inner_span, ref item_ids } = *module;

src/librustc_hir/stable_hash_impls.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ pub trait HashStableContext: syntax::HashStableContext + rustc_target::HashStabl
1111
fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher);
1212
fn hash_hir_id(&mut self, _: HirId, hasher: &mut StableHasher);
1313
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);
14+
fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
1715
fn hash_hir_mod(&mut self, _: &Mod<'_>, hasher: &mut StableHasher);
1816
fn hash_hir_expr(&mut self, _: &Expr<'_>, hasher: &mut StableHasher);
1917
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
@@ -38,21 +36,28 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
3836
}
3937
}
4038

39+
// The following implementations of HashStable for `ItemId`, `TraitItemId`, and
40+
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
41+
// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
42+
// are used when another item in the HIR is *referenced* and we certainly
43+
// want to pick up on a reference changing its target, so we hash the NodeIds
44+
// in "DefPath Mode".
45+
4146
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
4247
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
43-
hcx.hash_item_id(*self, hasher)
48+
hcx.hash_reference_to_item(self.id, hasher)
4449
}
4550
}
4651

4752
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
4853
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
49-
hcx.hash_impl_item_id(*self, hasher)
54+
hcx.hash_reference_to_item(self.hir_id, hasher)
5055
}
5156
}
5257

5358
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId {
5459
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
55-
hcx.hash_trait_item_id(*self, hasher)
60+
hcx.hash_reference_to_item(self.hir_id, hasher)
5661
}
5762
}
5863

0 commit comments

Comments
 (0)