Skip to content

Commit a7239e7

Browse files
committed
Auto merge of #130623 - m-ou-se:skip-query2, r=<try>
Skip query in get_parent_item when possible. `self.parent_owner_iter(hir_id).next()` does a query to retrieve the Node which is ignored here, which seems wasteful.
2 parents 1a5a224 + edca9c2 commit a7239e7

File tree

1 file changed

+4
-2
lines changed
  • compiler/rustc_middle/src/hir/map

1 file changed

+4
-2
lines changed

Diff for: compiler/rustc_middle/src/hir/map/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,10 @@ impl<'hir> Map<'hir> {
598598
/// in the HIR which is recorded by the map and is an item, either an item
599599
/// in a module, trait, or impl.
600600
pub fn get_parent_item(self, hir_id: HirId) -> OwnerId {
601-
if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() {
602-
def_id
601+
if hir_id.local_id.index() != 0 || hir_id.owner == CRATE_OWNER_ID {
602+
hir_id.owner
603+
} else if let Some(local_def_index) = self.def_key(hir_id.owner.def_id).parent {
604+
self.tcx.local_def_id_to_hir_id(LocalDefId { local_def_index }).owner
603605
} else {
604606
CRATE_OWNER_ID
605607
}

0 commit comments

Comments
 (0)