Skip to content

Commit

Permalink
Make local_def_id_to_hir_id query directly returh HirId
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Jan 29, 2022
1 parent 5a299a9 commit bf1ca2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 1 addition & 6 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,7 @@ impl<'hir> Map<'hir> {

#[inline]
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
let owner = self.tcx.local_def_id_to_hir_id(def_id);
match owner {
MaybeOwner::Owner(_) => HirId::make_owner(def_id),
MaybeOwner::Phantom => bug!("No HirId for {:?}", def_id),
MaybeOwner::NonOwner(hir_id) => hir_id,
}
self.tcx.local_def_id_to_hir_id(def_id)
}

pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ pub fn provide(providers: &mut Providers) {
let node = owner.node();
Some(Owner { node, hash_without_bodies: owner.nodes.hash_without_bodies })
};
providers.local_def_id_to_hir_id = |tcx, id| tcx.hir_crate(()).owners[id].map(|_| ());
providers.local_def_id_to_hir_id = |tcx, id| {
let owner = tcx.hir_crate(()).owners[id].map(|_| ());
match owner {
MaybeOwner::Owner(_) => HirId::make_owner(id),
MaybeOwner::Phantom => bug!("No HirId for {:?}", id),
MaybeOwner::NonOwner(hir_id) => hir_id,
}
};
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].map(|i| &i.nodes);
providers.hir_owner_parent = |tcx, id| {
// Accessing the def_key is ok since its value is hashed as part of `id`'s DefPathHash.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ rustc_queries! {
///
/// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly.
query local_def_id_to_hir_id(key: LocalDefId) -> hir::MaybeOwner<()> {
query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
desc { |tcx| "HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
}

Expand Down

0 comments on commit bf1ca2e

Please sign in to comment.