rust-lang / rust-lang/rust-clippy
wildcard_enum_match_arm unreachable wildcard
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Currently, wildcard_enum_match_arm will indicate against using a wildcard
even in the case that the wildcard is marked as unreachable!().
I find this a little too noisy.
Sometimes, instead of matching enums by explicitly stating all variants,
it can be more readable to group some variants under a method of the form is_*()
or use any kind of if guard.
When using guards, the use of unreachable wildcards is usually necessary and useful.
The unreachable!() macro is enough to catch any bugs that may hide in the guards,
given an extensive enough test suite.
Lint Name
wildcard_enum_match_arm
Reproducer
I tried this code:
let lval = match left.kind() {
wir::Kind::ConstInt(i) => i64::try_from(i).unwrap(),
wir::Kind::ConstSigned(s) => s,
x if !x.is_number() => return None,
_ => unreachable!(),
};
I saw this happen:
206 | _ => unreachable!(),
| ^ help: try: `x @ wir::Kind::Return | x @ wir::Kind::Neg ...
I expected to see this happen:
No warning at all.
If more variants are added that do not fall in the filter
(in this case we only care about numbers),
the unreachable!() will panic, so no lint is necessary.
Version
rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3
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 by locating the implementation and tests for the wildcard_enum_match_arm lint, then run the reproducer from the issue. Check how the lint handles a wildcard whose body is unreachable!() and add coverage for the guarded match shown. Done means that this case produces no warning while the lint still behaves as intended for other wildcard arms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100