Skip to content

Commit aa74533

Browse files
committed
Auto merge of #123415 - petrochenkov:parenting, r=<try>
hir: Drop owner's own item-local id (zero) from parenting tables I expect this to be a common case.
2 parents 99c42d2 + 44b3602 commit aa74533

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: compiler/rustc_ast_lowering/src/index.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
112112
}
113113

114114
fn insert_nested(&mut self, item: LocalDefId) {
115-
self.parenting.insert(item, self.parent_node);
115+
if self.parent_node.as_u32() != 0 {
116+
self.parenting.insert(item, self.parent_node);
117+
}
116118
}
117119
}
118120

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ pub fn provide(providers: &mut Providers) {
174174
let parent_owner_id = tcx.local_def_id_to_hir_id(parent_def_id).owner;
175175
HirId {
176176
owner: parent_owner_id,
177-
local_id: tcx.hir_crate(()).owners[parent_owner_id.def_id].unwrap().parenting
178-
[&owner_id.def_id],
177+
local_id: tcx.hir_crate(()).owners[parent_owner_id.def_id]
178+
.unwrap()
179+
.parenting
180+
.get(&owner_id.def_id)
181+
.copied()
182+
.unwrap_or(ItemLocalId::from_u32(0)),
179183
}
180184
})
181185
};

0 commit comments

Comments
 (0)