-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Closed
Copy link
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
single_match
: fix checking of explicitly matched enums #11441Auto merge of #11441 - Jarcho:issue_11365, r=xFrednet