Skip to content

Commit a19a5e6

Browse files
committed
Unify walk_closure_binder
1 parent d54c145 commit a19a5e6

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

compiler/rustc_ast/src/visitors.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ macro_rules! make_ast_visitor {
396396
$vis.visit_ident($ident)
397397
,
398398
$vis.visit_ident(*$ident)
399-
) }
399+
)
400+
}
400401
}
401402

402403
macro_rules! return_result {
@@ -416,6 +417,18 @@ macro_rules! make_ast_visitor {
416417
}
417418
}
418419

420+
macro_rules! visit_list {
421+
($visitor: expr, $visit: ident, $flat_map: ident, $list: expr) => {
422+
if_mut_expr!(
423+
$list.flat_map_in_place(|x| $visitor.$flat_map(x))
424+
,
425+
for elem in $list {
426+
try_v!($visitor.$visit(elem));
427+
}
428+
)
429+
}
430+
}
431+
419432
pub fn walk_ident<$($lt,)? V: $trait$(<$lt>)?>(
420433
vis: &mut V,
421434
ident: if_mut_ty!(ref_t!(Ident), Ident)
@@ -527,6 +540,20 @@ macro_rules! make_ast_visitor {
527540
return_result!(V)
528541
}
529542

543+
pub fn walk_closure_binder<$($lt,)? V: $trait$(<$lt>)?>(
544+
vis: &mut V,
545+
binder: ref_t!(ClosureBinder)
546+
) -> result!(V) {
547+
match binder {
548+
ClosureBinder::NotPresent => {}
549+
// TODO: skipped span
550+
ClosureBinder::For { generic_params, span: _ } => {
551+
visit_list!(vis, visit_generic_param, flat_map_generic_param, generic_params)
552+
}
553+
}
554+
return_result!(V)
555+
}
556+
530557
make_walk_flat_map!{Arm, walk_flat_map_arm, visit_arm}
531558
make_walk_flat_map!{ExprField, walk_flat_map_expr_field, visit_expr_field}
532559
make_walk_flat_map!{FieldDef, walk_flat_map_field_def, visit_field_def}
@@ -1117,19 +1144,6 @@ pub mod visit {
11171144
V::Result::output()
11181145
}
11191146

1120-
pub fn walk_closure_binder<'a, V: Visitor<'a>>(
1121-
visitor: &mut V,
1122-
binder: &'a ClosureBinder,
1123-
) -> V::Result {
1124-
match binder {
1125-
ClosureBinder::NotPresent => {}
1126-
ClosureBinder::For { generic_params, span: _ } => {
1127-
walk_list!(visitor, visit_generic_param, generic_params)
1128-
}
1129-
}
1130-
V::Result::output()
1131-
}
1132-
11331147
pub fn walk_where_predicate<'a, V: Visitor<'a>>(
11341148
visitor: &mut V,
11351149
predicate: &'a WherePredicate,
@@ -2144,15 +2158,6 @@ pub mod mut_visit {
21442158
}
21452159
}
21462160

2147-
fn walk_closure_binder<T: MutVisitor>(vis: &mut T, binder: &mut ClosureBinder) {
2148-
match binder {
2149-
ClosureBinder::NotPresent => {}
2150-
ClosureBinder::For { span: _, generic_params } => {
2151-
generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
2152-
}
2153-
}
2154-
}
2155-
21562161
fn walk_coroutine_kind<T: MutVisitor>(vis: &mut T, coroutine_kind: &mut CoroutineKind) {
21572162
match coroutine_kind {
21582163
CoroutineKind::Async { span, closure_id, return_impl_trait_id }

0 commit comments

Comments
 (0)