mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 09:27:25 +00:00
2b7dd31368
- add tests - refactor match_same_arms lint - prioritize match_expr_like_matches_macro over match_same_arms
102 lines
1.8 KiB
Rust
102 lines
1.8 KiB
Rust
// run-rustfix
|
|
|
|
#![warn(clippy::match_like_matches_macro)]
|
|
#![allow(unreachable_patterns, dead_code)]
|
|
|
|
fn main() {
|
|
let x = Some(5);
|
|
|
|
// Lint
|
|
let _y = matches!(x, Some(0));
|
|
|
|
// Lint
|
|
let _w = matches!(x, Some(_));
|
|
|
|
// Turn into is_none
|
|
let _z = x.is_none();
|
|
|
|
// Lint
|
|
let _zz = !matches!(x, Some(r) if r == 0);
|
|
|
|
// Lint
|
|
let _zzz = matches!(x, Some(5));
|
|
|
|
// No lint
|
|
let _a = match x {
|
|
Some(_) => false,
|
|
_ => false,
|
|
};
|
|
|
|
// No lint
|
|
let _ab = match x {
|
|
Some(0) => false,
|
|
_ => true,
|
|
None => false,
|
|
};
|
|
|
|
enum E {
|
|
A(u32),
|
|
B(i32),
|
|
C,
|
|
D,
|
|
};
|
|
let x = E::A(2);
|
|
{
|
|
// lint
|
|
let _ans = matches!(x, E::A(_) | E::B(_));
|
|
}
|
|
{
|
|
// lint
|
|
let _ans = !matches!(x, E::B(_) | E::C);
|
|
}
|
|
{
|
|
// no lint
|
|
let _ans = match x {
|
|
E::A(_) => false,
|
|
E::B(_) => false,
|
|
E::C => true,
|
|
_ => true,
|
|
};
|
|
}
|
|
{
|
|
// no lint
|
|
let _ans = match x {
|
|
E::A(_) => true,
|
|
E::B(_) => false,
|
|
E::C => false,
|
|
_ => true,
|
|
};
|
|
}
|
|
{
|
|
// no lint
|
|
let _ans = match x {
|
|
E::A(a) if a < 10 => false,
|
|
E::B(a) if a < 10 => false,
|
|
_ => true,
|
|
};
|
|
}
|
|
{
|
|
// no lint
|
|
let _ans = match x {
|
|
E::A(_) => false,
|
|
E::B(a) if a < 10 => false,
|
|
_ => true,
|
|
};
|
|
}
|
|
{
|
|
// no lint
|
|
let _ans = match x {
|
|
E::A(a) => a == 10,
|
|
E::B(_) => false,
|
|
_ => true,
|
|
};
|
|
}
|
|
{
|
|
// no lint
|
|
let _ans = match x {
|
|
E::A(_) => false,
|
|
E::B(_) => true,
|
|
_ => false,
|
|
};
|
|
}
|
|
}
|