-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #3652 - Aehmlo:where_the_wild_things_are, r=phansch
Add wildcard_match_arm lint This lint prevents using a wildcard in a match arm. Implemented as a restriction currently, because this is pretty much an edge case. See #3649 for more information. Didn't add any tests because I wasn't sure how, but if someone wants to point me in the right direction, I'd be happy to!
- Loading branch information
Showing
6 changed files
with
99 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#![deny(clippy::wildcard_enum_match_arm)] | ||
|
||
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
enum Color { | ||
Red, | ||
Green, | ||
Blue, | ||
Rgb(u8, u8, u8), | ||
Cyan, | ||
} | ||
|
||
impl Color { | ||
fn is_monochrome(self) -> bool { | ||
match self { | ||
Color::Red | Color::Green | Color::Blue => true, | ||
Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0, | ||
Color::Cyan => false, | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let color = Color::Rgb(0, 0, 127); | ||
match color { | ||
Color::Red => println!("Red"), | ||
_ => eprintln!("Not red"), | ||
}; | ||
match color { | ||
Color::Red => {}, | ||
Color::Green => {}, | ||
Color::Blue => {}, | ||
Color::Cyan => {}, | ||
c if c.is_monochrome() => {}, | ||
Color::Rgb(_, _, _) => {}, | ||
}; | ||
let x: u8 = unimplemented!(); | ||
match x { | ||
0 => {}, | ||
140 => {}, | ||
_ => {}, | ||
}; | ||
} |
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,15 @@ | ||
error: wildcard match will miss any future added variants. | ||
--> $DIR/wildcard_enum_match_arm.rs:26:9 | ||
| | ||
LL | _ => eprintln!("Not red"), | ||
| ^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/wildcard_enum_match_arm.rs:1:9 | ||
| | ||
LL | #![deny(clippy::wildcard_enum_match_arm)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: to resolve, match each variant explicitly | ||
|
||
error: aborting due to previous error | ||
|