@@ -139,6 +139,13 @@ macro_rules! mutability_helpers {
139
139
} ;
140
140
( $a: expr) => { } ;
141
141
}
142
+
143
+ macro_rules! derive_copy_clone {
144
+ ( $i: item) => {
145
+ #[ derive( Copy , Clone ) ]
146
+ $i
147
+ }
148
+ }
142
149
} ;
143
150
( mut ) => {
144
151
macro_rules! if_mut_ty {
@@ -170,6 +177,12 @@ macro_rules! mutability_helpers {
170
177
$a
171
178
} ;
172
179
}
180
+
181
+ macro_rules! derive_copy_clone {
182
+ ( $i: item) => {
183
+ $i
184
+ }
185
+ }
173
186
} ;
174
187
}
175
188
@@ -1032,6 +1045,17 @@ macro_rules! make_ast_visitor {
1032
1045
return_result!( V )
1033
1046
}
1034
1047
1048
+ derive_copy_clone!{
1049
+ #[ derive( Debug ) ]
1050
+ pub enum FnKind <' a> {
1051
+ /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
1052
+ Fn ( FnCtxt , Ident , & ' a $( $mut) ? FnSig , & ' a $( $mut) ? Visibility , & ' a $( $mut) ? Generics , Option <& ' a $( $mut) ? Block >) ,
1053
+
1054
+ /// E.g., `|x, y| body`.
1055
+ Closure ( & ' a $( $mut) ? ClosureBinder , & ' a $( $mut) ? P !( FnDecl ) , & ' a $( $mut) ? P !( Expr ) ) ,
1056
+ }
1057
+ }
1058
+
1035
1059
make_walk_flat_map!{ Arm , walk_flat_map_arm, visit_arm}
1036
1060
make_walk_flat_map!{ Attribute , walk_flat_map_attribute, visit_attribute}
1037
1061
make_walk_flat_map!{ ExprField , walk_flat_map_expr_field, visit_expr_field}
@@ -1111,15 +1135,6 @@ pub mod visit {
1111
1135
}
1112
1136
}
1113
1137
1114
- #[ derive( Copy , Clone , Debug ) ]
1115
- pub enum FnKind < ' a > {
1116
- /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
1117
- Fn ( FnCtxt , Ident , & ' a FnSig , & ' a Visibility , & ' a Generics , Option < & ' a Block > ) ,
1118
-
1119
- /// E.g., `|x, y| body`.
1120
- Closure ( & ' a ClosureBinder , & ' a FnDecl , & ' a Expr ) ,
1121
- }
1122
-
1123
1138
impl < ' a > FnKind < ' a > {
1124
1139
pub fn header ( & self ) -> Option < & ' a FnHeader > {
1125
1140
match * self {
@@ -1783,7 +1798,7 @@ pub mod mut_visit {
1783
1798
use crate :: ptr:: P ;
1784
1799
use crate :: token:: { self , Token } ;
1785
1800
use crate :: tokenstream:: * ;
1786
- use crate :: visit:: { AssocCtxt , BoundKind , LifetimeCtxt } ;
1801
+ use crate :: visit:: { AssocCtxt , BoundKind , LifetimeCtxt , FnCtxt } ;
1787
1802
1788
1803
pub trait ExpectOne < A : Array > {
1789
1804
fn expect_one ( self , err : & ' static str ) -> A :: Item ;
@@ -2223,7 +2238,7 @@ pub mod mut_visit {
2223
2238
2224
2239
fn walk_fn < T : MutVisitor > ( vis : & mut T , kind : FnKind < ' _ > ) {
2225
2240
match kind {
2226
- FnKind :: Fn ( FnSig { header, decl, span } , generics, body) => {
2241
+ FnKind :: Fn ( _ , _ , FnSig { header, decl, span } , _ , generics, body) => {
2227
2242
// Identifier and visibility are visited as a part of the item.
2228
2243
vis. visit_fn_header ( header) ;
2229
2244
vis. visit_generics ( generics) ;
@@ -2299,8 +2314,8 @@ pub mod mut_visit {
2299
2314
& mut self ,
2300
2315
id : NodeId ,
2301
2316
span : Span ,
2302
- _vis : & mut Visibility ,
2303
- _ident : & mut Ident ,
2317
+ vis : & mut Visibility ,
2318
+ ident : & mut Ident ,
2304
2319
visitor : & mut impl MutVisitor
2305
2320
) {
2306
2321
match self {
@@ -2315,7 +2330,9 @@ pub mod mut_visit {
2315
2330
}
2316
2331
ItemKind :: Fn ( box Fn { defaultness, generics, sig, body } ) => {
2317
2332
visit_defaultness ( visitor, defaultness) ;
2318
- visitor. visit_fn ( FnKind :: Fn ( sig, generics, body) , span, id) ;
2333
+ let kind =
2334
+ FnKind :: Fn ( FnCtxt :: Free , * ident, sig, vis, generics, body. as_deref_mut ( ) ) ;
2335
+ visitor. visit_fn ( kind, span, id) ;
2319
2336
}
2320
2337
ItemKind :: Mod ( safety, mod_kind) => {
2321
2338
visit_safety ( visitor, safety) ;
@@ -2457,7 +2474,7 @@ pub mod mut_visit {
2457
2474
smallvec ! [ item]
2458
2475
}
2459
2476
2460
- pub fn walk_assoc_item ( visitor : & mut impl MutVisitor , item : & mut Item < AssocItemKind > , _ctxt : AssocCtxt ) {
2477
+ pub fn walk_assoc_item ( visitor : & mut impl MutVisitor , item : & mut Item < AssocItemKind > , ctxt : AssocCtxt ) {
2461
2478
let Item { attrs, id, span, vis, ident, kind, tokens } = item;
2462
2479
visitor. visit_id ( id) ;
2463
2480
visit_attrs ( visitor, attrs) ;
@@ -2469,7 +2486,9 @@ pub mod mut_visit {
2469
2486
}
2470
2487
AssocItemKind :: Fn ( box Fn { defaultness, generics, sig, body } ) => {
2471
2488
visit_defaultness ( visitor, defaultness) ;
2472
- visitor. visit_fn ( FnKind :: Fn ( sig, generics, body) , * span, * id) ;
2489
+ let kind =
2490
+ FnKind :: Fn ( FnCtxt :: Assoc ( ctxt) , * ident, sig, vis, generics, body. as_deref_mut ( ) ) ;
2491
+ visitor. visit_fn ( kind, * span, * id) ;
2473
2492
}
2474
2493
AssocItemKind :: Type ( box TyAlias {
2475
2494
defaultness,
@@ -2543,8 +2562,8 @@ pub mod mut_visit {
2543
2562
& mut self ,
2544
2563
id : NodeId ,
2545
2564
span : Span ,
2546
- _vis : & mut Visibility ,
2547
- _ident : & mut Ident ,
2565
+ vis : & mut Visibility ,
2566
+ ident : & mut Ident ,
2548
2567
visitor : & mut impl MutVisitor ) {
2549
2568
match self {
2550
2569
ForeignItemKind :: Static ( box StaticItem { ty, mutability : _, expr, safety : _ } ) => {
@@ -2553,7 +2572,9 @@ pub mod mut_visit {
2553
2572
}
2554
2573
ForeignItemKind :: Fn ( box Fn { defaultness, generics, sig, body } ) => {
2555
2574
visit_defaultness ( visitor, defaultness) ;
2556
- visitor. visit_fn ( FnKind :: Fn ( sig, generics, body) , span, id) ;
2575
+ let kind =
2576
+ FnKind :: Fn ( FnCtxt :: Foreign , * ident, sig, vis, generics, body. as_deref_mut ( ) ) ;
2577
+ visitor. visit_fn ( kind, span, id) ;
2557
2578
}
2558
2579
ForeignItemKind :: TyAlias ( box TyAlias {
2559
2580
defaultness,
@@ -2910,13 +2931,4 @@ pub mod mut_visit {
2910
2931
crate :: ast_traits:: AstNodeWrapper :: new ( N :: dummy ( ) , T :: dummy ( ) )
2911
2932
}
2912
2933
}
2913
-
2914
- #[ derive( Debug ) ]
2915
- pub enum FnKind < ' a > {
2916
- /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
2917
- Fn ( & ' a mut FnSig , & ' a mut Generics , & ' a mut Option < P < Block > > ) ,
2918
-
2919
- /// E.g., `|x, y| body`.
2920
- Closure ( & ' a mut ClosureBinder , & ' a mut P < FnDecl > , & ' a mut P < Expr > ) ,
2921
- }
2922
2934
}
0 commit comments