@@ -40,12 +40,6 @@ pub trait MutVisitor: Sized {
4040 // fn flat_map_t(&mut self, t: T) -> SmallVec<[T; 1]>; // rare
4141 // fn filter_map_t(&mut self, t: T) -> Option<T>; // rarest
4242 //
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- //
4943 // When writing these methods, it is better to use destructuring like this:
5044 //
5145 // fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
@@ -179,7 +173,7 @@ pub trait MutVisitor: Sized {
179173 }
180174
181175 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)
183177 }
184178
185179 fn visit_generic_arg ( & mut self , arg : & mut GenericArg ) {
@@ -381,14 +375,11 @@ super::common_visitor_and_walkers!((mut) MutVisitor);
381375/// Use a map-style function (`FnOnce(T) -> T`) to overwrite a `&mut T`. Useful
382376/// when using a `flat_map_*` or `filter_map_*` method within a `visit_`
383377/// method.
384- //
385- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
386378pub fn visit_clobber < T : DummyAstNode > ( t : & mut T , f : impl FnOnce ( T ) -> T ) {
387379 let old_t = std:: mem:: replace ( t, T :: dummy ( ) ) ;
388380 * t = f ( old_t) ;
389381}
390382
391- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
392383#[ inline]
393384fn visit_vec < T , F > ( elems : & mut Vec < T > , mut visit_elem : F )
394385where
@@ -399,7 +390,6 @@ where
399390 }
400391}
401392
402- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
403393#[ inline]
404394fn visit_thin_vec < T , F > ( elems : & mut ThinVec < T > , mut visit_elem : F )
405395where
@@ -410,7 +400,6 @@ where
410400 }
411401}
412402
413- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
414403#[ inline]
415404fn visit_opt < T , F > ( opt : & mut Option < T > , mut visit_elem : F )
416405where
@@ -421,25 +410,21 @@ where
421410 }
422411}
423412
424- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
425413fn visit_attrs < T : MutVisitor > ( vis : & mut T , attrs : & mut AttrVec ) {
426414 for attr in attrs. iter_mut ( ) {
427415 vis. visit_attribute ( attr) ;
428416 }
429417}
430418
431- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
432419#[ allow( unused) ]
433420fn visit_exprs < T : MutVisitor > ( vis : & mut T , exprs : & mut Vec < P < Expr > > ) {
434421 exprs. flat_map_in_place ( |expr| vis. filter_map_expr ( expr) )
435422}
436423
437- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
438424fn visit_thin_exprs < T : MutVisitor > ( vis : & mut T , exprs : & mut ThinVec < P < Expr > > ) {
439425 exprs. flat_map_in_place ( |expr| vis. filter_map_expr ( expr) )
440426}
441427
442- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
443428fn visit_attr_args < T : MutVisitor > ( vis : & mut T , args : & mut AttrArgs ) {
444429 match args {
445430 AttrArgs :: Empty => { }
@@ -451,7 +436,6 @@ fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
451436 }
452437}
453438
454- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
455439fn visit_delim_args < T : MutVisitor > ( vis : & mut T , args : & mut DelimArgs ) {
456440 let DelimArgs { dspan, delim : _, tokens : _ } = args;
457441 let DelimSpan { open, close } = dspan;
@@ -1041,78 +1025,6 @@ pub fn walk_item_kind<K: WalkItemKind>(
10411025 kind. walk ( span, id, visibility, ctxt, vis)
10421026}
10431027
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-
11161028pub fn walk_crate < T : MutVisitor > ( vis : & mut T , krate : & mut Crate ) {
11171029 let Crate { attrs, items, spans, id, is_placeholder : _ } = krate;
11181030 vis. visit_id ( id) ;
@@ -1123,14 +1035,6 @@ pub fn walk_crate<T: MutVisitor>(vis: &mut T, krate: &mut Crate) {
11231035 vis. visit_span ( inject_use_span) ;
11241036}
11251037
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-
11341038pub fn walk_flat_map_item ( vis : & mut impl MutVisitor , mut item : P < Item > ) -> SmallVec < [ P < Item > ; 1 ] > {
11351039 vis. visit_item ( & mut item) ;
11361040 smallvec ! [ item]
@@ -1153,53 +1057,6 @@ pub fn walk_flat_map_assoc_item(
11531057 smallvec ! [ item]
11541058}
11551059
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-
12031060pub fn walk_pat < T : MutVisitor > ( vis : & mut T , pat : & mut P < Pat > ) {
12041061 let Pat { id, kind, span, tokens : _ } = pat. deref_mut ( ) ;
12051062 vis. visit_id ( id) ;
@@ -1500,11 +1357,9 @@ pub fn walk_expr<T: MutVisitor>(vis: &mut T, Expr { kind, id, span, attrs, token
15001357 vis. visit_span ( span) ;
15011358}
15021359
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)
15081363}
15091364
15101365pub fn walk_flat_map_stmt < T : MutVisitor > (
0 commit comments