-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 #4562 - phansch:wildcard_enum_match_rustfix, r=llogiq
Add run-rustfix for wildcard_enum_match_arm lint changelog: none cc #3630
- Loading branch information
Showing
3 changed files
with
73 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// run-rustfix | ||
|
||
#![deny(clippy::wildcard_enum_match_arm)] | ||
#![allow(unreachable_code, unused_variables)] | ||
|
||
#[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"), | ||
Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => eprintln!("Not red"), | ||
}; | ||
match color { | ||
Color::Red => println!("Red"), | ||
_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan => eprintln!("Not red"), | ||
}; | ||
let _str = match color { | ||
Color::Red => "Red".to_owned(), | ||
not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan => format!("{:?}", not_red), | ||
}; | ||
match color { | ||
Color::Red => {}, | ||
Color::Green => {}, | ||
Color::Blue => {}, | ||
Color::Cyan => {}, | ||
c if c.is_monochrome() => {}, | ||
Color::Rgb(_, _, _) => {}, | ||
}; | ||
let _str = match color { | ||
Color::Red => "Red", | ||
c @ Color::Green | c @ Color::Blue | c @ Color::Rgb(_, _, _) | c @ Color::Cyan => "Not red", | ||
}; | ||
match color { | ||
Color::Rgb(r, _, _) if r > 0 => "Some red", | ||
Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => "No red", | ||
}; | ||
match color { | ||
Color::Red | Color::Green | Color::Blue | Color::Cyan => {}, | ||
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
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