Skip to content

Commit c78f3ae

Browse files
committed
fix: empty_structs_with_brackets suggests wrongly on generics
1 parent 0397819 commit c78f3ae

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

clippy_lints/src/empty_with_brackets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ impl_lint_pass!(EmptyWithBrackets => [EMPTY_STRUCTS_WITH_BRACKETS, EMPTY_ENUM_VA
9393
impl LateLintPass<'_> for EmptyWithBrackets {
9494
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
9595
// FIXME: handle `struct $name {}`
96-
if let ItemKind::Struct(ident, _, var_data) = &item.kind
96+
if let ItemKind::Struct(ident, generics, var_data) = &item.kind
9797
&& !item.span.from_expansion()
9898
&& !ident.span.from_expansion()
9999
&& has_brackets(var_data)
100-
&& let span_after_ident = item.span.with_lo(ident.span.hi())
100+
&& let span_after_ident = item.span.with_lo(generics.span.hi())
101101
&& has_no_fields(cx, var_data, span_after_ident)
102102
{
103103
span_lint_and_then(

tests/ui/empty_structs_with_brackets.fixed

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@ macro_rules! empty_struct {
3232
empty_struct!(FromMacro);
3333

3434
fn main() {}
35+
36+
mod issue15349 {
37+
trait Bar<T> {}
38+
impl<T> Bar<T> for [u8; 7] {}
39+
40+
struct Foo<const N: usize>;
41+
//~^ empty_structs_with_brackets
42+
impl<const N: usize> Foo<N>
43+
where
44+
[u8; N]: Bar<[(); N]>,
45+
{
46+
fn foo() {}
47+
}
48+
}

tests/ui/empty_structs_with_brackets.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@ macro_rules! empty_struct {
3232
empty_struct!(FromMacro);
3333

3434
fn main() {}
35+
36+
mod issue15349 {
37+
trait Bar<T> {}
38+
impl<T> Bar<T> for [u8; 7] {}
39+
40+
struct Foo<const N: usize> {}
41+
//~^ empty_structs_with_brackets
42+
impl<const N: usize> Foo<N>
43+
where
44+
[u8; N]: Bar<[(); N]>,
45+
{
46+
fn foo() {}
47+
}
48+
}

tests/ui/empty_structs_with_brackets.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,13 @@ LL | struct MyEmptyTupleStruct(); // should trigger lint
1616
|
1717
= help: remove the brackets
1818

19-
error: aborting due to 2 previous errors
19+
error: found empty brackets on struct declaration
20+
--> tests/ui/empty_structs_with_brackets.rs:40:31
21+
|
22+
LL | struct Foo<const N: usize> {}
23+
| ^^^
24+
|
25+
= help: remove the brackets
26+
27+
error: aborting due to 3 previous errors
2028

0 commit comments

Comments
 (0)