1
Fork 0

Add visitors for PatField and ExprField.

This helps simplify the code. It also fixes it to use the correct parent
when lowering. One consequence is the `non_snake_case` lint needed
to change the way it looked for parent nodes in a struct pattern.

This also includes a small fix to use the correct `Target` for
expression field attribute validation.
This commit is contained in:
Eric Huss 2022-05-22 18:34:37 -07:00
parent 6c7cb2bb77
commit dcd5177fd4
6 changed files with 55 additions and 73 deletions

View file

@ -193,17 +193,19 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
self.insert(pat.span, pat.hir_id, Node::Pat(pat));
if let PatKind::Struct(_, fields, _) = pat.kind {
for field in fields {
self.insert(field.span, field.hir_id, Node::PatField(field));
}
}
self.with_parent(pat.hir_id, |this| {
intravisit::walk_pat(this, pat);
});
}
fn visit_pat_field(&mut self, field: &'hir PatField<'hir>) {
self.insert(field.span, field.hir_id, Node::PatField(field));
self.with_parent(field.hir_id, |this| {
intravisit::walk_pat_field(this, field);
});
}
fn visit_arm(&mut self, arm: &'hir Arm<'hir>) {
let node = Node::Arm(arm);