rust-lang / rust-lang/rust-clippy

wildcard_enum_match_arm does not lint wildcards that cover Option<LocalEnum> variants

Open
#17,291 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

wildcard_enum_match_arm does not fire when matching Option<LocalEnum> or Result<LocalEnum, _> with _. The wildcard silently covers both None and any unmatched Some(Variant), meaning new enum variants are swallowed without warning — exactly what this lint is designed to prevent.

The lint skips Option because it's a foreign/std type. But when the inner type is a local enum, the _ arm defeats exhaustiveness protection. The safe alternative is to destructure the Option first and match the inner enum directly, but nothing guides the developer toward this pattern.

Proposal: Either extend wildcard_enum_match_arm to fire when a wildcard covers Some(T)/Ok(T) where T is an enum that would otherwise trigger the lint, or introduce a separate lint for this case.

I would be interested in contributing to either extending the lint or creating a new one, depending on

Version
rustc 1.95.0 (59807616e 2026-04-14)                                                                                                                      
clippy 0.1.96 (ac68faa20c 2026-05-25)
Lint Name

wildcard_enum_match_arm

Reproducer

I tried this code:

#![deny(clippy::wildcard_enum_match_arm)]

enum Action {
    Create,
    Delete,
}

fn handle(action: Option<Action>) -> &'static str {
    match action {
        Some(Action::Create) => "creating",
        _ => "nothing", // covers None AND Some(Action::Delete)
    }
}

I expected to see this happen: a warning that the _ arm covers Some(Action::Delete) (and would silently cover any future variants added to Action).

Instead, this happened: no warning. If a developer adds Action::Update, it is silently caught by _ with no compiler or clippy diagnostic.

The safe pattern that preserves exhaustiveness:

fn handle(action: Option<Action>) -> &'static str {
    let Some(action) = action else { return "nothing" };
    match action {
        Action::Create => "creating",
        Action::Delete => "nothing",
    }
}
Version
rustc 1.96.0 (ac68faa20 2026-05-25)
binary: rustc
commit-hash: ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96
commit-date: 2026-05-25
host: x86_64-unknown-linux-gnu
release: 1.96.0
LLVM version: 22.1.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the wildcard_enum_match_arm lint implementation and its existing tests, then reproduce the Option<Action> example from the issue. Determine whether the current lint can cover Some(T) and Ok(T) when T is a local enum, or whether a separate lint is needed. Done means the chosen design emits a diagnostic for the reported cases and includes regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.