Skip to content

Commit b5092dc

Browse files
committed
Unify walk_fn
1 parent afe0d43 commit b5092dc

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> {
@@ -1457,24 +1479,6 @@ pub mod visit {
14571479
V::Result::output()
14581480
}
14591481

1460-
pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result {
1461-
match kind {
1462-
FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span: _ }, _vis, generics, body) => {
1463-
// Identifier and visibility are visited as a part of the item.
1464-
try_visit!(visitor.visit_fn_header(header));
1465-
try_visit!(visitor.visit_generics(generics));
1466-
try_visit!(visitor.visit_fn_decl(decl));
1467-
visit_opt!(visitor, visit_block, body);
1468-
}
1469-
FnKind::Closure(binder, decl, body) => {
1470-
try_visit!(visitor.visit_closure_binder(binder));
1471-
try_visit!(visitor.visit_fn_decl(decl));
1472-
try_visit!(visitor.visit_expr(body));
1473-
}
1474-
}
1475-
V::Result::output()
1476-
}
1477-
14781482
pub fn walk_assoc_item<'a, V: Visitor<'a>>(
14791483
visitor: &mut V,
14801484
item: &'a Item<AssocItemKind>,
@@ -2221,26 +2225,6 @@ pub mod mut_visit {
22212225
}
22222226
}
22232227

2224-
fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
2225-
match kind {
2226-
FnKind::Fn(_, _, FnSig { header, decl, span }, _, generics, body) => {
2227-
// Identifier and visibility are visited as a part of the item.
2228-
vis.visit_fn_header(header);
2229-
vis.visit_generics(generics);
2230-
vis.visit_fn_decl(decl);
2231-
if let Some(body) = body {
2232-
vis.visit_block(body);
2233-
}
2234-
vis.visit_span(span);
2235-
}
2236-
FnKind::Closure(binder, decl, body) => {
2237-
vis.visit_closure_binder(binder);
2238-
vis.visit_fn_decl(decl);
2239-
vis.visit_expr(body);
2240-
}
2241-
}
2242-
}
2243-
22442228
pub fn walk_generic_param<T: MutVisitor>(vis: &mut T, param: &mut GenericParam) {
22452229
let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = param;
22462230
vis.visit_id(id);

0 commit comments

Comments
 (0)