mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-17 18:28:40 +00:00
a5a07e503f
This commit changes the behavior of `single_match` lint. After that, we won't lint non-exhaustive matches like this: ```rust match Some(v) { Some(a) => println!("${:?}", a), None => {}, } ``` The rationale is that, because the type of `a` could be changed, so the user can get non-exhaustive match after applying the suggested lint (see https://github.com/rust-lang/rust-clippy/issues/8282#issuecomment-1013566068 for context). We also will lint `match` constructions with tuples. When we see the tuples on the both arms, we will check them both at the same time, and if they form exhaustive match, we could display the warning. Closes #8282
23 lines
633 B
Text
23 lines
633 B
Text
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
|
|
--> $DIR/single_match_else.rs:14:5
|
|
|
|
|
LL | / match ExprNode::Butterflies {
|
|
LL | | ExprNode::ExprAddrOf => Some(&NODE),
|
|
LL | | _ => {
|
|
LL | | let x = 5;
|
|
LL | | None
|
|
LL | | },
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
= note: `-D clippy::single-match-else` implied by `-D warnings`
|
|
help: try this
|
|
|
|
|
LL ~ if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else {
|
|
LL + let x = 5;
|
|
LL + None
|
|
LL + }
|
|
|
|
|
|
|
error: aborting due to previous error
|
|
|