@@ -87,6 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
8787            // skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>` 
8888            return ; 
8989        } 
90+ 
9091        // We push the self types of `impl`s on a stack here. Only the top type on the stack is 
9192        // relevant for linting, since this is the self type of the `impl` we're currently in. To 
9293        // avoid linting on nested items, we push `StackItem::NoCheck` on the stack to signal, that 
@@ -134,6 +135,14 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
134135    } 
135136
136137    fn  check_impl_item ( & mut  self ,  cx :  & LateContext < ' _ > ,  impl_item :  & hir:: ImplItem < ' _ > )  { 
138+         // Checking items of `impl Self` blocks in which macro expands into. 
139+         // HACK: Nested macros sometimes clears `macro_backtrace` of types in `check_ty`. 
140+         // To work around this problem, we check if this impl_item is from macro expansions. 
141+         // Just remember to remove this state again in `check_impl_item_post`. 
142+         if  impl_item. span . from_expansion ( )  { 
143+             self . stack . push ( StackItem :: NoCheck ) ; 
144+             return ; 
145+         } 
137146        // We want to skip types in trait `impl`s that aren't declared as `Self` in the trait 
138147        // declaration. The collection of those types is all this method implementation does. 
139148        if  let  ImplItemKind :: Fn ( FnSig  {  decl,  .. } ,  ..)  = impl_item. kind 
@@ -189,6 +198,11 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
189198        } 
190199    } 
191200
201+     fn  check_impl_item_post ( & mut  self ,  _:  & LateContext < ' _ > ,  _:  & hir:: ImplItem < ' _ > )  { 
202+         if  let  Some ( StackItem :: NoCheck )  = self . stack . last ( )  { 
203+             self . stack . pop ( ) ; 
204+         } 
205+     } 
192206
193207    fn  check_ty ( & mut  self ,  cx :  & LateContext < ' tcx > ,  hir_ty :  & Ty < ' tcx > )  { 
194208        if  !hir_ty. span . from_expansion ( ) 
0 commit comments