9797 }
9898}
9999
100- impl < V : MutVisitor , T > MutVisitable < V > for ( T , )
101- where
102- T : MutVisitable < V > ,
103- {
104- type Extra = T :: Extra ;
105- fn visit_mut ( & mut self , visitor : & mut V , extra : Self :: Extra ) {
106- self . 0 . visit_mut ( visitor, extra) ;
107- }
108- }
109-
110100impl < V : MutVisitor , T1 , T2 > MutVisitable < V > for ( T1 , T2 )
111101where
112102 T1 : MutVisitable < V , Extra = ( ) > ,
@@ -154,23 +144,17 @@ pub trait MutWalkable<V: MutVisitor> {
154144}
155145
156146macro_rules! visit_visitable {
157- ( mut $visitor: expr, $( $expr: expr) ,* $( , ) ?) => { {
147+ ( $visitor: expr, $( $expr: expr) ,* $( , ) ?) => { {
158148 $( MutVisitable :: visit_mut( $expr, $visitor, ( ) ) ; ) *
159149 } } ;
160150}
161151
162152macro_rules! visit_visitable_with {
163- ( mut $visitor: expr, $expr: expr, $extra: expr $( , ) ?) => {
153+ ( $visitor: expr, $expr: expr, $extra: expr $( , ) ?) => {
164154 MutVisitable :: visit_mut( $expr, $visitor, $extra)
165155 } ;
166156}
167157
168- macro_rules! walk_walkable {
169- ( $visitor: expr, $expr: expr, mut ) => {
170- MutWalkable :: walk_mut( $expr, $visitor)
171- } ;
172- }
173-
174158macro_rules! impl_visitable {
175159 ( |& mut $self: ident: $self_ty: ty,
176160 $vis: ident: & mut $vis_ty: ident,
@@ -186,10 +170,9 @@ macro_rules! impl_visitable {
186170}
187171
188172macro_rules! impl_walkable {
189- ( $ ( <$K : ident : $Kb : ident> ) ? |& mut $self: ident: $self_ty: ty,
173+ ( |& mut $self: ident: $self_ty: ty,
190174 $vis: ident: & mut $vis_ty: ident| $block: block) => {
191- #[ allow( unused_parens, non_local_definitions) ]
192- impl <$( $K: $Kb, ) ? $vis_ty: MutVisitor > MutWalkable <$vis_ty> for $self_ty {
175+ impl <$vis_ty: MutVisitor > MutWalkable <$vis_ty> for $self_ty {
193176 fn walk_mut( & mut $self, $vis: & mut $vis_ty) -> V :: Result {
194177 $block
195178 }
@@ -198,15 +181,15 @@ macro_rules! impl_walkable {
198181}
199182
200183macro_rules! impl_visitable_noop {
201- ( < mut > $( $ty: ty, ) * ) => {
184+ ( $( $ty: ty, ) * ) => {
202185 $(
203186 impl_visitable!( |& mut self : $ty, _vis: & mut V , _extra: ( ) | { } ) ;
204187 ) *
205188 } ;
206189}
207190
208191macro_rules! impl_visitable_list {
209- ( < mut > $( $ty: ty, ) * ) => {
192+ ( $( $ty: ty, ) * ) => {
210193 $( impl <V : MutVisitor , T > MutVisitable <V > for $ty
211194 where
212195 for <' a> & ' a mut $ty: IntoIterator <Item = & ' a mut T >,
@@ -225,7 +208,7 @@ macro_rules! impl_visitable_list {
225208}
226209
227210macro_rules! impl_visitable_direct {
228- ( < mut > $( $ty: ty, ) * ) => {
211+ ( $( $ty: ty, ) * ) => {
229212 $( impl_visitable!(
230213 |& mut self : $ty, visitor: & mut V , _extra: ( ) | {
231214 MutWalkable :: walk_mut( self , visitor)
@@ -235,75 +218,61 @@ macro_rules! impl_visitable_direct {
235218}
236219
237220macro_rules! impl_visitable_calling_walkable {
238- ( < mut >
221+ (
239222 $( fn $method: ident( $ty: ty $( , $extra_name: ident: $extra_ty: ty) ?) ; ) *
240223 ) => {
241224 $( fn $method( & mut self , node: & mut $ty $( , $extra_name: $extra_ty) ?) {
242225 impl_visitable!( |& mut self : $ty, visitor: & mut V , extra: ( $( $extra_ty) ?) | {
243226 let ( $( $extra_name) ?) = extra;
244227 visitor. $method( self $( , $extra_name) ?) ;
245228 } ) ;
246- walk_walkable! ( self , node, mut )
229+ MutWalkable :: walk_mut ( node, self )
247230 } ) *
248231 }
249232}
250233
251234macro_rules! define_named_walk {
252- ( ( mut ) $Visitor: ident
235+ ( $Visitor: ident
253236 $( pub fn $method: ident( $ty: ty) ; ) *
254237 ) => {
255238 $( pub fn $method<V : $Visitor>( visitor: & mut V , node: & mut $ty) {
256- walk_walkable! ( visitor , node, mut )
239+ MutWalkable :: walk_mut ( node, visitor )
257240 } ) *
258241 } ;
259242}
260243
261244super :: common_visitor_and_walkers!( ( mut ) MutVisitor ) ;
262245
263246macro_rules! generate_flat_map_visitor_fns {
264- ( $( $name : ident, $Ty: ty, $flat_map_fn : ident$ ( , $param: ident: $ParamTy: ty) * ; ) +) => {
247+ ( $( $flat_map_fn : ident, $Ty: ty $ ( , $param: ident: $ParamTy: ty) ? ; ) +) => {
265248 $(
266249 #[ allow( unused_parens) ]
267250 impl <V : MutVisitor > MutVisitable <V > for ThinVec <$Ty> {
268- type Extra = ( $( $ParamTy) , * ) ;
251+ type Extra = ( $( $ParamTy) ? ) ;
269252
270253 #[ inline]
271- fn visit_mut(
272- & mut self ,
273- visitor: & mut V ,
274- ( $( $param) ,* ) : Self :: Extra ,
275- ) -> V :: Result {
276- $name( visitor, self $( , $param) * )
254+ fn visit_mut( & mut self , visitor: & mut V , ( $( $param) ?) : Self :: Extra ) -> V :: Result {
255+ self . flat_map_in_place( |value| visitor. $flat_map_fn( value $( , $param) ?) ) ;
277256 }
278257 }
279-
280- fn $name<V : MutVisitor >(
281- vis: & mut V ,
282- values: & mut ThinVec <$Ty>,
283- $(
284- $param: $ParamTy,
285- ) *
286- ) {
287- values. flat_map_in_place( |value| vis. $flat_map_fn( value$( , $param) * ) ) ;
288- }
289258 ) +
290259 }
291260}
292261
293262generate_flat_map_visitor_fns ! {
294- visit_items , Box <Item >, flat_map_item ;
295- visit_foreign_items , Box <ForeignItem >, flat_map_foreign_item ;
296- visit_generic_params , GenericParam , flat_map_generic_param ;
297- visit_stmts , Stmt , flat_map_stmt ;
298- visit_exprs , Box <Expr >, filter_map_expr ;
299- visit_expr_fields , ExprField , flat_map_expr_field ;
300- visit_pat_fields , PatField , flat_map_pat_field ;
301- visit_variants , Variant , flat_map_variant ;
302- visit_assoc_items , Box <AssocItem >, flat_map_assoc_item , ctxt: AssocCtxt ;
303- visit_where_predicates , WherePredicate , flat_map_where_predicate ;
304- visit_params , Param , flat_map_param ;
305- visit_field_defs , FieldDef , flat_map_field_def ;
306- visit_arms , Arm , flat_map_arm ;
263+ flat_map_item , Box <Item >;
264+ flat_map_foreign_item , Box <ForeignItem >;
265+ flat_map_generic_param , GenericParam ;
266+ flat_map_stmt , Stmt ;
267+ filter_map_expr , Box <Expr >; // the odd one out; it works because `Option` impls `IntoIterator`
268+ flat_map_expr_field , ExprField ;
269+ flat_map_pat_field , PatField ;
270+ flat_map_variant , Variant ;
271+ flat_map_assoc_item , Box <AssocItem >, ctxt: AssocCtxt ;
272+ flat_map_where_predicate , WherePredicate ;
273+ flat_map_param , Param ;
274+ flat_map_field_def , FieldDef ;
275+ flat_map_arm , Arm ;
307276}
308277
309278pub fn walk_flat_map_pat_field < T : MutVisitor > (
@@ -316,7 +285,11 @@ pub fn walk_flat_map_pat_field<T: MutVisitor>(
316285
317286macro_rules! generate_walk_flat_map_fns {
318287 ( $( $fn_name: ident( $Ty: ty$( , $extra_name: ident: $ExtraTy: ty) * ) => $visit_fn_name: ident; ) +) => { $(
319- pub fn $fn_name<V : MutVisitor >( vis: & mut V , mut value: $Ty$( , $extra_name: $ExtraTy) * ) -> SmallVec <[ $Ty; 1 ] > {
288+ pub fn $fn_name<V : MutVisitor >(
289+ vis: & mut V ,
290+ mut value: $Ty
291+ $( , $extra_name: $ExtraTy) *
292+ ) -> SmallVec <[ $Ty; 1 ] > {
320293 vis. $visit_fn_name( & mut value$( , $extra_name) * ) ;
321294 smallvec![ value]
322295 }
0 commit comments