diff options
| author | bors <bors@rust-lang.org> | 2024-04-03 18:18:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-03 18:18:44 +0000 |
| commit | 98efd808e1b77cd70a097620aad6250727167a28 (patch) | |
| tree | af31db583ae047fe31a63428d6e3b02441dbf0b3 /compiler | |
| parent | 703dc9ce64d9b31a239a7280d9b5f9ddd85ffed6 (diff) | |
| parent | 44b36024786a5e00d55111c1a43a0c8388caefcb (diff) | |
| download | rust-98efd808e1b77cd70a097620aad6250727167a28.tar.gz rust-98efd808e1b77cd70a097620aad6250727167a28.zip | |
Auto merge of #123415 - petrochenkov:parenting, r=compiler-errors
hir: Drop owner's own item-local id (zero) from parenting tables I expect this to be a common case.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/index.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/hir/mod.rs | 8 |
2 files changed, 9 insertions, 3 deletions
diff --git a/compiler/rustc_ast_lowering/src/index.rs b/compiler/rustc_ast_lowering/src/index.rs index a1164008d0d..6e09632d0e3 100644 --- a/compiler/rustc_ast_lowering/src/index.rs +++ b/compiler/rustc_ast_lowering/src/index.rs @@ -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); + } } } diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 28f7574f66f..42a06c968c7 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -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)), } }) }; |
