Description
The AST visitor (in compiler/rustc_ast/src/visit.rs
) uses struct/enum deconstruction to access fields in its walk_*
methods, e.g.:
pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V::Result {
let Expr { id, kind, span, attrs, tokens: _ } = expression;
walk_list!(visitor, visit_attribute, attrs);
match kind {
...
}
...
}
This is good, because it's impossible to add a new field to an AST type and fail to update the appropriate visitor -- you'll get a compile error. (I swear there was a comment about this, but I can't find it right now.)
In contrast, the HIR visitor (in compiler/rustc_hir/src/intravisit.rs
) uses field access:
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) -> V::Result {
try_visit!(visitor.visit_id(expression.hir_id));
match expression.kind {
...
}
...
}
It would be good to change the HIR visitor to use deconstruction everywhere. This would identify any fields that are currently erroneously unvisited, and prevent future occurrences.
Likewise for the THIR visitor (in compiler/rustc_middle/src/thir/visit.rs
) which is a lot smaller and simpler.
This would be a good task for a new contributor, maybe even a good first bug.