Skip to content

empty-structs-with-brackets wants to remove const parameters of structs 🤔 #15349

@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

--force-warn clippy::empty-structs-with-brackets

this code:

//@ run-pass
trait Bar<T> {} //~ WARN trait `Bar` is never used
impl<T> Bar<T> for [u8; 7] {}

struct Foo<const N: usize> {}
impl<const N: usize> Foo<N>
where
    [u8; N]: Bar<[(); N]>,
{
    fn foo() {}
}

fn main() {
    Foo::foo();
}

caused the following diagnostics:

    Checking _issue-69654-run-pass v0.1.0 (/tmp/icemaker_global_tempdir.0gE5D6KlClUx/icemaker_clippyfix_tempdir.Hquhfwmj7hC8/_issue-69654-run-pass)
warning: found empty brackets on struct declaration
 --> src/main.rs:5:11
  |
5 | struct Foo<const N: usize> {}
  |           ^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_structs_with_brackets
  = note: requested on the command line with `--force-warn clippy::empty-structs-with-brackets`
  = help: remove the brackets

warning: `_issue-69654-run-pass` (bin "_issue-69654-run-pass") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.42s

However after applying these diagnostics, the resulting code:

//@ run-pass
trait Bar<T> {} //~ WARN trait `Bar` is never used
impl<T> Bar<T> for [u8; 7] {}

struct Foo;
impl<const N: usize> Foo
where
    [u8; N]: Bar<[(); N]>,
{
    fn foo() {}
}

fn main() {
    Foo::foo();
}

no longer compiled:

    Checking _issue-69654-run-pass v0.1.0 (/tmp/icemaker_global_tempdir.0gE5D6KlClUx/icemaker_clippyfix_tempdir.Hquhfwmj7hC8/_issue-69654-run-pass)
error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
 --> src/main.rs:6:6
  |
6 | impl<const N: usize> Foo
  |      ^^^^^^^^^^^^^^ unconstrained const parameter
  |
  = note: expressions using a const parameter must map each value to a distinct output value
  = note: proving the result of expressions other than the parameter are unique is not supported

For more information about this error, try `rustc --explain E0207`.
error: could not compile `_issue-69654-run-pass` (bin "_issue-69654-run-pass") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_issue-69654-run-pass` (bin "_issue-69654-run-pass" test) due to 1 previous error

Version:

rustc 1.90.0-nightly (f32b23204 2025-07-26)
binary: rustc
commit-hash: f32b23204a0efe2fe8383ed4be1a30b56c1bbf94
commit-date: 2025-07-26
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

Metadata

Metadata

Assignees

Labels

I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions