Skip to content

Commit 9dc9f27

Browse files
committed
Unify walk_fn
1 parent 8a5b539 commit 9dc9f27

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

compiler/rustc_ast/src/visitors.rs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,28 @@ macro_rules! make_ast_visitor {
10451045
return_result!(V)
10461046
}
10471047

1048+
pub fn walk_fn<$($lt,)? V: $trait$(<$lt>)?>(
1049+
visitor: &mut V,
1050+
kind: fn_kind!()
1051+
) -> result!(V) {
1052+
match kind {
1053+
FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span }, _vis, generics, body) => {
1054+
// Identifier and visibility are visited as a part of the item.
1055+
try_v!(visitor.visit_fn_header(header));
1056+
try_v!(visitor.visit_generics(generics));
1057+
try_v!(visitor.visit_fn_decl(decl));
1058+
visit_o!(body, |body| visitor.visit_block(body));
1059+
try_v!(visit_span!(visitor, span))
1060+
}
1061+
FnKind::Closure(binder, decl, body) => {
1062+
try_v!(visitor.visit_closure_binder(binder));
1063+
try_v!(visitor.visit_fn_decl(decl));
1064+
try_v!(visitor.visit_expr(body));
1065+
}
1066+
}
1067+
return_result!(V)
1068+
}
1069+
10481070
derive_copy_clone!{
10491071
#[derive(Debug)]
10501072
pub enum FnKind<'a> {
@@ -1465,24 +1487,6 @@ pub mod visit {
14651487
V::Result::output()
14661488
}
14671489

1468-
pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result {
1469-
match kind {
1470-
FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span: _ }, _vis, generics, body) => {
1471-
// Identifier and visibility are visited as a part of the item.
1472-
try_visit!(visitor.visit_fn_header(header));
1473-
try_visit!(visitor.visit_generics(generics));
1474-
try_visit!(visitor.visit_fn_decl(decl));
1475-
visit_opt!(visitor, visit_block, body);
1476-
}
1477-
FnKind::Closure(binder, decl, body) => {
1478-
try_visit!(visitor.visit_closure_binder(binder));
1479-
try_visit!(visitor.visit_fn_decl(decl));
1480-
try_visit!(visitor.visit_expr(body));
1481-
}
1482-
}
1483-
V::Result::output()
1484-
}
1485-
14861490
pub fn walk_assoc_item<'a, V: Visitor<'a>>(
14871491
visitor: &mut V,
14881492
item: &'a Item<AssocItemKind>,
@@ -2236,26 +2240,6 @@ pub mod mut_visit {
22362240
}
22372241
}
22382242

2239-
fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
2240-
match kind {
2241-
FnKind::Fn(_, _, FnSig { header, decl, span }, _, generics, body) => {
2242-
// Identifier and visibility are visited as a part of the item.
2243-
vis.visit_fn_header(header);
2244-
vis.visit_generics(generics);
2245-
vis.visit_fn_decl(decl);
2246-
if let Some(body) = body {
2247-
vis.visit_block(body);
2248-
}
2249-
vis.visit_span(span);
2250-
}
2251-
FnKind::Closure(binder, decl, body) => {
2252-
vis.visit_closure_binder(binder);
2253-
vis.visit_fn_decl(decl);
2254-
vis.visit_expr(body);
2255-
}
2256-
}
2257-
}
2258-
22592243
pub fn walk_generic_param<T: MutVisitor>(vis: &mut T, param: &mut GenericParam) {
22602244
let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = param;
22612245
vis.visit_id(id);

0 commit comments

Comments
 (0)