Assert that HIR nodes are not their own parent.
This commit is contained in:
parent
ccb5595df2
commit
51f486931f
4 changed files with 13 additions and 1 deletions
|
@ -69,6 +69,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||||
fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
|
fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
|
||||||
debug_assert_eq!(self.owner, hir_id.owner);
|
debug_assert_eq!(self.owner, hir_id.owner);
|
||||||
debug_assert_ne!(hir_id.local_id.as_u32(), 0);
|
debug_assert_ne!(hir_id.local_id.as_u32(), 0);
|
||||||
|
debug_assert_ne!(hir_id.local_id, self.parent_node);
|
||||||
|
|
||||||
// Make sure that the DepNode of some node coincides with the HirId
|
// Make sure that the DepNode of some node coincides with the HirId
|
||||||
// owner of that node.
|
// owner of that node.
|
||||||
|
|
|
@ -1256,7 +1256,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
|
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
|
||||||
}
|
}
|
||||||
TyKind::ImplicitSelf => {
|
TyKind::ImplicitSelf => {
|
||||||
let hir_id = self.lower_node_id(t.id);
|
let hir_id = self.next_id();
|
||||||
let res = self.expect_full_res(t.id);
|
let res = self.expect_full_res(t.id);
|
||||||
let res = self.lower_res(res);
|
let res = self.lower_res(res);
|
||||||
hir::TyKind::Path(hir::QPath::Resolved(
|
hir::TyKind::Path(hir::QPath::Resolved(
|
||||||
|
|
|
@ -835,7 +835,16 @@ impl<'tcx> OwnerNodes<'tcx> {
|
||||||
impl fmt::Debug for OwnerNodes<'_> {
|
impl fmt::Debug for OwnerNodes<'_> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("OwnerNodes")
|
f.debug_struct("OwnerNodes")
|
||||||
|
// Do not print all the pointers to all the nodes, as it would be unreadable.
|
||||||
.field("node", &self.nodes[ItemLocalId::from_u32(0)])
|
.field("node", &self.nodes[ItemLocalId::from_u32(0)])
|
||||||
|
.field(
|
||||||
|
"parents",
|
||||||
|
&self
|
||||||
|
.nodes
|
||||||
|
.iter_enumerated()
|
||||||
|
.map(|(id, parented_node)| (id, parented_node.as_ref().map(|node| node.parent)))
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
)
|
||||||
.field("bodies", &self.bodies)
|
.field("bodies", &self.bodies)
|
||||||
.field("local_id_to_def_id", &self.local_id_to_def_id)
|
.field("local_id_to_def_id", &self.local_id_to_def_id)
|
||||||
.field("hash_without_bodies", &self.hash_without_bodies)
|
.field("hash_without_bodies", &self.hash_without_bodies)
|
||||||
|
|
|
@ -301,6 +301,8 @@ impl<'hir> Map<'hir> {
|
||||||
let owner = self.tcx.hir_owner_nodes(id.owner).as_owner()?;
|
let owner = self.tcx.hir_owner_nodes(id.owner).as_owner()?;
|
||||||
let node = owner.nodes[id.local_id].as_ref()?;
|
let node = owner.nodes[id.local_id].as_ref()?;
|
||||||
let hir_id = HirId { owner: id.owner, local_id: node.parent };
|
let hir_id = HirId { owner: id.owner, local_id: node.parent };
|
||||||
|
// HIR indexing should have checked that.
|
||||||
|
debug_assert_ne!(id.local_id, node.parent);
|
||||||
Some(hir_id)
|
Some(hir_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue