Skip to content

exhaustive-structs wants to add non_exhaustive to structs with default_field_values which does not work #14992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
matthiaskrgr opened this issue Jun 6, 2025 · 1 comment · May be fixed by #15022
Assignees
Labels
I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jun 6, 2025

Using the following flags

--force-warn clippy::exhaustive-structs

this code:

#![feature(default_field_values)]

pub struct A {
    pub a: isize = 42,
}

caused the following diagnostics:

    Checking _struct_field_default v0.1.0 (/tmp/icemaker_global_tempdir.o4hDRjvshrmO/icemaker_clippyfix_tempdir.6eDmH3ibcMeG/_struct_field_default)
warning: exported structs should not be exhaustive
 --> src/lib.rs:3:1
  |
3 | / pub struct A {
4 | |     pub a: isize = 42,
5 | | }
  | |_^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_structs
  = note: requested on the command line with `--force-warn clippy::exhaustive-structs`
help: try adding #[non_exhaustive]
  |
3 + #[non_exhaustive]
4 | pub struct A {
  |

warning: `_struct_field_default` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s

However after applying these diagnostics, the resulting code:

#![feature(default_field_values)]

#[non_exhaustive]
pub struct A {
    pub a: isize = 42,
}

no longer compiled:

    Checking _struct_field_default v0.1.0 (/tmp/icemaker_global_tempdir.o4hDRjvshrmO/icemaker_clippyfix_tempdir.6eDmH3ibcMeG/_struct_field_default)
error: `#[non_exhaustive]` can't be used to annotate items with default field values
 --> src/lib.rs:3:1
  |
3 |   #[non_exhaustive]
  |   ^^^^^^^^^^^^^^^^^
4 | / pub struct A {
5 | |     pub a: isize = 42,
6 | | }
  | |_- this struct has default field values

error: could not compile `_struct_field_default` (lib test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_struct_field_default` (lib) due to 1 previous error

Version:

rustc 1.89.0-nightly (cf423712b 2025-06-05)
binary: rustc
commit-hash: cf423712b9e95e9f6ec84b1ecb3d125e55ac8d56
commit-date: 2025-06-05
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

@matthiaskrgr matthiaskrgr added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jun 6, 2025
@profetia
Copy link
Contributor

profetia commented Jun 6, 2025

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants