Skip to content

Commit c0f1a69

Browse files
Rollup merge of rust-lang#130618 - m-ou-se:skip-query, r=compiler-errors
Skip query in get_parent_item when possible. For HirIds with a non-zero item local id, `self.parent_owner_iter(hir_id).next()` just returns the same HirId with the item local id set to 0, but also does a query to retrieve the Node which is ignored here, which seems wasteful.
2 parents 0a0ea28 + c0c569f commit c0f1a69

File tree

1 file changed

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

1 file changed

+4
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +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() {
601+
if hir_id.local_id != ItemLocalId::ZERO {
602+
// If this is a child of a HIR owner, return the owner.
603+
hir_id.owner
604+
} else if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() {
602605
def_id
603606
} else {
604607
CRATE_OWNER_ID

0 commit comments

Comments
 (0)