1
Fork 0

Use invalid local id for zeroth node parent.

This commit is contained in:
Camille GILLOT 2021-10-12 08:34:38 +02:00
parent 6b7995195a
commit c5628a5e65
3 changed files with 11 additions and 2 deletions

View file

@ -47,7 +47,10 @@ pub(super) fn index_hir<'hir>(
bodies: &IndexVec<ItemLocalId, Option<&'hir Body<'hir>>>, bodies: &IndexVec<ItemLocalId, Option<&'hir Body<'hir>>>,
) -> (IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>, FxHashMap<LocalDefId, ItemLocalId>) { ) -> (IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>, FxHashMap<LocalDefId, ItemLocalId>) {
let mut nodes = IndexVec::new(); let mut nodes = IndexVec::new();
nodes.push(Some(ParentedNode { parent: ItemLocalId::new(0), node: item.into() })); // 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.push(Some(ParentedNode { parent: ItemLocalId::INVALID, node: item.into() }));
let mut collector = NodeCollector { let mut collector = NodeCollector {
source_map: sess.source_map(), source_map: sess.source_map(),
definitions, definitions,

View file

@ -696,7 +696,9 @@ pub struct OwnerNodes<'tcx> {
/// Pre-computed hash of the item signature, sithout recursing into the body. /// Pre-computed hash of the item signature, sithout recursing into the body.
pub hash_without_bodies: Fingerprint, pub hash_without_bodies: Fingerprint,
/// Full HIR for the current owner. /// Full HIR for the current owner.
// The zeroth node's parent is trash, but is never accessed. // The zeroth node's parent should never be accessed: the owner's parent is computed by the
// hir_owner_parent query. It is set to `ItemLocalId::INVALID` to force an ICE if accidentally
// used.
pub nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>, pub nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,
/// Content of local bodies. /// Content of local bodies.
pub bodies: IndexVec<ItemLocalId, Option<&'tcx Body<'tcx>>>, pub bodies: IndexVec<ItemLocalId, Option<&'tcx Body<'tcx>>>,

View file

@ -56,6 +56,10 @@ rustc_index::newtype_index! {
pub struct ItemLocalId { .. } pub struct ItemLocalId { .. }
} }
rustc_data_structures::impl_stable_hash_via_hash!(ItemLocalId); rustc_data_structures::impl_stable_hash_via_hash!(ItemLocalId);
impl ItemLocalId {
/// Signal local id which should never be used.
pub const INVALID: ItemLocalId = ItemLocalId::MAX;
}
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`. /// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`.
pub const CRATE_HIR_ID: HirId = HirId { pub const CRATE_HIR_ID: HirId = HirId {