1
Fork 0

Make Node::ExprField a child of Node::Expr.

This was incorrectly inserting the ExprField as a sibling of the struct
expression.

This required adjusting various parts which were looking at parent node
of a field expression to find the struct.
This commit is contained in:
Eric Huss 2022-07-05 17:42:39 -07:00
parent dcd5177fd4
commit 7b36047239
5 changed files with 139 additions and 148 deletions

View file

@ -226,17 +226,19 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
self.insert(expr.span, expr.hir_id, Node::Expr(expr));
if let ExprKind::Struct(_, fields, _) = expr.kind {
for field in fields {
self.insert(field.span, field.hir_id, Node::ExprField(field));
}
}
self.with_parent(expr.hir_id, |this| {
intravisit::walk_expr(this, expr);
});
}
fn visit_expr_field(&mut self, field: &'hir ExprField<'hir>) {
self.insert(field.span, field.hir_id, Node::ExprField(field));
self.with_parent(field.hir_id, |this| {
intravisit::walk_expr_field(this, field);
});
}
fn visit_stmt(&mut self, stmt: &'hir Stmt<'hir>) {
self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt));