2023-04-20 14:37:15 +00:00
|
|
|
//@run-rustfix
|
2020-05-09 21:08:41 +00:00
|
|
|
|
|
|
|
#![warn(clippy::match_wildcard_for_single_variants)]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
enum Foo {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
}
|
|
|
|
|
2020-05-15 21:19:30 +00:00
|
|
|
enum Color {
|
|
|
|
Red,
|
|
|
|
Green,
|
|
|
|
Blue,
|
|
|
|
Rgb(u8, u8, u8),
|
|
|
|
}
|
2021-03-07 00:25:09 +00:00
|
|
|
impl Color {
|
|
|
|
fn f(self) {
|
|
|
|
match self {
|
|
|
|
Self::Red => (),
|
|
|
|
Self::Green => (),
|
|
|
|
Self::Blue => (),
|
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2020-05-15 21:19:30 +00:00
|
|
|
|
2020-05-09 21:08:41 +00:00
|
|
|
fn main() {
|
2020-05-15 21:19:30 +00:00
|
|
|
let f = Foo::A;
|
|
|
|
match f {
|
2020-05-09 21:08:41 +00:00
|
|
|
Foo::A => {},
|
|
|
|
Foo::B => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
2020-05-15 21:19:30 +00:00
|
|
|
|
|
|
|
let color = Color::Red;
|
|
|
|
|
|
|
|
// check exhaustive bindings
|
|
|
|
match color {
|
|
|
|
Color::Red => {},
|
|
|
|
Color::Green => {},
|
|
|
|
Color::Rgb(_r, _g, _b) => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
// check exhaustive wild
|
|
|
|
match color {
|
|
|
|
Color::Red => {},
|
|
|
|
Color::Green => {},
|
|
|
|
Color::Rgb(..) => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
match color {
|
|
|
|
Color::Red => {},
|
|
|
|
Color::Green => {},
|
|
|
|
Color::Rgb(_, _, _) => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
// shouldn't lint as there is one missing variant
|
|
|
|
// and one that isn't exhaustively covered
|
|
|
|
match color {
|
|
|
|
Color::Red => {},
|
|
|
|
Color::Green => {},
|
|
|
|
Color::Rgb(255, _, _) => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
2021-03-07 00:25:09 +00:00
|
|
|
|
|
|
|
// References shouldn't change anything
|
|
|
|
match &color {
|
|
|
|
&Color::Red => (),
|
|
|
|
Color::Green => (),
|
|
|
|
&Color::Rgb(..) => (),
|
|
|
|
&_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
use self::Color as C;
|
|
|
|
|
|
|
|
match color {
|
|
|
|
C::Red => (),
|
|
|
|
C::Green => (),
|
|
|
|
C::Rgb(..) => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
match color {
|
|
|
|
C::Red => (),
|
|
|
|
Color::Green => (),
|
|
|
|
Color::Rgb(..) => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
match Some(0) {
|
|
|
|
Some(0) => 0,
|
|
|
|
Some(_) => 1,
|
|
|
|
_ => 2,
|
|
|
|
};
|
2021-03-08 15:33:36 +00:00
|
|
|
|
|
|
|
#[non_exhaustive]
|
|
|
|
enum Bar {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
}
|
|
|
|
match Bar::A {
|
|
|
|
Bar::A => (),
|
|
|
|
Bar::B => (),
|
|
|
|
_ => (),
|
|
|
|
};
|
2021-03-27 06:50:19 +00:00
|
|
|
|
|
|
|
//#6984
|
|
|
|
{
|
|
|
|
#![allow(clippy::manual_non_exhaustive)]
|
|
|
|
pub enum Enum {
|
|
|
|
A,
|
|
|
|
B,
|
2021-07-01 10:35:16 +00:00
|
|
|
C,
|
2021-03-27 06:50:19 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
__Private,
|
|
|
|
}
|
2021-07-01 10:35:16 +00:00
|
|
|
match Enum::A {
|
|
|
|
Enum::A => (),
|
|
|
|
Enum::B => (),
|
|
|
|
Enum::C => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
2021-03-27 06:50:19 +00:00
|
|
|
match Enum::A {
|
|
|
|
Enum::A => (),
|
|
|
|
Enum::B => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
2020-05-09 21:08:41 +00:00
|
|
|
}
|
2022-12-10 12:05:08 +00:00
|
|
|
|
|
|
|
mod issue9993 {
|
|
|
|
enum Foo {
|
|
|
|
A(bool),
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test() {
|
|
|
|
let _ = match Foo::A(true) {
|
|
|
|
_ if false => 0,
|
|
|
|
Foo::A(true) => 1,
|
|
|
|
Foo::A(false) => 2,
|
|
|
|
Foo::B => 3,
|
|
|
|
};
|
2022-12-11 03:20:46 +00:00
|
|
|
|
|
|
|
let _ = match Foo::B {
|
|
|
|
_ if false => 0,
|
|
|
|
Foo::A(_) => 1,
|
|
|
|
_ => 2,
|
|
|
|
};
|
2022-12-10 12:05:08 +00:00
|
|
|
}
|
|
|
|
}
|