Skip to content

Commit 51f4869

Browse files
committed
Assert that HIR nodes are not their own parent.
1 parent ccb5595 commit 51f4869

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

compiler/rustc_ast_lowering/src/index.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
6969
fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
7070
debug_assert_eq!(self.owner, hir_id.owner);
7171
debug_assert_ne!(hir_id.local_id.as_u32(), 0);
72+
debug_assert_ne!(hir_id.local_id, self.parent_node);
7273

7374
// Make sure that the DepNode of some node coincides with the HirId
7475
// owner of that node.

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12561256
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
12571257
}
12581258
TyKind::ImplicitSelf => {
1259-
let hir_id = self.lower_node_id(t.id);
1259+
let hir_id = self.next_id();
12601260
let res = self.expect_full_res(t.id);
12611261
let res = self.lower_res(res);
12621262
hir::TyKind::Path(hir::QPath::Resolved(

compiler/rustc_hir/src/hir.rs

+9
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,16 @@ impl<'tcx> OwnerNodes<'tcx> {
835835
impl fmt::Debug for OwnerNodes<'_> {
836836
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
837837
f.debug_struct("OwnerNodes")
838+
// Do not print all the pointers to all the nodes, as it would be unreadable.
838839
.field("node", &self.nodes[ItemLocalId::from_u32(0)])
840+
.field(
841+
"parents",
842+
&self
843+
.nodes
844+
.iter_enumerated()
845+
.map(|(id, parented_node)| (id, parented_node.as_ref().map(|node| node.parent)))
846+
.collect::<Vec<_>>(),
847+
)
839848
.field("bodies", &self.bodies)
840849
.field("local_id_to_def_id", &self.local_id_to_def_id)
841850
.field("hash_without_bodies", &self.hash_without_bodies)

compiler/rustc_middle/src/hir/map/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ impl<'hir> Map<'hir> {
301301
let owner = self.tcx.hir_owner_nodes(id.owner).as_owner()?;
302302
let node = owner.nodes[id.local_id].as_ref()?;
303303
let hir_id = HirId { owner: id.owner, local_id: node.parent };
304+
// HIR indexing should have checked that.
305+
debug_assert_ne!(id.local_id, node.parent);
304306
Some(hir_id)
305307
}
306308
}

0 commit comments

Comments
 (0)