Skip to content

Commit 2e55b42

Browse files
committed
Auto merge of #9454 - kraktus:use_self, r=flip1995
Do not lint `use_self` in proc macro expansion fix #9440 fix #8910 fix #6902 changelog: [`use_self`]: Do not lint in proc macro expansion
2 parents d574216 + 59ee6a8 commit 2e55b42

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

clippy_lints/src/use_self.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::ty::same_type_and_consts;
3-
use clippy_utils::{meets_msrv, msrvs};
3+
use clippy_utils::{is_from_proc_macro, meets_msrv, msrvs};
44
use if_chain::if_chain;
55
use rustc_data_structures::fx::FxHashSet;
66
use rustc_errors::Applicability;
@@ -87,7 +87,7 @@ impl_lint_pass!(UseSelf => [USE_SELF]);
8787
const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
8888

8989
impl<'tcx> LateLintPass<'tcx> for UseSelf {
90-
fn check_item(&mut self, _cx: &LateContext<'_>, item: &Item<'_>) {
90+
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
9191
if matches!(item.kind, ItemKind::OpaqueTy(_)) {
9292
// skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>`
9393
return;
@@ -103,6 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
103103
if parameters.as_ref().map_or(true, |params| {
104104
!params.parenthesized && !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)))
105105
});
106+
if !is_from_proc_macro(cx, item); // expensive, should be last check
106107
then {
107108
StackItem::Check {
108109
impl_id: item.def_id,
@@ -213,9 +214,6 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
213214
hir_ty_to_ty(cx.tcx, hir_ty)
214215
};
215216
if same_type_and_consts(ty, cx.tcx.type_of(impl_id));
216-
let hir = cx.tcx.hir();
217-
// prevents false positive on `#[derive(serde::Deserialize)]`
218-
if !hir.span(hir.get_parent_node(hir_ty.hir_id)).in_derive_expansion();
219217
then {
220218
span_lint(cx, hir_ty.span);
221219
}

tests/ui/use_self.fixed

+9
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,12 @@ mod issue8845 {
608608
}
609609
}
610610
}
611+
612+
mod issue6902 {
613+
use serde::Serialize;
614+
615+
#[derive(Serialize)]
616+
pub enum Foo {
617+
Bar = 1,
618+
}
619+
}

tests/ui/use_self.rs

+9
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,12 @@ mod issue8845 {
608608
}
609609
}
610610
}
611+
612+
mod issue6902 {
613+
use serde::Serialize;
614+
615+
#[derive(Serialize)]
616+
pub enum Foo {
617+
Bar = 1,
618+
}
619+
}

0 commit comments

Comments
 (0)