@@ -29,6 +29,14 @@ pub fn has_self_in_block(block: &mut Block) -> bool {
29
29
visitor. 0
30
30
}
31
31
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
+
32
40
struct HasSelf ( bool ) ;
33
41
34
42
impl VisitMut for HasSelf {
@@ -54,6 +62,12 @@ impl VisitMut for HasSelf {
54
62
fn visit_item_mut ( & mut self , _: & mut Item ) {
55
63
// Do not recurse into nested items.
56
64
}
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
+ }
57
71
}
58
72
59
73
pub struct ReplaceReceiver {
@@ -278,14 +292,14 @@ impl VisitMut for ReplaceReceiver {
278
292
}
279
293
}
280
294
281
- fn visit_macro_mut ( & mut self , i : & mut Macro ) {
295
+ fn visit_macro_mut ( & mut self , mac : & mut Macro ) {
282
296
// We can't tell in general whether `self` inside a macro invocation
283
297
// refers to the self in the argument list or a different self
284
298
// introduced within the macro. Heuristic: if the macro input contains
285
299
// `fn`, then `self` is more likely to refer to something other than the
286
300
// 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 ) ;
289
303
}
290
304
}
291
305
}
0 commit comments