diff options
| author | kraktus <kraktus@users.noreply.github.com> | 2022-10-24 18:25:59 +0200 |
|---|---|---|
| committer | kraktus <kraktus@users.noreply.github.com> | 2022-10-24 18:30:16 +0200 |
| commit | e86e810889481d6f4284e6ec29224ed5fca490bd (patch) | |
| tree | 3d0ae2f444684f28db81e39bad707cdd9978da4d | |
| parent | 628a79d6b67cc2acd2019f6c3c8e5adbc4384c9c (diff) | |
| download | rust-e86e810889481d6f4284e6ec29224ed5fca490bd.tar.gz rust-e86e810889481d6f4284e6ec29224ed5fca490bd.zip | |
[`use_self`] fix FP when trait impl defined in macro
Found when working on `lintcheck --fix`
| -rw-r--r-- | clippy_lints/src/use_self.rs | 1 | ||||
| -rw-r--r-- | tests/ui/use_self_trait.fixed | 26 | ||||
| -rw-r--r-- | tests/ui/use_self_trait.rs | 26 |
3 files changed, 53 insertions, 0 deletions
diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 65f1b546208..acf27c34e94 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -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 !item.span.from_expansion(); if !is_from_proc_macro(cx, item); // expensive, should be last check then { StackItem::Check { diff --git a/tests/ui/use_self_trait.fixed b/tests/ui/use_self_trait.fixed index 9bcd692fb35..12adf1e41a6 100644 --- a/tests/ui/use_self_trait.fixed +++ b/tests/ui/use_self_trait.fixed @@ -112,4 +112,30 @@ impl NameTrait for u8 { } } +mod impl_in_macro { + macro_rules! parse_ip_impl { + // minimized from serde=1.0.118 + ($ty:ty) => { + impl FooTrait for $ty { + fn new() -> Self { + <$ty>::bar() + } + } + }; + } + + struct Foo; + + trait FooTrait { + fn new() -> Self; + } + + impl Foo { + fn bar() -> Self { + Self + } + } + parse_ip_impl!(Foo); // Should not lint +} + fn main() {} diff --git a/tests/ui/use_self_trait.rs b/tests/ui/use_self_trait.rs index de305d40f33..49dbcddc1d8 100644 --- a/tests/ui/use_self_trait.rs +++ b/tests/ui/use_self_trait.rs @@ -112,4 +112,30 @@ impl NameTrait for u8 { } } +mod impl_in_macro { + macro_rules! parse_ip_impl { + // minimized from serde=1.0.118 + ($ty:ty) => { + impl FooTrait for $ty { + fn new() -> Self { + <$ty>::bar() + } + } + }; + } + + struct Foo; + + trait FooTrait { + fn new() -> Self; + } + + impl Foo { + fn bar() -> Self { + Self + } + } + parse_ip_impl!(Foo); // Should not lint +} + fn main() {} |
