rust-lang / rust-lang/rust-clippy
`struct_excessive_bools` false positive for booleans in CLI arguments
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The lint triggers even when we truly want to boolean productions, where booleans are not exclusive and could not be simplified with enums.
Lint Name
struct_excessive_bools
Reproducer
This is a common struct for CLI arguments:
struct App {
force: bool,
no_clobber: bool,
interactive: bool,
verbose: bool,
// files, ...
}
It emits:
warning: more than 3 bools in a struct
--> src/lib.rs:1:1
|
1 | / pub struct App {
2 | | pub force: bool,
3 | | pub no_clobber: bool,
4 | | pub interactive: bool,
5 | | pub verbose: bool,
6 | | // files, ...
7 | | }
| |_^
|
= help: consider using a state machine or refactoring bools into two-variant enums
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#struct_excessive_bools
= note: requested on the command line with `-W clippy::struct-excessive-bools`
The help does not work in this case, since we cannot replace it with enum in a simple way. We actually want to accept and handle all $2^4$ possibilities.
Version
rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the struct_excessive_bools lint and reproduce the report using the App example in src/lib.rs. Read the lint's existing behavior and discussion to determine an appropriate way to avoid this false positive for independent CLI flags. Done means the example no longer receives an inappropriate warning while genuine excessive-bool cases remain detected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100