rustc: make LocalDefId's index field public like DefId's is.

This commit is contained in:
Eduard-Mihai Burtescu 2019-10-31 20:48:13 +02:00
parent e1762fdad1
commit 55ed19fe1b
4 changed files with 8 additions and 6 deletions

View File

@ -263,7 +263,7 @@ impl<'hir> Map<'hir> {
#[inline]
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
self.tcx.definitions.def_index_to_hir_id(def_id.to_def_id().index)
self.tcx.definitions.def_index_to_hir_id(def_id.local_def_index)
}
pub fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {

View File

@ -735,7 +735,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
let var_owner_def_id =
DefId { krate: local_id_root.krate, index: var_path.hir_id.owner };
let closure_def_id =
DefId { krate: local_id_root.krate, index: closure_expr_id.to_def_id().index };
DefId { krate: local_id_root.krate, index: closure_expr_id.local_def_index };
(
hcx.def_path_hash(var_owner_def_id),
var_path.hir_id.local_id,

View File

@ -24,7 +24,7 @@ impl HirId {
}
pub fn owner_local_def_id(self) -> LocalDefId {
LocalDefId::from_def_id(DefId::local(self.owner))
LocalDefId { local_def_index: self.owner }
}
}

View File

@ -211,18 +211,20 @@ rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);
/// and a DefId from a different crate would signify a bug somewhere. This
/// is when LocalDefId comes in handy.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct LocalDefId(DefIndex);
pub struct LocalDefId {
pub local_def_index: DefIndex,
}
impl LocalDefId {
#[inline]
pub fn from_def_id(def_id: DefId) -> LocalDefId {
assert!(def_id.is_local());
LocalDefId(def_id.index)
LocalDefId { local_def_index: def_id.index }
}
#[inline]
pub fn to_def_id(self) -> DefId {
DefId { krate: LOCAL_CRATE, index: self.0 }
DefId { krate: LOCAL_CRATE, index: self.local_def_index }
}
}