forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#5582 - vtmargaryan:match_wildcard_for_single_…
…variants, r=flip1995 New lint: `match_wildcard_for_single_variants` changelog: Added a new lint match_wildcard_for_single_variants to warn on enum matches where a wildcard is used to match a single variant Closes rust-lang#5556
- Loading branch information
Showing
14 changed files
with
227 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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), | ||
} | ||
|
||
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, _, _) => {}, | ||
_ => {}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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), | ||
} | ||
|
||
fn main() { | ||
let f = Foo::A; | ||
match f { | ||
Foo::A => {}, | ||
Foo::B => {}, | ||
_ => {}, | ||
} | ||
|
||
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, _, _) => {}, | ||
_ => {}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
error: wildcard match will miss any future added variants | ||
--> $DIR/match_wildcard_for_single_variants.rs:24:9 | ||
| | ||
LL | _ => {}, | ||
| ^ help: try this: `Foo::C` | ||
| | ||
= note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings` | ||
|
||
error: wildcard match will miss any future added variants | ||
--> $DIR/match_wildcard_for_single_variants.rs:34:9 | ||
| | ||
LL | _ => {}, | ||
| ^ help: try this: `Color::Blue` | ||
|
||
error: wildcard match will miss any future added variants | ||
--> $DIR/match_wildcard_for_single_variants.rs:42: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 | ||
| | ||
LL | _ => {}, | ||
| ^ help: try this: `Color::Blue` | ||
|
||
error: aborting due to 4 previous errors | ||
|