-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Summary
After #8282 was closed via #8322 (in Rust 1.60) the example below is no longer linting.
The original rationale was that Clippy should not lint match
es on user-defined enums which explicitly list all possible options. Otherwise extending the enum later would break the original code, but not the fixed one, which may be unexpected for the author.
However, there is little reason to believe that standard types like std::option::Option
will be extended in the future. I suggest that they're exempt from this check. Another example is std::result::Result
. Of course, that does not help with user-defined Result
-like types like in the anyhow
crate, but still.
Lint Name
single_match
Reproducer
I tried this code:
fn main() {
let x = Some(10);
match x {
Some(_) => println!("hi!"),
None => {},
};
}
I expected to see this happen:
Like in Rust 1.58:
warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> a.rs:3:5
|
3 | / match x {
4 | | Some(x) => println!("hi! {}", x),
5 | | None => {},
6 | | };
| |_____^ help: try this: `if let Some(x) = x { println!("hi! {}", x) }`
|
= note: `#[warn(clippy::single_match)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
warning: 1 warning emitted
Instead, this happened:
No output
Version
Clippy 0.1.63 (2022-05-31 e094492)