Skip to content

Commit a1b90e8

Browse files
Auto merge of #142706 - fee1-dead-contrib:push-zsznlqyrzsqo, r=<try>
completely deduplicate `Visitor` and `MutVisitor` r? oli-obk This closes #127615. ### Discussion > * Give every `MutVisitor::visit_*` method a corresponding `flat_map_*` method. Not every AST node exists in a location where they can be mapped to multiple instances of themselves. Not every AST node exists in a location where they can be removed from existence (e.g. `filter_map_expr`). I don't think this is doable. > * Give every `MutVisitor::visit_*` method a corresponding `Visitor` method and vice versa The only three remaining method-level asymmetries after this PR are `visit_stmt` and `visit_nested_use_tree` (only on `Visitor`) and `visit_span` (only on `MutVisitor`). `visit_stmt` doesn't seem applicable to `MutVisitor` because `walk_flat_map_stmt_kind` will ask `flat_map_item` / `filter_map_expr` to potentially turn a single `Stmt` to multiple based on what a visitor wants. So only using `flat_map_stmt` seems appropriate. `visit_nested_use_tree` is used for `rustc_resolve` to track stuff. Not useful for `MutVisitor` for now. `visit_span` is currently not used for `MutVisitor` already, it was just kept in case we want to revive #127241. cc `@cjgillot` maybe we could remove for now and re-insert later if we find a use-case? It does involve some extra effort to maintain. * Remaining FIXMEs `visit_lifetime` has an extra param for `Visitor` that's not in `MutVisitor`. This is again something only used by `rustc_resolve`. I think we can keep that symmetry for now.
2 parents 8a65ee0 + ed397ad commit a1b90e8

File tree

8 files changed

+464
-723
lines changed

8 files changed

+464
-723
lines changed

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ impl<Wrapped, Tag> AstNodeWrapper<Wrapped, Tag> {
321321
}
322322
}
323323

324+
// FIXME: remove after `stmt_expr_attributes` is stabilized.
325+
impl<T, Tag> From<AstNodeWrapper<P<T>, Tag>> for AstNodeWrapper<T, Tag> {
326+
fn from(value: AstNodeWrapper<P<T>, Tag>) -> Self {
327+
AstNodeWrapper { wrapped: *value.wrapped, tag: value.tag }
328+
}
329+
}
330+
324331
impl<Wrapped: HasNodeId, Tag> HasNodeId for AstNodeWrapper<Wrapped, Tag> {
325332
fn node_id(&self) -> NodeId {
326333
self.wrapped.node_id()

0 commit comments

Comments
 (0)