Skip to content

wildcard_enum_match_arm unreachable wildcard #16381

@hydrogs

Description

@hydrogs

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions