Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 23a2f98

Browse files
committedOct 14, 2024·
Add make_walk_flat_map
1 parent 68a8d3b commit 23a2f98

File tree

1 file changed

+32
-80
lines changed

1 file changed

+32
-80
lines changed
 

‎compiler/rustc_ast/src/visitors.rs

+32-80
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,38 @@ macro_rules! make_ast_visitor {
17711771
}
17721772
return_result!(V)
17731773
}
1774+
1775+
macro_if!{$($mut)? {
1776+
macro_rules! make_walk_flat_map {
1777+
(
1778+
$ty: ty
1779+
$$(, $arg: ident : $arg_ty: ty)*;
1780+
$walk_flat_map: ident,
1781+
$visit: ident
1782+
) => {
1783+
pub fn $walk_flat_map(
1784+
vis: &mut impl $trait$(<$lt>)?,
1785+
mut arg: $ty
1786+
$$(, $arg: $arg_ty)*
1787+
) -> SmallVec<[$ty; 1]> {
1788+
vis.$visit(&mut arg $$(, $arg)*);
1789+
smallvec![arg]
1790+
}
1791+
}
1792+
}
1793+
1794+
make_walk_flat_map!{Arm; walk_flat_map_arm, visit_arm}
1795+
make_walk_flat_map!{ExprField; walk_flat_map_expr_field, visit_expr_field}
1796+
make_walk_flat_map!{FieldDef; walk_flat_map_field_def, visit_field_def}
1797+
make_walk_flat_map!{GenericParam; walk_flat_map_generic_param, visit_generic_param}
1798+
make_walk_flat_map!{Param; walk_flat_map_param, visit_param}
1799+
make_walk_flat_map!{PatField; walk_flat_map_pat_field, visit_pat_field}
1800+
make_walk_flat_map!{Variant; walk_flat_map_variant, visit_variant}
1801+
1802+
make_walk_flat_map!{P<Item>; walk_flat_map_item, visit_item}
1803+
make_walk_flat_map!{P<AssocItem>, ctxt: AssocCtxt; walk_flat_map_assoc_item, visit_assoc_item}
1804+
make_walk_flat_map!{P<ForeignItem>; walk_flat_map_foreign_item, visit_foreign_item}
1805+
}}
17741806
}
17751807
}
17761808

@@ -1979,27 +2011,6 @@ pub mod mut_visit {
19792011
vis.visit_span(close);
19802012
}
19812013

1982-
pub fn walk_flat_map_pat_field<T: MutVisitor>(
1983-
vis: &mut T,
1984-
mut fp: PatField,
1985-
) -> SmallVec<[PatField; 1]> {
1986-
vis.visit_pat_field(&mut fp);
1987-
smallvec![fp]
1988-
}
1989-
1990-
pub fn walk_flat_map_arm<T: MutVisitor>(vis: &mut T, mut arm: Arm) -> SmallVec<[Arm; 1]> {
1991-
vis.visit_arm(&mut arm);
1992-
smallvec![arm]
1993-
}
1994-
1995-
pub fn walk_flat_map_variant<T: MutVisitor>(
1996-
visitor: &mut T,
1997-
mut variant: Variant,
1998-
) -> SmallVec<[Variant; 1]> {
1999-
visitor.visit_variant(&mut variant);
2000-
smallvec![variant]
2001-
}
2002-
20032014
fn walk_meta_list_item<T: MutVisitor>(vis: &mut T, li: &mut MetaItemInner) {
20042015
match li {
20052016
MetaItemInner::MetaItem(mi) => vis.visit_meta_item(mi),
@@ -2017,14 +2028,6 @@ pub mod mut_visit {
20172028
vis.visit_span(span);
20182029
}
20192030

2020-
pub fn walk_flat_map_param<T: MutVisitor>(
2021-
vis: &mut T,
2022-
mut param: Param,
2023-
) -> SmallVec<[Param; 1]> {
2024-
vis.visit_param(&mut param);
2025-
smallvec![param]
2026-
}
2027-
20282031
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
20292032
fn visit_attr_tt<T: MutVisitor>(vis: &mut T, tt: &mut AttrTokenTree) {
20302033
match tt {
@@ -2171,61 +2174,10 @@ pub mod mut_visit {
21712174
}
21722175
}
21732176

2174-
pub fn walk_flat_map_generic_param<T: MutVisitor>(
2175-
vis: &mut T,
2176-
mut param: GenericParam,
2177-
) -> SmallVec<[GenericParam; 1]> {
2178-
vis.visit_generic_param(&mut param);
2179-
smallvec![param]
2180-
}
2181-
2182-
pub fn walk_flat_map_field_def<T: MutVisitor>(
2183-
visitor: &mut T,
2184-
mut fd: FieldDef,
2185-
) -> SmallVec<[FieldDef; 1]> {
2186-
visitor.visit_field_def(&mut fd);
2187-
smallvec![fd]
2188-
}
2189-
2190-
pub fn walk_flat_map_expr_field<T: MutVisitor>(
2191-
vis: &mut T,
2192-
mut f: ExprField,
2193-
) -> SmallVec<[ExprField; 1]> {
2194-
vis.visit_expr_field(&mut f);
2195-
smallvec![f]
2196-
}
2197-
21982177
pub fn walk_item_kind(item: &mut Item<impl WalkItemKind>, vis: &mut impl MutVisitor) {
21992178
item.kind.walk(item.id, item.span, &mut item.vis, &mut item.ident, vis)
22002179
}
22012180

2202-
/// Mutates one item, returning the item again.
2203-
pub fn walk_flat_map_item(
2204-
vis: &mut impl MutVisitor,
2205-
mut item: P<Item>,
2206-
) -> SmallVec<[P<Item>; 1]> {
2207-
vis.visit_item(&mut item);
2208-
smallvec![item]
2209-
}
2210-
2211-
pub fn walk_flat_map_foreign_item(
2212-
vis: &mut impl MutVisitor,
2213-
mut item: P<ForeignItem>,
2214-
) -> SmallVec<[P<ForeignItem>; 1]> {
2215-
vis.visit_foreign_item(&mut item);
2216-
smallvec![item]
2217-
}
2218-
2219-
/// Mutates one item, returning the item again.
2220-
pub fn walk_flat_map_assoc_item(
2221-
vis: &mut impl MutVisitor,
2222-
mut item: P<AssocItem>,
2223-
ctxt: AssocCtxt,
2224-
) -> SmallVec<[P<AssocItem>; 1]> {
2225-
vis.visit_assoc_item(&mut item, ctxt);
2226-
smallvec![item]
2227-
}
2228-
22292181
pub fn noop_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Option<P<Expr>> {
22302182
Some({
22312183
vis.visit_expr(&mut e);

0 commit comments

Comments
 (0)
Please sign in to comment.