Auto merge of #6863 - Jarcho:wild_enum_match, r=llogiq
`match_wildcard` improvements fixes: #6604 fixes: #5733 fixes: #6862 #5733 is only fixed in the normal case, if different paths are used for the variants then the same problem will occur. It's cause by `def_path_str` returning an utterly useless result. I haven't dug into why yet. For #6604 there should be some discussion before accepting this. It's easy enough to change the message rather than disable the lint for `Option` and `Result`. changelog: Attempt to find a common path prefix for `match_wildcard_for_single_variants` and `wildcard_enum_match_arm` changelog: Don't lint op `Option` and `Result` for `match_wildcard_for_single_variants` and `wildcard_enum_match_arm` changelog: Consider `or` patterns and `Self` prefix for `match_wildcard_for_single_variants` and `wildcard_enum_match_arm`
This commit is contained in:
commit
4d686196b9
14 changed files with 323 additions and 118 deletions
|
|
@ -15,6 +15,16 @@ enum Color {
|
|||
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;
|
||||
|
|
@ -56,4 +66,46 @@ fn main() {
|
|||
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 => (),
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,16 @@ enum Color {
|
|||
Blue,
|
||||
Rgb(u8, u8, u8),
|
||||
}
|
||||
impl Color {
|
||||
fn f(self) {
|
||||
match self {
|
||||
Self::Red => (),
|
||||
Self::Green => (),
|
||||
Self::Blue => (),
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let f = Foo::A;
|
||||
|
|
@ -56,4 +66,46 @@ fn main() {
|
|||
Color::Rgb(255, _, _) => {},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
// 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,
|
||||
};
|
||||
|
||||
#[non_exhaustive]
|
||||
enum Bar {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
match Bar::A {
|
||||
Bar::A => (),
|
||||
Bar::B => (),
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,52 @@
|
|||
error: wildcard match will miss any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:24:9
|
||||
error: wildcard matches only a single variant and will also match any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:24:13
|
||||
|
|
||||
LL | _ => {},
|
||||
| ^ help: try this: `Foo::C`
|
||||
LL | _ => (),
|
||||
| ^ help: try this: `Self::Rgb(..)`
|
||||
|
|
||||
= note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings`
|
||||
|
||||
error: wildcard match will miss any future added variants
|
||||
error: wildcard matches only a single variant and will also match any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:34:9
|
||||
|
|
||||
LL | _ => {},
|
||||
| ^ help: try this: `Color::Blue`
|
||||
| ^ help: try this: `Foo::C`
|
||||
|
||||
error: wildcard match will miss any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:42:9
|
||||
error: wildcard matches only a single variant and will also match any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:44:9
|
||||
|
|
||||
LL | _ => {},
|
||||
| ^ help: try this: `Color::Blue`
|
||||
|
||||
error: wildcard match will miss any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:48:9
|
||||
error: wildcard matches only a single variant and will also match any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:52:9
|
||||
|
|
||||
LL | _ => {},
|
||||
| ^ help: try this: `Color::Blue`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: wildcard matches only a single variant and will also match any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:58:9
|
||||
|
|
||||
LL | _ => {},
|
||||
| ^ help: try this: `Color::Blue`
|
||||
|
||||
error: wildcard matches only a single variant and will also match any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:75:9
|
||||
|
|
||||
LL | &_ => (),
|
||||
| ^^ help: try this: `Color::Blue`
|
||||
|
||||
error: wildcard matches only a single variant and will also match any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:84:9
|
||||
|
|
||||
LL | _ => (),
|
||||
| ^ help: try this: `C::Blue`
|
||||
|
||||
error: wildcard matches only a single variant and will also match any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:91:9
|
||||
|
|
||||
LL | _ => (),
|
||||
| ^ help: try this: `Color::Blue`
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ fn main() {
|
|||
let error_kind = ErrorKind::NotFound;
|
||||
match error_kind {
|
||||
ErrorKind::NotFound => {},
|
||||
std::io::ErrorKind::PermissionDenied | std::io::ErrorKind::ConnectionRefused | std::io::ErrorKind::ConnectionReset | std::io::ErrorKind::ConnectionAborted | std::io::ErrorKind::NotConnected | std::io::ErrorKind::AddrInUse | std::io::ErrorKind::AddrNotAvailable | std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::AlreadyExists | std::io::ErrorKind::WouldBlock | std::io::ErrorKind::InvalidInput | std::io::ErrorKind::InvalidData | std::io::ErrorKind::TimedOut | std::io::ErrorKind::WriteZero | std::io::ErrorKind::Interrupted | std::io::ErrorKind::Other | std::io::ErrorKind::UnexpectedEof | _ => {},
|
||||
ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | _ => {},
|
||||
}
|
||||
match error_kind {
|
||||
ErrorKind::NotFound => {},
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: wildcard match will miss any future added variants
|
||||
error: wildcard match will also match any future added variants
|
||||
--> $DIR/wildcard_enum_match_arm.rs:39:9
|
||||
|
|
||||
LL | _ => eprintln!("Not red"),
|
||||
|
|
@ -10,29 +10,29 @@ note: the lint level is defined here
|
|||
LL | #![deny(clippy::wildcard_enum_match_arm)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: wildcard match will miss any future added variants
|
||||
error: wildcard match will also match any future added variants
|
||||
--> $DIR/wildcard_enum_match_arm.rs:43:9
|
||||
|
|
||||
LL | _not_red => eprintln!("Not red"),
|
||||
| ^^^^^^^^ help: try this: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan`
|
||||
|
||||
error: wildcard match will miss any future added variants
|
||||
error: wildcard match will also match any future added variants
|
||||
--> $DIR/wildcard_enum_match_arm.rs:47:9
|
||||
|
|
||||
LL | not_red => format!("{:?}", not_red),
|
||||
| ^^^^^^^ help: try this: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan`
|
||||
|
||||
error: wildcard match will miss any future added variants
|
||||
error: wildcard match will also match any future added variants
|
||||
--> $DIR/wildcard_enum_match_arm.rs:63:9
|
||||
|
|
||||
LL | _ => "No red",
|
||||
| ^ help: try this: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
|
||||
|
||||
error: match on non-exhaustive enum doesn't explicitly match all known variants
|
||||
error: wildcard matches known variants and will also match future added variants
|
||||
--> $DIR/wildcard_enum_match_arm.rs:80:9
|
||||
|
|
||||
LL | _ => {},
|
||||
| ^ help: try this: `std::io::ErrorKind::PermissionDenied | std::io::ErrorKind::ConnectionRefused | std::io::ErrorKind::ConnectionReset | std::io::ErrorKind::ConnectionAborted | std::io::ErrorKind::NotConnected | std::io::ErrorKind::AddrInUse | std::io::ErrorKind::AddrNotAvailable | std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::AlreadyExists | std::io::ErrorKind::WouldBlock | std::io::ErrorKind::InvalidInput | std::io::ErrorKind::InvalidData | std::io::ErrorKind::TimedOut | std::io::ErrorKind::WriteZero | std::io::ErrorKind::Interrupted | std::io::ErrorKind::Other | std::io::ErrorKind::UnexpectedEof | _`
|
||||
| ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | _`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue