Rollup merge of #123454 - petrochenkov:zeroindex2, r=fmease

hir: Use `ItemLocalId::ZERO` in a couple more places

Follow up to https://github.com/rust-lang/rust/pull/123415 and https://github.com/rust-lang/rust/pull/123419.
This commit is contained in:
Jacob Pratt 2024-04-04 21:16:57 -04:00 committed by GitHub
commit 929e0db6a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View File

@ -19,7 +19,7 @@ struct NodeCollector<'a, 'hir> {
parenting: LocalDefIdMap<ItemLocalId>,
/// The parent of this node
parent_node: hir::ItemLocalId,
parent_node: ItemLocalId,
owner: OwnerId,
}
@ -31,17 +31,16 @@ pub(super) fn index_hir<'hir>(
bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>,
num_nodes: usize,
) -> (IndexVec<ItemLocalId, ParentedNode<'hir>>, LocalDefIdMap<ItemLocalId>) {
let zero_id = ItemLocalId::ZERO;
let err_node = ParentedNode { parent: zero_id, node: Node::Err(item.span()) };
let err_node = ParentedNode { parent: ItemLocalId::ZERO, node: Node::Err(item.span()) };
let mut nodes = IndexVec::from_elem_n(err_node, num_nodes);
// This node's parent should never be accessed: the owner's parent is computed by the
// hir_owner_parent query. Make it invalid (= ItemLocalId::MAX) to force an ICE whenever it is
// used.
nodes[zero_id] = ParentedNode { parent: ItemLocalId::INVALID, node: item.into() };
nodes[ItemLocalId::ZERO] = ParentedNode { parent: ItemLocalId::INVALID, node: item.into() };
let mut collector = NodeCollector {
tcx,
owner: item.def_id(),
parent_node: zero_id,
parent_node: ItemLocalId::ZERO,
nodes,
bodies,
parenting: Default::default(),
@ -112,7 +111,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
}
fn insert_nested(&mut self, item: LocalDefId) {
if self.parent_node.as_u32() != 0 {
if self.parent_node != ItemLocalId::ZERO {
self.parenting.insert(item, self.parent_node);
}
}

View File

@ -179,7 +179,7 @@ pub fn provide(providers: &mut Providers) {
.parenting
.get(&owner_id.def_id)
.copied()
.unwrap_or(ItemLocalId::from_u32(0)),
.unwrap_or(ItemLocalId::ZERO),
}
})
};