@@ -236,7 +236,10 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
236
236
}
237
237
238
238
fn check_ty ( & mut self , cx : & LateContext < ' _ > , hir_ty : & hir:: Ty < ' _ > ) {
239
- if in_macro ( hir_ty. span ) | in_impl ( cx, hir_ty) | !meets_msrv ( self . msrv . as_ref ( ) , & USE_SELF_MSRV ) {
239
+ if in_macro_recursively ( cx, hir_ty. hir_id )
240
+ | in_impl ( cx, hir_ty)
241
+ | !meets_msrv ( self . msrv . as_ref ( ) , & USE_SELF_MSRV )
242
+ {
240
243
return ;
241
244
}
242
245
@@ -265,15 +268,12 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
265
268
// https://github.com/rust-lang/rust/blob/master/src/librustc_ast_lowering/path.rs#l142-l162
266
269
let hir = cx. tcx . hir ( ) ;
267
270
let id = hir. get_parent_node ( hir_ty. hir_id ) ;
268
-
269
- if !hir. opt_span ( id) . map_or ( false , in_macro) {
270
- match hir. find ( id) {
271
- Some ( Node :: Expr ( Expr {
272
- kind : ExprKind :: Path ( QPath :: TypeRelative ( _, segment) ) ,
273
- ..
274
- } ) ) => span_lint_until_last_segment ( cx, hir_ty. span , segment) ,
275
- _ => span_lint ( cx, hir_ty. span ) ,
276
- }
271
+ match hir. find ( id) {
272
+ Some ( Node :: Expr ( Expr {
273
+ kind : ExprKind :: Path ( QPath :: TypeRelative ( _, segment) ) ,
274
+ ..
275
+ } ) ) => span_lint_until_last_segment ( cx, hir_ty. span , segment) ,
276
+ _ => span_lint ( cx, hir_ty. span ) ,
277
277
}
278
278
}
279
279
}
@@ -288,7 +288,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
288
288
}
289
289
}
290
290
291
- if in_macro ( expr. span ) | !meets_msrv ( self . msrv . as_ref ( ) , & USE_SELF_MSRV ) {
291
+ if in_macro_recursively ( cx , expr. hir_id ) | !meets_msrv ( self . msrv . as_ref ( ) , & USE_SELF_MSRV ) {
292
292
return ;
293
293
}
294
294
@@ -467,3 +467,18 @@ fn should_lint_ty(hir_ty: &hir::Ty<'_>, ty: Ty<'_>, self_ty: Ty<'_>) -> bool {
467
467
}
468
468
}
469
469
}
470
+
471
+ fn in_macro_recursively ( cx : & LateContext < ' _ > , hir_id : HirId ) -> bool {
472
+ let map = cx. tcx . hir ( ) ;
473
+ if map. opt_span ( hir_id) . map_or ( false , in_macro) {
474
+ return true ;
475
+ }
476
+
477
+ for ( parent_id, _) in map. parent_iter ( hir_id) {
478
+ if map. opt_span ( parent_id) . map_or ( false , in_macro) {
479
+ return true ;
480
+ }
481
+ }
482
+
483
+ false
484
+ }
0 commit comments