diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 994ca9b669068..0d56cf5c2b27c 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -128,6 +128,11 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { + // Checking items of `impl Self` blocks in which macro expands into. + if impl_item.span.from_expansion() { + self.stack.push(StackItem::NoCheck); + return; + } // We want to skip types in trait `impl`s that aren't declared as `Self` in the trait // declaration. The collection of those types is all this method implementation does. if let ImplItemKind::Fn(FnSig { decl, .. }, ..) = impl_item.kind @@ -183,6 +188,13 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } } + fn check_impl_item_post(&mut self, _: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { + if impl_item.span.from_expansion() + && let Some(StackItem::NoCheck) = self.stack.last() + { + self.stack.pop(); + } + } fn check_ty(&mut self, cx: &LateContext<'tcx>, hir_ty: &Ty<'tcx, AmbigArg>) { if !hir_ty.span.from_expansion() @@ -197,7 +209,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Def(DefKind::TyParam, _) ) && !types_to_skip.contains(&hir_ty.hir_id) - && let ty = ty_from_hir_ty(cx, hir_ty) + && let ty = ty_from_hir_ty(cx, hir_ty.as_unambig_ty()) && let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity() && same_type_and_consts(ty, impl_ty) // Ensure the type we encounter and the one from the impl have the same lifetime parameters. It may be that diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index c6358a90f1e5b..572e919fb2d21 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -682,12 +682,12 @@ mod issue_13092 { struct MyStruct; impl MyStruct { - macro_inner_item!(Self); + macro_inner_item!(MyStruct); } impl MyStruct { thread_local! { - static SPECIAL: RefCell = RefCell::default(); + static SPECIAL: RefCell = RefCell::default(); } } } diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index 06260a598be25..bd5b685b45d54 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -259,25 +259,5 @@ error: unnecessary structure name repetition LL | E::A => {}, | ^ help: use the applicable keyword: `Self` -error: unnecessary structure name repetition - --> tests/ui/use_self.rs:685:27 - | -LL | macro_inner_item!(MyStruct); - | ^^^^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> tests/ui/use_self.rs:690:37 - | -LL | static SPECIAL: RefCell = RefCell::default(); - | ^^^^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> tests/ui/use_self.rs:690:37 - | -LL | static SPECIAL: RefCell = RefCell::default(); - | ^^^^^^^^ help: use the applicable keyword: `Self` - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 46 previous errors +error: aborting due to 43 previous errors