diff options
| author | Michael Goulet <michael@errs.io> | 2024-09-23 23:49:11 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-23 23:49:11 -0400 |
| commit | c0f1a69229a8d139cde0e8a65eb8dfb79dca0ae9 (patch) | |
| tree | c6b0985036a731a660e1c2c3570f11653ce586c9 | |
| parent | 0a0ea28f26b37d44a27380713f98b5d9c97f309b (diff) | |
| parent | c0c569f99db937a143d949bd07009ab1a9a37dd1 (diff) | |
| download | rust-c0f1a69229a8d139cde0e8a65eb8dfb79dca0ae9.tar.gz rust-c0f1a69229a8d139cde0e8a65eb8dfb79dca0ae9.zip | |
Rollup merge of #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.
| -rw-r--r-- | compiler/rustc_middle/src/hir/map/mod.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 167b5aef68b..e11361a615f 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -598,7 +598,10 @@ 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 != 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 } else { CRATE_OWNER_ID |
