rust-lang / rust-lang/rust-clippy
lint regarding unqualified enum variant name acting as a catch-all match arm in use with enum glob import
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
I was watching a video talking about a few strong Rust opinions. But, one of them struck me more of a potential issue Rust developers should be aware of. This clip explains the issue. Although unlikely to intentionally be introduced by a developer, it is still something that can happen if the developer is not careful.
If accepted, I believe this lint should be added under clippy::correctness as code will just be straight up wrong if this issue exists in code.
P.S.: I apologize for the wordy issue name. I couldn't think of a more concise way to put it.
Advantage
- Prevent unexpected behavior in an identical situation by denying code that exhibits the issue.
Drawbacks
-
Could be considered redundant due to the existence of the
enum_glob_uselintI do not believe this lint is redundant due to this. Despite the fact that the glob itself will be rejected if
deny(enum_glob_use), it is a possibility that a developer will not deny the lint which would accept the glob and open up the code to the issue described in this lint proposal. By adding this lint, specifically toclippy::correctness, code that exhibits this issue will be denied no matter what.
Example
Triggering Code:
enum Foo { Bar, Quox }
fn main() {
use Foo::*;
let f = Foo::Quox;
match f {
Bar => dbg!("bar"),
Baz => dbg!("baz"), // raises `unused_variables` and `non_snake_case` warnings
};
// Results in the printing of "baz"
}
Correct Code:
enum Foo { Bar, Quox }
fn main() {
let f = Foo::Quox;
match f {
Foo::Bar => dbg!("bar"),
Foo::Quox => dbg!("baz"), // no warnings
};
// Results in the printing of "baz"
}
Other Example:
enum Foo { Bar, Quox }
fn main() {
let f = Foo::Quox;
match f {
Foo::Bar => dbg!("bar"),
Baz => dbg!("baz"),
};
}
This example above might seem like it exhibits the same issue I am proposing a lint against. I would disagree. In the code above, there is no glob import used. Therefore, it makes it more clear thar Baz is NOT a variant of Foo and instead is potentially an improperly cased catch-all variable name.
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
The issue provides Rust examples but no source file or test entry point. Start by reproducing the enum-glob match behavior and reviewing existing Clippy lint conventions. Done means a correctness lint reliably identifies the described pattern without flagging the non-glob example.
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
- 35/100