Skip to content

Commit

Permalink
Auto merge of #123415 - petrochenkov:parenting, r=<try>
Browse files Browse the repository at this point in the history
hir: Drop owner's own item-local id (zero) from parenting tables

I expect this to be a common case.
  • Loading branch information
bors committed Apr 3, 2024
2 parents 99c42d2 + 44b3602 commit aa74533
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_ast_lowering/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
}

fn insert_nested(&mut self, item: LocalDefId) {
self.parenting.insert(item, self.parent_node);
if self.parent_node.as_u32() != 0 {
self.parenting.insert(item, self.parent_node);
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ pub fn provide(providers: &mut Providers) {
let parent_owner_id = tcx.local_def_id_to_hir_id(parent_def_id).owner;
HirId {
owner: parent_owner_id,
local_id: tcx.hir_crate(()).owners[parent_owner_id.def_id].unwrap().parenting
[&owner_id.def_id],
local_id: tcx.hir_crate(()).owners[parent_owner_id.def_id]
.unwrap()
.parenting
.get(&owner_id.def_id)
.copied()
.unwrap_or(ItemLocalId::from_u32(0)),
}
})
};
Expand Down

0 comments on commit aa74533

Please sign in to comment.