rust-lang / rust-lang/rust-clippy
Lint to ensure all variants of an enum are used
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
Check that all variants of an enum are used inside a function.
This is similar to standard exhaustiveness checking of a match, and the non-exhaustive-omitted-patterns lint for non-exhaustive enums; but generalized to usecases that are not using match.
Lint Name
No response
Category
restriction
Advantage
Ensures that when new variants are added to an enum (whether because it's an internal enum, public enum with a major version bump, or an external non-exhaustive enum) those variants are handled.
A major usecase I see for this is things that produce values of the enum and are expected to be able to produce every variant, such as parsers.
Drawbacks
How do you determine which enum to lint on?
Example
enum Intensity { Normal, Bold, Faint }
struct Unknown;
impl FromStr for Intensity {
type Err = Unknown;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"normal" => Ok(Intensity::Normal),
"bold" => Ok(Intensity::Bold),
_ => Err(Unknown),
}
}
}
Could be written as:
enum Intensity { Normal, Bold, Faint }
struct Unknown;
impl FromStr for Intensity {
type Err = Unknown;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"normal" => Ok(Intensity::Normal),
"bold" => Ok(Intensity::Bold),
"faint" => Ok(Intensity::Faint),
_ => Err(Unknown),
}
}
}
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 files, tests, or entry points are named. Start by reviewing existing Clippy lint implementations for enum analysis, then determine how the lint would identify the enum and verify every variant is produced; the Intensity and FromStr examples define the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100