Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
awused opened this issue Aug 20, 2023 · 0 comments · Fixed by #11441
Closed

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

awused opened this issue Aug 20, 2023 · 0 comments · Fixed by #11441
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@awused
Copy link

awused commented Aug 20, 2023

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

@awused awused added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Aug 20, 2023
@bors bors closed this as completed in 5ccf543 Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant