-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New lint: match_wildcard_for_single_variants
#5582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 8 commits into
rust-lang:master
from
covaii:match_wildcard_for_single_variants
May 20, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
94e4b5e
Add the redundant_wildcard_enum_match lint
covaii 0ad9f7d
Fix trivial cases of new match_wildcard_for_single_variants lint
covaii 4948307
Fix cases of match_wildcard_for_single_variants lint when it is spann…
covaii 749619c
Apply suggestions from PR review
covaii 1c59cd5
Fix example code of wildcard_enum_match_arm lint
covaii 10313a2
Revert "Fix cases of match_wildcard_for_single_variants lint when it …
covaii 2620d24
Fix check for missing enum variants from match expressions
covaii d906253
Add more test cases for match_wildcard_for_single_variants
covaii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.