Skip to content

Commit bf1ca2e

Browse files
committed
Make local_def_id_to_hir_id query directly returh HirId
1 parent 5a299a9 commit bf1ca2e

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,7 @@ impl<'hir> Map<'hir> {
215215

216216
#[inline]
217217
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
218-
let owner = self.tcx.local_def_id_to_hir_id(def_id);
219-
match owner {
220-
MaybeOwner::Owner(_) => HirId::make_owner(def_id),
221-
MaybeOwner::Phantom => bug!("No HirId for {:?}", def_id),
222-
MaybeOwner::NonOwner(hir_id) => hir_id,
223-
}
218+
self.tcx.local_def_id_to_hir_id(def_id)
224219
}
225220

226221
pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {

compiler/rustc_middle/src/hir/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ pub fn provide(providers: &mut Providers) {
6969
let node = owner.node();
7070
Some(Owner { node, hash_without_bodies: owner.nodes.hash_without_bodies })
7171
};
72-
providers.local_def_id_to_hir_id = |tcx, id| tcx.hir_crate(()).owners[id].map(|_| ());
72+
providers.local_def_id_to_hir_id = |tcx, id| {
73+
let owner = tcx.hir_crate(()).owners[id].map(|_| ());
74+
match owner {
75+
MaybeOwner::Owner(_) => HirId::make_owner(id),
76+
MaybeOwner::Phantom => bug!("No HirId for {:?}", id),
77+
MaybeOwner::NonOwner(hir_id) => hir_id,
78+
}
79+
};
7380
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].map(|i| &i.nodes);
7481
providers.hir_owner_parent = |tcx, id| {
7582
// Accessing the def_key is ok since its value is hashed as part of `id`'s DefPathHash.

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ rustc_queries! {
6060
///
6161
/// This can be conveniently accessed by methods on `tcx.hir()`.
6262
/// Avoid calling this query directly.
63-
query local_def_id_to_hir_id(key: LocalDefId) -> hir::MaybeOwner<()> {
63+
query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
6464
desc { |tcx| "HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
6565
}
6666

0 commit comments

Comments
 (0)