mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-30 16:39:26 +00:00
fae7a09eea
This fixes a bug where match_wildcard_for_single_variants produced a bad suggestion where besides the missing variant, one or more hidden variants were left. This also adds tests to the ui-tests match_wildcard_for_single_variants and wildcard_enum_match_arm to make sure that the correct suggestion is produced.
134 lines
2.4 KiB
Rust
134 lines
2.4 KiB
Rust
// run-rustfix
|
|
|
|
#![warn(clippy::match_wildcard_for_single_variants)]
|
|
#![allow(dead_code)]
|
|
|
|
enum Foo {
|
|
A,
|
|
B,
|
|
C,
|
|
}
|
|
|
|
enum Color {
|
|
Red,
|
|
Green,
|
|
Blue,
|
|
Rgb(u8, u8, u8),
|
|
}
|
|
impl Color {
|
|
fn f(self) {
|
|
match self {
|
|
Self::Red => (),
|
|
Self::Green => (),
|
|
Self::Blue => (),
|
|
Self::Rgb(..) => (),
|
|
};
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let f = Foo::A;
|
|
match f {
|
|
Foo::A => {},
|
|
Foo::B => {},
|
|
Foo::C => {},
|
|
}
|
|
|
|
let color = Color::Red;
|
|
|
|
// check exhaustive bindings
|
|
match color {
|
|
Color::Red => {},
|
|
Color::Green => {},
|
|
Color::Rgb(_r, _g, _b) => {},
|
|
Color::Blue => {},
|
|
}
|
|
|
|
// check exhaustive wild
|
|
match color {
|
|
Color::Red => {},
|
|
Color::Green => {},
|
|
Color::Rgb(..) => {},
|
|
Color::Blue => {},
|
|
}
|
|
match color {
|
|
Color::Red => {},
|
|
Color::Green => {},
|
|
Color::Rgb(_, _, _) => {},
|
|
Color::Blue => {},
|
|
}
|
|
|
|
// 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, _, _) => {},
|
|
_ => {},
|
|
}
|
|
|
|
// References shouldn't change anything
|
|
match &color {
|
|
&Color::Red => (),
|
|
Color::Green => (),
|
|
&Color::Rgb(..) => (),
|
|
Color::Blue => (),
|
|
}
|
|
|
|
use self::Color as C;
|
|
|
|
match color {
|
|
C::Red => (),
|
|
C::Green => (),
|
|
C::Rgb(..) => (),
|
|
C::Blue => (),
|
|
}
|
|
|
|
match color {
|
|
C::Red => (),
|
|
Color::Green => (),
|
|
Color::Rgb(..) => (),
|
|
Color::Blue => (),
|
|
}
|
|
|
|
match Some(0) {
|
|
Some(0) => 0,
|
|
Some(_) => 1,
|
|
_ => 2,
|
|
};
|
|
|
|
#[non_exhaustive]
|
|
enum Bar {
|
|
A,
|
|
B,
|
|
C,
|
|
}
|
|
match Bar::A {
|
|
Bar::A => (),
|
|
Bar::B => (),
|
|
_ => (),
|
|
};
|
|
|
|
//#6984
|
|
{
|
|
#![allow(clippy::manual_non_exhaustive)]
|
|
pub enum Enum {
|
|
A,
|
|
B,
|
|
C,
|
|
#[doc(hidden)]
|
|
__Private,
|
|
}
|
|
match Enum::A {
|
|
Enum::A => (),
|
|
Enum::B => (),
|
|
Enum::C => (),
|
|
_ => (),
|
|
}
|
|
match Enum::A {
|
|
Enum::A => (),
|
|
Enum::B => (),
|
|
_ => (),
|
|
}
|
|
}
|
|
}
|