Linter
fn main() { let maybe_n = Some(123); match maybe_n { Some(n) => println!("{n}"), _ => (), } }
📎 Clippy
➡️
fn main() { let maybe_n = Some(123); if let Some(n) = maybe_n { println!("{n}") } }
warning: you seem to be trying to use
match
for destructuring a single pattern.
Consider usingif let
fn main() {
let maybe_n = Some(123);
+#[allow(clippy::single_match)] // deliberately allow this once
match maybe_n {
Some(n) => println!("{n}"),
_ => (),
}
}
-
Rust ships with a linter
-
It's called clippy, also a very original name.
-
If you write the code on the left, it will tell you to write code on the right.
-
This is really nice because it's teaching you how to write cleaner code.
-
Clippy has over 9000 lints.