about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryanglsh <yanglsh@shanghaitech.edu.cn>2025-07-27 15:13:34 +0800
committeryanglsh <yanglsh@shanghaitech.edu.cn>2025-07-27 15:13:34 +0800
commitc78f3aedfc262c95b08d944c878976dcc133dcf3 (patch)
tree4a326ffe7257469c5589ee1aed151a4720330bc9
parent03978193a5900c0d4767891eee408a54aaf1915c (diff)
fix: `empty_structs_with_brackets` suggests wrongly on generics
-rw-r--r--clippy_lints/src/empty_with_brackets.rs4
-rw-r--r--tests/ui/empty_structs_with_brackets.fixed14
-rw-r--r--tests/ui/empty_structs_with_brackets.rs14
-rw-r--r--tests/ui/empty_structs_with_brackets.stderr10
4 files changed, 39 insertions, 3 deletions
diff --git a/clippy_lints/src/empty_with_brackets.rs b/clippy_lints/src/empty_with_brackets.rs
index f2757407ba5..e7230ebf8cb 100644
--- a/clippy_lints/src/empty_with_brackets.rs
+++ b/clippy_lints/src/empty_with_brackets.rs
@@ -93,11 +93,11 @@ impl_lint_pass!(EmptyWithBrackets => [EMPTY_STRUCTS_WITH_BRACKETS, EMPTY_ENUM_VA
 impl LateLintPass<'_> for EmptyWithBrackets {
     fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
         // FIXME: handle `struct $name {}`
-        if let ItemKind::Struct(ident, _, var_data) = &item.kind
+        if let ItemKind::Struct(ident, generics, var_data) = &item.kind
             && !item.span.from_expansion()
             && !ident.span.from_expansion()
             && has_brackets(var_data)
-            && let span_after_ident = item.span.with_lo(ident.span.hi())
+            && let span_after_ident = item.span.with_lo(generics.span.hi())
             && has_no_fields(cx, var_data, span_after_ident)
         {
             span_lint_and_then(
diff --git a/tests/ui/empty_structs_with_brackets.fixed b/tests/ui/empty_structs_with_brackets.fixed
index 419cf2354f8..22386245ffe 100644
--- a/tests/ui/empty_structs_with_brackets.fixed
+++ b/tests/ui/empty_structs_with_brackets.fixed
@@ -32,3 +32,17 @@ macro_rules! empty_struct {
 empty_struct!(FromMacro);
 
 fn main() {}
+
+mod issue15349 {
+    trait Bar<T> {}
+    impl<T> Bar<T> for [u8; 7] {}
+
+    struct Foo<const N: usize>;
+    //~^ empty_structs_with_brackets
+    impl<const N: usize> Foo<N>
+    where
+        [u8; N]: Bar<[(); N]>,
+    {
+        fn foo() {}
+    }
+}
diff --git a/tests/ui/empty_structs_with_brackets.rs b/tests/ui/empty_structs_with_brackets.rs
index 90c415c1220..5cb54b66134 100644
--- a/tests/ui/empty_structs_with_brackets.rs
+++ b/tests/ui/empty_structs_with_brackets.rs
@@ -32,3 +32,17 @@ macro_rules! empty_struct {
 empty_struct!(FromMacro);
 
 fn main() {}
+
+mod issue15349 {
+    trait Bar<T> {}
+    impl<T> Bar<T> for [u8; 7] {}
+
+    struct Foo<const N: usize> {}
+    //~^ empty_structs_with_brackets
+    impl<const N: usize> Foo<N>
+    where
+        [u8; N]: Bar<[(); N]>,
+    {
+        fn foo() {}
+    }
+}
diff --git a/tests/ui/empty_structs_with_brackets.stderr b/tests/ui/empty_structs_with_brackets.stderr
index 86ef43aa960..f662bb9423e 100644
--- a/tests/ui/empty_structs_with_brackets.stderr
+++ b/tests/ui/empty_structs_with_brackets.stderr
@@ -16,5 +16,13 @@ LL | struct MyEmptyTupleStruct(); // should trigger lint
    |
    = help: remove the brackets
 
-error: aborting due to 2 previous errors
+error: found empty brackets on struct declaration
+  --> tests/ui/empty_structs_with_brackets.rs:40:31
+   |
+LL |     struct Foo<const N: usize> {}
+   |                               ^^^
+   |
+   = help: remove the brackets
+
+error: aborting due to 3 previous errors