rust-lang / rust-lang/rust-clippy
Detect enums with cfg controlled variants that aren't non_exhaustive
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
If an enum has variants controlled by cfg (e.g. feature flags), it should almost certainly be non_exhaustive. This lint would flag exhaustive enums controlled by cfg.
This should not flag enums with cfg variants that nonetheless have the same variants in all cfgs.
Lint Name
cfg_enum_exhaustive
Category
suspicious
Advantage
- Avoid requiring cfg in every match
- Avoid having unexpected errors that only arise in some configurations
Drawbacks
Possible false positives.
Example
enum E {
V1,
#[cfg(feature = "xyz")]
V2,
}
Could be written as:
#[non_exhaustive]
enum E {
V1,
#[cfg(feature = "xyz")]
V2,
}
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
No implementation files, entry points, or tests are named. Start by locating the Clippy lint registration and test pattern for enum or cfg-related lints, then use the examples in this issue to define the cases. Done means exhaustive enums with cfg-controlled variants are flagged, while enums with identical variants in every configuration are not.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100