diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-10-12 08:34:38 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-10-12 08:41:53 +0200 |
| commit | c5628a5e656073bd3bceacb7824c2f66845d99f3 (patch) | |
| tree | e11b270899e8820dff00815437e6081dd7a51ae0 | |
| parent | 6b7995195a7d89ee3d5b669ca7424d0f412ad7bb (diff) | |
| download | rust-c5628a5e656073bd3bceacb7824c2f66845d99f3.tar.gz rust-c5628a5e656073bd3bceacb7824c2f66845d99f3.zip | |
Use invalid local id for zeroth node parent.
| -rw-r--r-- | compiler/rustc_ast_lowering/src/index.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/hir.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/hir_id.rs | 4 |
3 files changed, 11 insertions, 2 deletions
diff --git a/compiler/rustc_ast_lowering/src/index.rs b/compiler/rustc_ast_lowering/src/index.rs index 7b0f1caaee1..dc2b1a730fb 100644 --- a/compiler/rustc_ast_lowering/src/index.rs +++ b/compiler/rustc_ast_lowering/src/index.rs @@ -47,7 +47,10 @@ pub(super) fn index_hir<'hir>( bodies: &IndexVec<ItemLocalId, Option<&'hir Body<'hir>>>, ) -> (IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>, FxHashMap<LocalDefId, ItemLocalId>) { 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 { source_map: sess.source_map(), definitions, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 0530a691020..1ec37566fab 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -696,7 +696,9 @@ pub struct OwnerNodes<'tcx> { /// Pre-computed hash of the item signature, sithout recursing into the body. pub hash_without_bodies: Fingerprint, /// 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>>>, /// Content of local bodies. pub bodies: IndexVec<ItemLocalId, Option<&'tcx Body<'tcx>>>, diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs index 0b25ebc27bd..877871f7c3d 100644 --- a/compiler/rustc_hir/src/hir_id.rs +++ b/compiler/rustc_hir/src/hir_id.rs @@ -56,6 +56,10 @@ rustc_index::newtype_index! { pub struct 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`. pub const CRATE_HIR_ID: HirId = HirId { |
