From 7a19b17084f4c33a582f01414d8848dd79964dc8 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 20 Sep 2024 16:12:44 +0200 Subject: [PATCH 1/2] Skip query in get_parent_item when possible. --- compiler/rustc_middle/src/hir/map/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 8b0a855612c..5efbf0cfa3a 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -598,7 +598,9 @@ impl<'hir> Map<'hir> { /// in the HIR which is recorded by the map and is an item, either an item /// in a module, trait, or impl. pub fn get_parent_item(self, hir_id: HirId) -> OwnerId { - if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() { + if hir_id.local_id.index() != 0 { + hir_id.owner + } else if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() { def_id } else { CRATE_OWNER_ID From c0c569f99db937a143d949bd07009ab1a9a37dd1 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 23 Sep 2024 09:36:17 +0000 Subject: [PATCH 2/2] Update compiler/rustc_middle/src/hir/map/mod.rs Co-authored-by: Michael Goulet --- compiler/rustc_middle/src/hir/map/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 5efbf0cfa3a..3d3153ce35c 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -598,7 +598,8 @@ impl<'hir> Map<'hir> { /// in the HIR which is recorded by the map and is an item, either an item /// in a module, trait, or impl. pub fn get_parent_item(self, hir_id: HirId) -> OwnerId { - if hir_id.local_id.index() != 0 { + if hir_id.local_id != ItemLocalId::ZERO { + // If this is a child of a HIR owner, return the owner. hir_id.owner } else if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() { def_id