Skip to content

single_match incorrectly lints on exhaustive matches inside of Option/Result #11365

@awused

Description

@awused

Summary

single_match isn't supposed to lint on exhaustive matches of user-defined types, but it will if those are inside an Option or Result.

Lint Name

single_match

Reproducer

I tried this code:

enum Test {
    A,
    B,
}

fn main() {
    let test = Some(Test::A);

    match test {
        Some(Test::A | Test::B) => todo!(),
        None => {}
    }
}

Clippy suggests this code:

    if let Some(Test::A | Test::B) = test {
        todo!()
    }

I expected to see this happen:

Nothing, single_match should not trigger here since I've exhaustively listed every variant of my enum. It seems some specific carve-outs were added for Option/Result in single_match, but they're over-eager. The code clippy suggests is equivalent, right now, but if I were to add a Test::C variant without remembering to handle it, clippy's version would not catch it.

Version

rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.71.1
LLVM version: 16.0.5

Additional Labels

No response

Activity

added
C-bugCategory: Clippy is not doing the correct thing
I-false-positiveIssue: The lint was triggered on code it shouldn't have
on Aug 20, 2023
added a commit that references this issue on Aug 8, 2024
5ccf543
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @awused

      Issue actions

        `single_match` incorrectly lints on exhaustive matches inside of Option/Result · Issue #11365 · rust-lang/rust-clippy