]> git.lizzy.rs Git - rust.git/commitdiff
[`use_self`] fix FP when trait impl defined in macro
authorkraktus <kraktus@users.noreply.github.com>
Mon, 24 Oct 2022 16:25:59 +0000 (18:25 +0200)
committerkraktus <kraktus@users.noreply.github.com>
Mon, 24 Oct 2022 16:30:16 +0000 (18:30 +0200)
Found when working on `lintcheck --fix`

clippy_lints/src/use_self.rs
tests/ui/use_self_trait.fixed
tests/ui/use_self_trait.rs

index 65f1b5462081925f8faa6045e5f8de142952da1d..acf27c34e94ad9d317681ef51587971ccec58e4c 100644 (file)
@@ -103,6 +103,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
             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 {
index 9bcd692fb3511d805c24f6b49902eb31300936de..12adf1e41a63f81d5221f19b720ae74b8f3c96b7 100644 (file)
@@ -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() {}
index de305d40f330b1a4707995a0f286a844b6da0449..49dbcddc1d8ac4aa488005147ecadbc5779c020d 100644 (file)
@@ -112,4 +112,30 @@ fn vals(_: Self) -> Self {
     }
 }
 
+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() {}