@@ -202,7 +202,24 @@ pub(crate) trait Walkable<'a, V: Visitor<'a>> {
202
202
fn walk_ref ( & ' a self , visitor : & mut V ) -> V :: Result ;
203
203
}
204
204
205
- #[ macro_export]
205
+ macro_rules! visit_visitable {
206
+ ( $visitor: expr, $( $expr: expr) ,* $( , ) ?) => { {
207
+ $( try_visit!( Visitable :: visit( $expr, $visitor, ( ) ) ) ; ) *
208
+ } } ;
209
+ }
210
+
211
+ macro_rules! visit_visitable_with {
212
+ ( $visitor: expr, $expr: expr, $extra: expr $( , ) ?) => {
213
+ try_visit!( Visitable :: visit( $expr, $visitor, $extra) )
214
+ } ;
215
+ }
216
+
217
+ macro_rules! walk_walkable {
218
+ ( $visitor: expr, $expr: expr, ) => {
219
+ Walkable :: walk_ref( $expr, $visitor)
220
+ } ;
221
+ }
222
+
206
223
macro_rules! impl_visitable {
207
224
( |& $lt: lifetime $self: ident: $self_ty: ty,
208
225
$vis: ident: & mut $vis_ty: ident,
@@ -215,20 +232,8 @@ macro_rules! impl_visitable {
215
232
}
216
233
}
217
234
} ;
218
- ( |& mut $self: ident: $self_ty: ty,
219
- $vis: ident: & mut $vis_ty: ident,
220
- $extra: ident: $extra_ty: ty| $block: block) => {
221
- #[ allow( unused_parens, non_local_definitions) ]
222
- impl <$vis_ty: MutVisitor > MutVisitable <$vis_ty> for $self_ty {
223
- type Extra = $extra_ty;
224
- fn visit_mut( & mut $self, $vis: & mut $vis_ty, $extra: Self :: Extra ) {
225
- $block
226
- }
227
- }
228
- } ;
229
235
}
230
236
231
- #[ macro_export]
232
237
macro_rules! impl_walkable {
233
238
( $( <$K: ident: $Kb: ident>) ? |& $lt: lifetime $self: ident: $self_ty: ty,
234
239
$vis: ident: & mut $vis_ty: ident| $block: block) => {
@@ -239,18 +244,8 @@ macro_rules! impl_walkable {
239
244
}
240
245
}
241
246
} ;
242
- ( $( <$K: ident: $Kb: ident>) ? |& mut $self: ident: $self_ty: ty,
243
- $vis: ident: & mut $vis_ty: ident| $block: block) => {
244
- #[ allow( unused_parens, non_local_definitions) ]
245
- impl <$( $K: $Kb, ) ? $vis_ty: MutVisitor > MutWalkable <$vis_ty> for $self_ty {
246
- fn walk_mut( & mut $self, $vis: & mut $vis_ty) {
247
- $block
248
- }
249
- }
250
- } ;
251
247
}
252
248
253
- #[ macro_export]
254
249
macro_rules! impl_visitable_noop {
255
250
( <$lt: lifetime> $( $ty: ty, ) * ) => {
256
251
$(
@@ -259,16 +254,8 @@ macro_rules! impl_visitable_noop {
259
254
} ) ;
260
255
) *
261
256
} ;
262
- ( <mut > $( $ty: ty, ) * ) => {
263
- $(
264
- impl_visitable!( |& mut self : $ty, _vis: & mut V , _extra: ( ) | { } ) ;
265
- ) *
266
- }
267
257
}
268
258
269
- impl_visitable_noop ! ( <' ast> Span , ) ;
270
-
271
- #[ macro_export]
272
259
macro_rules! impl_visitable_list {
273
260
( <$lt: lifetime> $( $ty: ty, ) * ) => {
274
261
$( impl <$lt, V : Visitor <$lt>, T > Visitable <$lt, V > for $ty
@@ -287,25 +274,8 @@ macro_rules! impl_visitable_list {
287
274
}
288
275
} ) *
289
276
} ;
290
- ( <mut > $( $ty: ty, ) * ) => {
291
- $( impl <V : MutVisitor , T > MutVisitable <V > for $ty
292
- where
293
- for <' a> & ' a mut $ty: IntoIterator <Item = & ' a mut T >,
294
- T : MutVisitable <V >,
295
- {
296
- type Extra = <T as MutVisitable <V >>:: Extra ;
297
-
298
- #[ inline]
299
- fn visit_mut( & mut self , visitor: & mut V , extra: Self :: Extra ) {
300
- for i in self {
301
- i. visit_mut( visitor, extra) ;
302
- }
303
- }
304
- } ) *
305
- }
306
277
}
307
278
308
- #[ macro_export]
309
279
macro_rules! impl_visitable_direct {
310
280
( <$lt: lifetime> $( $ty: ty, ) * ) => {
311
281
$( impl_visitable!(
@@ -314,78 +284,22 @@ macro_rules! impl_visitable_direct {
314
284
}
315
285
) ; ) *
316
286
} ;
317
- ( <mut > $( $ty: ty, ) * ) => {
318
- $( impl_visitable!(
319
- |& mut self : $ty, visitor: & mut V , _extra: ( ) | {
320
- MutWalkable :: walk_mut( self , visitor)
321
- }
322
- ) ; ) *
323
- }
324
- }
325
-
326
- #[ macro_export]
327
- macro_rules! impl_visitable_calling {
328
- ( $method: ident<$( $lt: lifetime) ? $( $mut: ident) ?>( $ty: ty $( , $extra: ident: $extra_ty: ty) ?) ) => {
329
- impl_visitable!(
330
- |& $( $lt) ? $( $mut) ? self : $ty, visitor: & mut V , extra: ( $( $extra_ty) ?) | {
331
- let ( $( $extra) ?) = extra;
332
- visitor. $method( self $( , $extra) ?)
333
- }
334
- )
335
- } ;
336
- }
337
-
338
- #[ macro_export]
339
- macro_rules! visit_visitable {
340
- ( $visitor: expr, $( $expr: expr) ,* $( , ) ?) => { {
341
- $( try_visit!( Visitable :: visit( $expr, $visitor, ( ) ) ) ; ) *
342
- } } ;
343
- ( mut $visitor: expr, $( $expr: expr) ,* $( , ) ?) => { {
344
- $( MutVisitable :: visit_mut( $expr, $visitor, ( ) ) ; ) *
345
- } } ;
346
287
}
347
288
348
- #[ macro_export]
349
- macro_rules! visit_visitable_with {
350
- ( $visitor: expr, $expr: expr, $extra: expr $( , ) ?) => {
351
- try_visit!( Visitable :: visit( $expr, $visitor, $extra) )
352
- } ;
353
- ( mut $visitor: expr, $expr: expr, $extra: expr $( , ) ?) => {
354
- MutVisitable :: visit_mut( $expr, $visitor, $extra)
355
- } ;
356
- }
357
-
358
- #[ macro_export]
359
- macro_rules! walk_walkable {
360
- ( $visitor: expr, $expr: expr, ) => {
361
- Walkable :: walk_ref( $expr, $visitor)
362
- } ;
363
- ( $visitor: expr, $expr: expr, mut ) => {
364
- MutWalkable :: walk_mut( $expr, $visitor)
365
- } ;
366
- }
367
-
368
- #[ macro_export]
369
289
macro_rules! impl_visitable_calling_walkable {
370
290
( <$lt: lifetime>
371
291
$( fn $method: ident( $ty: ty $( , $extra_name: ident: $extra_ty: ty) ?) ; ) *
372
292
) => {
373
293
$( fn $method( & mut self , node: & $lt $ty $( , $extra_name: $extra_ty) ?) -> Self :: Result {
374
- impl_visitable_calling!( $method<$lt>( $ty $( , $extra_name: $extra_ty) ?) ) ;
294
+ impl_visitable!( |& $lt self : $ty, visitor: & mut V , extra: ( $( $extra_ty) ?) | {
295
+ let ( $( $extra_name) ?) = extra;
296
+ visitor. $method( self $( , $extra_name) ?)
297
+ } ) ;
375
298
walk_walkable!( self , node, )
376
299
} ) *
377
300
} ;
378
- ( <mut >
379
- $( fn $method: ident( $ty: ty $( , $extra_name: ident: $extra_ty: ty) ?) ; ) *
380
- ) => {
381
- $( fn $method( & mut self , node: & mut $ty $( , $extra_name: $extra_ty) ?) {
382
- impl_visitable_calling!( $method<mut >( $ty $( , $extra_name: $extra_ty) ?) ) ;
383
- walk_walkable!( self , node, mut )
384
- } ) *
385
- }
386
301
}
387
302
388
- #[ macro_export]
389
303
macro_rules! define_named_walk {
390
304
( $Visitor: ident<$lt: lifetime>
391
305
$( pub fn $method: ident( $ty: ty) ; ) *
@@ -394,13 +308,6 @@ macro_rules! define_named_walk {
394
308
walk_walkable!( visitor, node, )
395
309
} ) *
396
310
} ;
397
- ( ( mut ) $Visitor: ident
398
- $( pub fn $method: ident( $ty: ty) ; ) *
399
- ) => {
400
- $( pub fn $method<V : $Visitor>( visitor: & mut V , node: & mut $ty) {
401
- walk_walkable!( visitor, node, mut )
402
- } ) *
403
- } ;
404
311
}
405
312
406
313
#[ macro_export]
@@ -470,6 +377,8 @@ macro_rules! common_visitor_and_walkers {
470
377
u8 ,
471
378
usize ,
472
379
) ;
380
+ // `Span` is only a no-op for the non-mutable visitor.
381
+ $( impl_visitable_noop!( <$lt> Span , ) ; ) ?
473
382
474
383
// This macro generates `impl Visitable` and `impl MutVisitable` that simply iterate over
475
384
// their contents. We do not use a generic impl for `ThinVec` because we want to allow
@@ -628,7 +537,9 @@ macro_rules! common_visitor_and_walkers {
628
537
// field access version will continue working and it would be easy to
629
538
// forget to add handling for it.
630
539
fn visit_ident( & mut self , Ident { name: _, span } : & $( $lt) ? $( $mut) ? Ident ) -> Self :: Result {
631
- impl_visitable_calling!( visit_ident<$( $lt) ? $( $mut) ?>( Ident ) ) ;
540
+ impl_visitable!( |& $( $lt) ? $( $mut) ? self : Ident , visitor: & mut V , _extra: ( ) | {
541
+ visitor. visit_ident( self )
542
+ } ) ;
632
543
visit_span( self , span)
633
544
}
634
545
@@ -759,7 +670,9 @@ macro_rules! common_visitor_and_walkers {
759
670
// in case it's needed for something like #127241.
760
671
#[ inline]
761
672
fn visit_span( & mut self , _sp: & $mut Span ) {
762
- impl_visitable_calling!( visit_span<$mut>( Span ) ) ;
673
+ impl_visitable!( |& mut self : Span , visitor: & mut V , _extra: ( ) | {
674
+ visitor. visit_span( self )
675
+ } ) ;
763
676
// Do nothing.
764
677
}
765
678
0 commit comments