From c433d542cf64304d2f701c42165bbb4ae55c0309 Mon Sep 17 00:00:00 2001 From: kraktus Date: Sat, 10 Sep 2022 11:36:31 +0200 Subject: [PATCH 1/2] Do not lint `use_self` in proc macro expansion --- clippy_lints/src/use_self.rs | 5 +++-- tests/ui/use_self.fixed | 9 +++++++++ tests/ui/use_self.rs | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 486ea5e5ccfa..d1c00341818c 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::same_type_and_consts; -use clippy_utils::{meets_msrv, msrvs}; +use clippy_utils::{is_from_proc_macro, meets_msrv, msrvs}; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; @@ -87,7 +87,7 @@ impl_lint_pass!(UseSelf => [USE_SELF]); const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element"; impl<'tcx> LateLintPass<'tcx> for UseSelf { - fn check_item(&mut self, _cx: &LateContext<'_>, item: &Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) { if matches!(item.kind, ItemKind::OpaqueTy(_)) { // skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>` return; @@ -103,6 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if parameters.as_ref().map_or(true, |params| { !params.parenthesized && !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_))) }); + if !is_from_proc_macro(cx, item); // expensive, should be last check then { StackItem::Check { impl_id: item.def_id, diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index 4f80aaecc902..37986187da17 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -608,3 +608,12 @@ mod issue8845 { } } } + +mod issue6902 { + use serde::Serialize; + + #[derive(Serialize)] + pub enum Foo { + Bar = 1, + } +} diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 52da72db53ce..1b2b3337c92e 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -608,3 +608,12 @@ mod issue8845 { } } } + +mod issue6902 { + use serde::Serialize; + + #[derive(Serialize)] + pub enum Foo { + Bar = 1, + } +} From 59ee6a89a3e6dc9547002e014470573647f22a8f Mon Sep 17 00:00:00 2001 From: kraktus Date: Sat, 10 Sep 2022 11:47:07 +0200 Subject: [PATCH 2/2] Remove duplicate context check --- clippy_lints/src/use_self.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index d1c00341818c..44ab9bca7959 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -214,9 +214,6 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { hir_ty_to_ty(cx.tcx, hir_ty) }; if same_type_and_consts(ty, cx.tcx.type_of(impl_id)); - let hir = cx.tcx.hir(); - // prevents false positive on `#[derive(serde::Deserialize)]` - if !hir.span(hir.get_parent_node(hir_ty.hir_id)).in_derive_expansion(); then { span_lint(cx, hir_ty.span); }