Closed as not planned
Description
Summary
By using unit-like struct syntax, one is opting into behavior which is incompatible with ever adding any fields (the constant named after the struct). Therefore, adding #[non_exhaustive]
does not provide any forward-compatibility benefit — adding fields is always a breaking change. Therefore, Clippy should not recommend #[non_exhaustive]
on unit-like structs.
Lint Name
exhaustive_structs
Reproducer
I tried this code:
#![warn(clippy::exhaustive_structs)]
pub struct Foo;
I saw this happen:
warning: exported structs should not be exhaustive
--> src/lib.rs:2:1
|
2 | pub struct Foo;
| ^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_structs
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![warn(clippy::exhaustive_structs)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try adding #[non_exhaustive]
|
2 + #[non_exhaustive]
3 | pub struct Foo;
|
I expected to see this happen: No lint
Version
rustc 1.77.1 (7cf61ebde 2024-03-27)
binary: rustc
commit-hash: 7cf61ebde7b22796c69757901dd346d0fe70bd97
commit-date: 2024-03-27
host: x86_64-apple-darwin
release: 1.77.1
LLVM version: 17.0.6
Additional Labels
No response