@@ -29,6 +29,14 @@ pub fn has_self_in_block(block: &mut Block) -> bool {
2929 visitor. 0
3030}
3131
32+ fn has_self_in_token_stream ( tokens : TokenStream ) -> bool {
33+ tokens. into_iter ( ) . any ( |tt| match tt {
34+ TokenTree :: Ident ( ident) => ident == "Self" ,
35+ TokenTree :: Group ( group) => has_self_in_token_stream ( group. stream ( ) ) ,
36+ _ => false ,
37+ } )
38+ }
39+
3240struct HasSelf ( bool ) ;
3341
3442impl VisitMut for HasSelf {
@@ -54,6 +62,12 @@ impl VisitMut for HasSelf {
5462 fn visit_item_mut ( & mut self , _: & mut Item ) {
5563 // Do not recurse into nested items.
5664 }
65+
66+ fn visit_macro_mut ( & mut self , mac : & mut Macro ) {
67+ if !contains_fn ( mac. tokens . clone ( ) ) {
68+ self . 0 |= has_self_in_token_stream ( mac. tokens . clone ( ) ) ;
69+ }
70+ }
5771}
5872
5973pub struct ReplaceReceiver {
@@ -278,14 +292,14 @@ impl VisitMut for ReplaceReceiver {
278292 }
279293 }
280294
281- fn visit_macro_mut ( & mut self , i : & mut Macro ) {
295+ fn visit_macro_mut ( & mut self , mac : & mut Macro ) {
282296 // We can't tell in general whether `self` inside a macro invocation
283297 // refers to the self in the argument list or a different self
284298 // introduced within the macro. Heuristic: if the macro input contains
285299 // `fn`, then `self` is more likely to refer to something other than the
286300 // outer function's self argument.
287- if !contains_fn ( i . tokens . clone ( ) ) {
288- self . visit_token_stream ( & mut i . tokens ) ;
301+ if !contains_fn ( mac . tokens . clone ( ) ) {
302+ self . visit_token_stream ( & mut mac . tokens ) ;
289303 }
290304 }
291305}
0 commit comments