@@ -202,7 +202,24 @@ pub(crate) trait Walkable<'a, V: Visitor<'a>> {
202202 fn walk_ref ( & ' a self , visitor : & mut V ) -> V :: Result ;
203203}
204204
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+
206223macro_rules! impl_visitable {
207224 ( |& $lt: lifetime $self: ident: $self_ty: ty,
208225 $vis: ident: & mut $vis_ty: ident,
@@ -215,20 +232,8 @@ macro_rules! impl_visitable {
215232 }
216233 }
217234 } ;
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- } ;
229235}
230236
231- #[ macro_export]
232237macro_rules! impl_walkable {
233238 ( $( <$K: ident: $Kb: ident>) ? |& $lt: lifetime $self: ident: $self_ty: ty,
234239 $vis: ident: & mut $vis_ty: ident| $block: block) => {
@@ -239,18 +244,8 @@ macro_rules! impl_walkable {
239244 }
240245 }
241246 } ;
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- } ;
251247}
252248
253- #[ macro_export]
254249macro_rules! impl_visitable_noop {
255250 ( <$lt: lifetime> $( $ty: ty, ) * ) => {
256251 $(
@@ -259,16 +254,8 @@ macro_rules! impl_visitable_noop {
259254 } ) ;
260255 ) *
261256 } ;
262- ( <mut > $( $ty: ty, ) * ) => {
263- $(
264- impl_visitable!( |& mut self : $ty, _vis: & mut V , _extra: ( ) | { } ) ;
265- ) *
266- }
267257}
268258
269- impl_visitable_noop ! ( <' ast> Span , ) ;
270-
271- #[ macro_export]
272259macro_rules! impl_visitable_list {
273260 ( <$lt: lifetime> $( $ty: ty, ) * ) => {
274261 $( impl <$lt, V : Visitor <$lt>, T > Visitable <$lt, V > for $ty
@@ -287,25 +274,8 @@ macro_rules! impl_visitable_list {
287274 }
288275 } ) *
289276 } ;
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- }
306277}
307278
308- #[ macro_export]
309279macro_rules! impl_visitable_direct {
310280 ( <$lt: lifetime> $( $ty: ty, ) * ) => {
311281 $( impl_visitable!(
@@ -314,78 +284,22 @@ macro_rules! impl_visitable_direct {
314284 }
315285 ) ; ) *
316286 } ;
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- } } ;
346287}
347288
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]
369289macro_rules! impl_visitable_calling_walkable {
370290 ( <$lt: lifetime>
371291 $( fn $method: ident( $ty: ty $( , $extra_name: ident: $extra_ty: ty) ?) ; ) *
372292 ) => {
373293 $( 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+ } ) ;
375298 walk_walkable!( self , node, )
376299 } ) *
377300 } ;
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- }
386301}
387302
388- #[ macro_export]
389303macro_rules! define_named_walk {
390304 ( $Visitor: ident<$lt: lifetime>
391305 $( pub fn $method: ident( $ty: ty) ; ) *
@@ -394,13 +308,6 @@ macro_rules! define_named_walk {
394308 walk_walkable!( visitor, node, )
395309 } ) *
396310 } ;
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- } ;
404311}
405312
406313#[ macro_export]
@@ -470,6 +377,8 @@ macro_rules! common_visitor_and_walkers {
470377 u8 ,
471378 usize ,
472379 ) ;
380+ // `Span` is only a no-op for the non-mutable visitor.
381+ $( impl_visitable_noop!( <$lt> Span , ) ; ) ?
473382
474383 // This macro generates `impl Visitable` and `impl MutVisitable` that simply iterate over
475384 // 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 {
628537 // field access version will continue working and it would be easy to
629538 // forget to add handling for it.
630539 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+ } ) ;
632543 visit_span( self , span)
633544 }
634545
@@ -759,7 +670,9 @@ macro_rules! common_visitor_and_walkers {
759670 // in case it's needed for something like #127241.
760671 #[ inline]
761672 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+ } ) ;
763676 // Do nothing.
764677 }
765678
0 commit comments