Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip query in get_parent_item when possible. #130623

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +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() {
def_id
if hir_id.local_id.index() != 0 || hir_id.owner == CRATE_OWNER_ID {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if hir_id.local_id.index() != 0 || hir_id.owner == CRATE_OWNER_ID {
if hir_id.local_id.index() != 0 || hir_id.owner == CRATE_OWNER_ID {
// If this is a child of a HIR owner, return the owner.
// If we're at the top of the HIR tree, then the crate is its own parent.

hir_id.owner
} else if let Some(local_def_index) = self.def_key(hir_id.owner.def_id).parent {
self.tcx.local_def_id_to_hir_id(LocalDefId { local_def_index }).owner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.tcx.local_def_id_to_hir_id(LocalDefId { local_def_index }).owner
self.tcx.local_def_id_to_hir_id(LocalDefId { local_def_index }).expect_owner()

} else {
CRATE_OWNER_ID
}
Expand Down
Loading