rust/compiler/rustc_ast/src
Matthias Krüger 9d70af54e4
Rollup merge of #133153 - maxcabrajac:flat_maps, r=petrochenkov
Add visits to nodes that already have flat_maps in ast::MutVisitor

This PR aims to add `visit_` methods for every node that has a `flat_map_` in MutVisitor, giving implementers free choice over overriding `flat_map` for 1-to-n conversions or `visit` for a 1-to-1.

There is one major problem: `flat_map_stmt`.
While all other default implementations of `flat_map`s are 1-to-1 conversion, as they either only call visits or a internal 1-to-many conversions are natural, `flat_map_stmt` doesn't follow this pattern.

`flat_map_stmt`'s default implementation is a 1-to-n conversion that panics if n > 1 (effectively being a 1-to-[0;1]). This means that it cannot be used as is for a default `visit_stmt`, which would be required to be a 1-to-1.

Implementing `visit_stmt` without runtime checks would require it to reach over a potential `flat_map_item` or `filter_map_expr` overrides and call for their `visit` counterparts directly.
Other than that, if we want to keep the behavior of `flat_map_stmt` it cannot call `visit_stmt` internally.

To me, it seems reasonable to make all default implementations 1-to-1 conversions and let implementers handle `visit_stmt` if they need it, but I don't know if calling `visit` directly when a 1-to-1 is required is ok or not.

related to #128974 & #127615

r? ``@petrochenkov``
2024-11-21 07:56:12 +01:00
..
attr Add documentation on ast::Attribute 2024-11-05 16:38:15 +01:00
expand Single commit implementing the enzyme/autodiff frontend 2024-10-11 19:13:31 +02:00
util Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr 2024-10-15 11:50:31 +00:00
ast_traits.rs Remove needless returns detected by clippy in the compiler 2024-09-09 13:32:22 +02:00
ast.rs Check for both StmtKind::MacCall and ExprKind::MacCall 2024-11-05 18:23:21 +00:00
entry.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
format.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
lib.rs Add warn(unreachable_pub) to several crates. 2024-08-16 08:46:13 +10:00
mut_visit.rs Rollup merge of #133153 - maxcabrajac:flat_maps, r=petrochenkov 2024-11-21 07:56:12 +01:00
node_id.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
ptr.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
token.rs fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
tokenstream.rs Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
visit.rs Rollup merge of #133153 - maxcabrajac:flat_maps, r=petrochenkov 2024-11-21 07:56:12 +01:00