1
Fork 0

Hash DefId in rustc_span.

This commit is contained in:
Camille GILLOT 2021-04-19 22:27:49 +02:00
parent 1f949e94e8
commit a7a50b0c0a
6 changed files with 55 additions and 71 deletions

View file

@ -5,7 +5,7 @@ use crate::hir::{
TraitItem, TraitItemId, Ty, VisibilityKind,
};
use crate::hir_id::{HirId, ItemLocalId};
use rustc_span::def_id::{DefPathHash, LocalDefId};
use rustc_span::def_id::DefPathHash;
/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
@ -21,7 +21,6 @@ pub trait HashStableContext:
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F);
fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash;
}
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
@ -29,7 +28,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
let def_path_hash = hcx.local_def_path_hash(self.owner);
let def_path_hash = self.owner.to_stable_hash_key(hcx);
(def_path_hash, self.local_id)
}
}
@ -39,7 +38,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId {
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
hcx.local_def_path_hash(self.def_id)
self.def_id.to_stable_hash_key(hcx)
}
}
@ -48,7 +47,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
hcx.local_def_path_hash(self.def_id)
self.def_id.to_stable_hash_key(hcx)
}
}
@ -57,7 +56,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
hcx.local_def_path_hash(self.def_id)
self.def_id.to_stable_hash_key(hcx)
}
}
@ -66,7 +65,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
hcx.local_def_path_hash(self.def_id)
self.def_id.to_stable_hash_key(hcx)
}
}