rust-lang / rust-lang/rust-clippy

`wildcard_enum_match_arm` lint don't work in case of a single variant

Open
#12,115 0 comments 2 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

I tried to use an example from wildcard_enum_match_arm lint doc, but it didn't work. I also noticed that there is a separate match_wildcard_for_single_variants lint for a single variant, but if it's expected to use it instead then example seems need to be changed.

Lint Name

wildcard_enum_match_arm

Reproducer

I tried this code: (playground link)

#![warn(clippy::wildcard_enum_match_arm)]

fn main() {
    enum Foo {
        A(usize),
        B(usize),
    }

    let x = Foo::B(1);

    match x {
        Foo::A(_) => {}
        _ => {}
    }
}

I expected to see this happen: Lint warning emitted.

Instead, this happened: No lint warning.

Version
rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: x86_64-unknown-linux-gnu
release: 1.74.1
LLVM version: 17.0.4

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 with the wildcard_enum_match_arm lint and compare its behavior with match_wildcard_for_single_variants using the supplied reproducer. Check the linked lint documentation examples as well. Done means the single-variant case either emits the expected warning or the documentation clearly directs users to the appropriate lint.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.