@@ -173,6 +173,12 @@ macro_rules! make_ast_visitor {
173173 }
174174 }
175175
176+ macro_rules! FnKind {
177+ ( ) => {
178+ macro_if!{ $( $lt) ? { FnKind <$( $lt) ?> } else { FnKind <' _> } }
179+ } ;
180+ }
181+
176182 /// Each method of the traits `Visitor` and `MutVisitor` trait is a hook
177183 /// to be potentially overridden. Each method's default implementation
178184 /// recursively visits the substructure of the input via the corresponding
@@ -246,11 +252,6 @@ macro_rules! make_ast_visitor {
246252 walk_flat_map_assoc_item( self , i, ctxt)
247253 }
248254
249- /// `Span` and `NodeId` are mutated at the caller site.
250- fn visit_fn( & mut self , fk: FnKind <' _>, _: Span , _: NodeId ) {
251- walk_fn( self , fk)
252- }
253-
254255 fn flat_map_stmt( & mut self , s: Stmt ) -> SmallVec <[ Stmt ; 1 ] > {
255256 walk_flat_map_stmt( self , s)
256257 }
@@ -312,9 +313,6 @@ macro_rules! make_ast_visitor {
312313 fn visit_expr_post( & mut self , _ex: & ' ast Expr ) -> Self :: Result {
313314 Self :: Result :: output( )
314315 }
315- fn visit_fn( & mut self , fk: FnKind <' ast>, _: Span , _: NodeId ) -> Self :: Result {
316- walk_fn( self , fk)
317- }
318316 fn visit_fn_header( & mut self , _header: & ' ast FnHeader ) -> Self :: Result {
319317 Self :: Result :: output( )
320318 }
@@ -378,6 +376,10 @@ macro_rules! make_ast_visitor {
378376 make_visit!{ ForeignItem ; visit_foreign_item, walk_item}
379377 make_visit!{ Item ; visit_item, walk_item}
380378
379+ fn visit_fn( & mut self , fn_kind: FnKind !( ) , _span: Span , _id: NodeId ) -> result!( ) {
380+ walk_fn( self , fn_kind)
381+ }
382+
381383 fn visit_variant_discr( & mut self , discr: ref_t!( AnonConst ) ) -> result!( ) {
382384 self . visit_anon_const( discr)
383385 }
@@ -1263,6 +1265,29 @@ macro_rules! make_ast_visitor {
12631265 try_v!( visit_span!( visitor, span) ) ;
12641266 return_result!( V )
12651267 }
1268+
1269+ pub fn walk_fn<$( $lt, ) ? V : $trait$( <$lt>) ?>(
1270+ visitor: & mut V ,
1271+ kind: FnKind !( )
1272+ ) -> result!( V ) {
1273+ match kind {
1274+ FnKind :: Fn ( _ctxt, _ident, FnSig { header, decl, span } , _vis, generics, body) => {
1275+ // Identifier and visibility are visited as a part of the item.
1276+ try_v!( visitor. visit_fn_header( header) ) ;
1277+ try_v!( visitor. visit_generics( generics) ) ;
1278+ try_v!( visitor. visit_fn_decl( decl) ) ;
1279+ visit_o!( body, |body| visitor. visit_block( body) ) ;
1280+ try_v!( visit_span!( visitor, span) )
1281+ }
1282+ FnKind :: Closure ( binder, coroutine_kind, decl, body) => {
1283+ visit_o!( coroutine_kind, |ck| visitor. visit_coroutine_kind( ck) ) ;
1284+ try_v!( visitor. visit_closure_binder( binder) ) ;
1285+ try_v!( visitor. visit_fn_decl( decl) ) ;
1286+ try_v!( visitor. visit_expr( body) ) ;
1287+ }
1288+ }
1289+ return_result!( V )
1290+ }
12661291 }
12671292}
12681293
@@ -1527,24 +1552,6 @@ pub mod visit {
15271552 }
15281553 }
15291554
1530- pub fn walk_fn < ' a , V : Visitor < ' a > > ( visitor : & mut V , kind : FnKind < ' a > ) -> V :: Result {
1531- match kind {
1532- FnKind :: Fn ( _ctxt, _ident, FnSig { header, decl, span : _ } , _vis, generics, body) => {
1533- // Identifier and visibility are visited as a part of the item.
1534- try_visit ! ( visitor. visit_fn_header( header) ) ;
1535- try_visit ! ( visitor. visit_generics( generics) ) ;
1536- try_visit ! ( visitor. visit_fn_decl( decl) ) ;
1537- visit_opt ! ( visitor, visit_block, body) ;
1538- }
1539- FnKind :: Closure ( binder, _coroutine_kind, decl, body) => {
1540- try_visit ! ( visitor. visit_closure_binder( binder) ) ;
1541- try_visit ! ( visitor. visit_fn_decl( decl) ) ;
1542- try_visit ! ( visitor. visit_expr( body) ) ;
1543- }
1544- }
1545- V :: Result :: output ( )
1546- }
1547-
15481555 pub fn walk_assoc_item < ' a , V : Visitor < ' a > > (
15491556 visitor : & mut V ,
15501557 item : & ' a AssocItem ,
@@ -2108,27 +2115,6 @@ pub mod mut_visit {
21082115 }
21092116 }
21102117
2111- fn walk_fn < T : MutVisitor > ( vis : & mut T , kind : FnKind < ' _ > ) {
2112- match kind {
2113- FnKind :: Fn ( _, _, FnSig { header, decl, span } , _, generics, body) => {
2114- // Identifier and visibility are visited as a part of the item.
2115- vis. visit_fn_header ( header) ;
2116- vis. visit_generics ( generics) ;
2117- vis. visit_fn_decl ( decl) ;
2118- if let Some ( body) = body {
2119- vis. visit_block ( body) ;
2120- }
2121- vis. visit_span ( span) ;
2122- }
2123- FnKind :: Closure ( binder, coroutine_kind, decl, body) => {
2124- coroutine_kind. as_mut ( ) . map ( |ck| vis. visit_coroutine_kind ( ck) ) ;
2125- vis. visit_closure_binder ( binder) ;
2126- vis. visit_fn_decl ( decl) ;
2127- vis. visit_expr ( body) ;
2128- }
2129- }
2130- }
2131-
21322118 pub fn walk_flat_map_generic_param < T : MutVisitor > (
21332119 vis : & mut T ,
21342120 mut param : GenericParam ,
0 commit comments