mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
73 lines
1.2 KiB
Rust
73 lines
1.2 KiB
Rust
#![feature(tool_lints)]
|
|
|
|
#![warn(clippy::single_match)]
|
|
|
|
fn dummy() {
|
|
}
|
|
|
|
fn single_match(){
|
|
let x = Some(1u8);
|
|
|
|
match x {
|
|
Some(y) => { println!("{:?}", y); }
|
|
_ => ()
|
|
};
|
|
|
|
let z = (1u8,1u8);
|
|
match z {
|
|
(2...3, 7...9) => dummy(),
|
|
_ => {}
|
|
};
|
|
|
|
// Not linted (pattern guards used)
|
|
match x {
|
|
Some(y) if y == 0 => println!("{:?}", y),
|
|
_ => ()
|
|
}
|
|
|
|
// Not linted (no block with statements in the single arm)
|
|
match z {
|
|
(2...3, 7...9) => println!("{:?}", z),
|
|
_ => println!("nope"),
|
|
}
|
|
}
|
|
|
|
enum Foo { Bar, Baz(u8) }
|
|
use Foo::*;
|
|
use std::borrow::Cow;
|
|
|
|
fn single_match_know_enum() {
|
|
let x = Some(1u8);
|
|
let y : Result<_, i8> = Ok(1i8);
|
|
|
|
match x {
|
|
Some(y) => dummy(),
|
|
None => ()
|
|
};
|
|
|
|
match y {
|
|
Ok(y) => dummy(),
|
|
Err(..) => ()
|
|
};
|
|
|
|
let c = Cow::Borrowed("");
|
|
|
|
match c {
|
|
Cow::Borrowed(..) => dummy(),
|
|
Cow::Owned(..) => (),
|
|
};
|
|
|
|
let z = Foo::Bar;
|
|
// no warning
|
|
match z {
|
|
Bar => println!("42"),
|
|
Baz(_) => (),
|
|
}
|
|
|
|
match z {
|
|
Baz(_) => println!("42"),
|
|
Bar => (),
|
|
}
|
|
}
|
|
|
|
fn main() { }
|