@@ -40,12 +40,6 @@ pub trait MutVisitor: Sized {
40
40
// fn flat_map_t(&mut self, t: T) -> SmallVec<[T; 1]>; // rare
41
41
// fn filter_map_t(&mut self, t: T) -> Option<T>; // rarest
42
42
//
43
- // Any additions to this trait should happen in form of a call to a public
44
- // `noop_*` function that only calls out to the visitor again, not other
45
- // `noop_*` functions. This is a necessary API workaround to the problem of
46
- // not being able to call out to the super default method in an overridden
47
- // default method.
48
- //
49
43
// When writing these methods, it is better to use destructuring like this:
50
44
//
51
45
// fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
@@ -179,7 +173,7 @@ pub trait MutVisitor: Sized {
179
173
}
180
174
181
175
fn filter_map_expr ( & mut self , e : P < Expr > ) -> Option < P < Expr > > {
182
- noop_filter_map_expr ( self , e)
176
+ walk_filter_map_expr ( self , e)
183
177
}
184
178
185
179
fn visit_generic_arg ( & mut self , arg : & mut GenericArg ) {
@@ -381,14 +375,11 @@ super::common_visitor_and_walkers!((mut) MutVisitor);
381
375
/// Use a map-style function (`FnOnce(T) -> T`) to overwrite a `&mut T`. Useful
382
376
/// when using a `flat_map_*` or `filter_map_*` method within a `visit_`
383
377
/// method.
384
- //
385
- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
386
378
pub fn visit_clobber < T : DummyAstNode > ( t : & mut T , f : impl FnOnce ( T ) -> T ) {
387
379
let old_t = std:: mem:: replace ( t, T :: dummy ( ) ) ;
388
380
* t = f ( old_t) ;
389
381
}
390
382
391
- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
392
383
#[ inline]
393
384
fn visit_vec < T , F > ( elems : & mut Vec < T > , mut visit_elem : F )
394
385
where
@@ -399,7 +390,6 @@ where
399
390
}
400
391
}
401
392
402
- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
403
393
#[ inline]
404
394
fn visit_thin_vec < T , F > ( elems : & mut ThinVec < T > , mut visit_elem : F )
405
395
where
@@ -410,7 +400,6 @@ where
410
400
}
411
401
}
412
402
413
- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
414
403
#[ inline]
415
404
fn visit_opt < T , F > ( opt : & mut Option < T > , mut visit_elem : F )
416
405
where
@@ -421,25 +410,21 @@ where
421
410
}
422
411
}
423
412
424
- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
425
413
fn visit_attrs < T : MutVisitor > ( vis : & mut T , attrs : & mut AttrVec ) {
426
414
for attr in attrs. iter_mut ( ) {
427
415
vis. visit_attribute ( attr) ;
428
416
}
429
417
}
430
418
431
- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
432
419
#[ allow( unused) ]
433
420
fn visit_exprs < T : MutVisitor > ( vis : & mut T , exprs : & mut Vec < P < Expr > > ) {
434
421
exprs. flat_map_in_place ( |expr| vis. filter_map_expr ( expr) )
435
422
}
436
423
437
- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
438
424
fn visit_thin_exprs < T : MutVisitor > ( vis : & mut T , exprs : & mut ThinVec < P < Expr > > ) {
439
425
exprs. flat_map_in_place ( |expr| vis. filter_map_expr ( expr) )
440
426
}
441
427
442
- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
443
428
fn visit_attr_args < T : MutVisitor > ( vis : & mut T , args : & mut AttrArgs ) {
444
429
match args {
445
430
AttrArgs :: Empty => { }
@@ -451,7 +436,6 @@ fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
451
436
}
452
437
}
453
438
454
- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
455
439
fn visit_delim_args < T : MutVisitor > ( vis : & mut T , args : & mut DelimArgs ) {
456
440
let DelimArgs { dspan, delim : _, tokens : _ } = args;
457
441
let DelimSpan { open, close } = dspan;
@@ -1041,78 +1025,6 @@ pub fn walk_item_kind<K: WalkItemKind>(
1041
1025
kind. walk ( span, id, visibility, ctxt, vis)
1042
1026
}
1043
1027
1044
- impl WalkItemKind for AssocItemKind {
1045
- type Ctxt = AssocCtxt ;
1046
- fn walk < V : MutVisitor > (
1047
- & mut self ,
1048
- span : Span ,
1049
- id : NodeId ,
1050
- visibility : & mut Visibility ,
1051
- ctxt : Self :: Ctxt ,
1052
- visitor : & mut V ,
1053
- ) {
1054
- match self {
1055
- AssocItemKind :: Const ( item) => {
1056
- walk_const_item ( visitor, item) ;
1057
- }
1058
- AssocItemKind :: Fn ( func) => {
1059
- visitor. visit_fn ( FnKind :: Fn ( FnCtxt :: Assoc ( ctxt) , visibility, & mut * func) , span, id) ;
1060
- }
1061
- AssocItemKind :: Type ( box TyAlias {
1062
- defaultness,
1063
- ident,
1064
- generics,
1065
- where_clauses,
1066
- bounds,
1067
- ty,
1068
- } ) => {
1069
- visit_defaultness ( visitor, defaultness) ;
1070
- visitor. visit_ident ( ident) ;
1071
- visitor. visit_generics ( generics) ;
1072
- visit_bounds ( visitor, bounds, BoundKind :: Bound ) ;
1073
- visit_opt ( ty, |ty| visitor. visit_ty ( ty) ) ;
1074
- walk_ty_alias_where_clauses ( visitor, where_clauses) ;
1075
- }
1076
- AssocItemKind :: MacCall ( mac) => visitor. visit_mac_call ( mac) ,
1077
- AssocItemKind :: Delegation ( box Delegation {
1078
- id,
1079
- qself,
1080
- path,
1081
- ident,
1082
- rename,
1083
- body,
1084
- from_glob : _,
1085
- } ) => {
1086
- visitor. visit_id ( id) ;
1087
- visitor. visit_qself ( qself) ;
1088
- visitor. visit_path ( path) ;
1089
- visitor. visit_ident ( ident) ;
1090
- if let Some ( rename) = rename {
1091
- visitor. visit_ident ( rename) ;
1092
- }
1093
- if let Some ( body) = body {
1094
- visitor. visit_block ( body) ;
1095
- }
1096
- }
1097
- AssocItemKind :: DelegationMac ( box DelegationMac { qself, prefix, suffixes, body } ) => {
1098
- visitor. visit_qself ( qself) ;
1099
- visitor. visit_path ( prefix) ;
1100
- if let Some ( suffixes) = suffixes {
1101
- for ( ident, rename) in suffixes {
1102
- visitor. visit_ident ( ident) ;
1103
- if let Some ( rename) = rename {
1104
- visitor. visit_ident ( rename) ;
1105
- }
1106
- }
1107
- }
1108
- if let Some ( body) = body {
1109
- visitor. visit_block ( body) ;
1110
- }
1111
- }
1112
- }
1113
- }
1114
- }
1115
-
1116
1028
pub fn walk_crate < T : MutVisitor > ( vis : & mut T , krate : & mut Crate ) {
1117
1029
let Crate { attrs, items, spans, id, is_placeholder : _ } = krate;
1118
1030
vis. visit_id ( id) ;
@@ -1123,14 +1035,6 @@ pub fn walk_crate<T: MutVisitor>(vis: &mut T, krate: &mut Crate) {
1123
1035
vis. visit_span ( inject_use_span) ;
1124
1036
}
1125
1037
1126
- pub fn walk_item ( visitor : & mut impl MutVisitor , item : & mut P < Item < impl WalkItemKind < Ctxt = ( ) > > > ) {
1127
- walk_item_ctxt ( visitor, item, ( ) )
1128
- }
1129
-
1130
- pub fn walk_assoc_item ( visitor : & mut impl MutVisitor , item : & mut P < AssocItem > , ctxt : AssocCtxt ) {
1131
- walk_item_ctxt ( visitor, item, ctxt)
1132
- }
1133
-
1134
1038
pub fn walk_flat_map_item ( vis : & mut impl MutVisitor , mut item : P < Item > ) -> SmallVec < [ P < Item > ; 1 ] > {
1135
1039
vis. visit_item ( & mut item) ;
1136
1040
smallvec ! [ item]
@@ -1153,53 +1057,6 @@ pub fn walk_flat_map_assoc_item(
1153
1057
smallvec ! [ item]
1154
1058
}
1155
1059
1156
- impl WalkItemKind for ForeignItemKind {
1157
- type Ctxt = ( ) ;
1158
- fn walk < V : MutVisitor > (
1159
- & mut self ,
1160
- span : Span ,
1161
- id : NodeId ,
1162
- visibility : & mut Visibility ,
1163
- _ctxt : Self :: Ctxt ,
1164
- visitor : & mut V ,
1165
- ) {
1166
- match self {
1167
- ForeignItemKind :: Static ( box StaticItem {
1168
- ident,
1169
- ty,
1170
- mutability : _,
1171
- expr,
1172
- safety : _,
1173
- define_opaque,
1174
- } ) => {
1175
- visitor. visit_ident ( ident) ;
1176
- visitor. visit_ty ( ty) ;
1177
- visit_opt ( expr, |expr| visitor. visit_expr ( expr) ) ;
1178
- walk_define_opaques ( visitor, define_opaque) ;
1179
- }
1180
- ForeignItemKind :: Fn ( func) => {
1181
- visitor. visit_fn ( FnKind :: Fn ( FnCtxt :: Foreign , visibility, & mut * func) , span, id) ;
1182
- }
1183
- ForeignItemKind :: TyAlias ( box TyAlias {
1184
- defaultness,
1185
- ident,
1186
- generics,
1187
- where_clauses,
1188
- bounds,
1189
- ty,
1190
- } ) => {
1191
- visit_defaultness ( visitor, defaultness) ;
1192
- visitor. visit_ident ( ident) ;
1193
- visitor. visit_generics ( generics) ;
1194
- visit_bounds ( visitor, bounds, BoundKind :: Bound ) ;
1195
- visit_opt ( ty, |ty| visitor. visit_ty ( ty) ) ;
1196
- walk_ty_alias_where_clauses ( visitor, where_clauses) ;
1197
- }
1198
- ForeignItemKind :: MacCall ( mac) => visitor. visit_mac_call ( mac) ,
1199
- }
1200
- }
1201
- }
1202
-
1203
1060
pub fn walk_pat < T : MutVisitor > ( vis : & mut T , pat : & mut P < Pat > ) {
1204
1061
let Pat { id, kind, span, tokens : _ } = pat. deref_mut ( ) ;
1205
1062
vis. visit_id ( id) ;
@@ -1500,11 +1357,9 @@ pub fn walk_expr<T: MutVisitor>(vis: &mut T, Expr { kind, id, span, attrs, token
1500
1357
vis. visit_span ( span) ;
1501
1358
}
1502
1359
1503
- pub fn noop_filter_map_expr < T : MutVisitor > ( vis : & mut T , mut e : P < Expr > ) -> Option < P < Expr > > {
1504
- Some ( {
1505
- vis. visit_expr ( & mut e) ;
1506
- e
1507
- } )
1360
+ pub fn walk_filter_map_expr < T : MutVisitor > ( vis : & mut T , mut e : P < Expr > ) -> Option < P < Expr > > {
1361
+ vis. visit_expr ( & mut e) ;
1362
+ Some ( e)
1508
1363
}
1509
1364
1510
1365
pub fn walk_flat_map_stmt < T : MutVisitor > (
0 commit comments