]> git.lizzy.rs Git - rust.git/blob - tests/ui/wildcard_enum_match_arm.rs
wildcard_match_arm: lint only enum matches.
[rust.git] / tests / ui / wildcard_enum_match_arm.rs
1 #![deny(clippy::wildcard_enum_match_arm)]
2
3 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
4 enum Color {
5     Red,
6     Green,
7     Blue,
8     Rgb(u8, u8, u8),
9     Cyan,
10 }
11
12 impl Color {
13     fn is_monochrome(self) -> bool {
14         match self {
15             Color::Red | Color::Green | Color::Blue => true,
16             Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0,
17             Color::Cyan => false,
18         }
19     }
20 }
21
22 fn main() {
23     let color = Color::Rgb(0, 0, 127);
24     match color {
25         Color::Red => println!("Red"),
26         _ => eprintln!("Not red"),
27     };
28     match color {
29         Color::Red => {},
30         Color::Green => {},
31         Color::Blue => {},
32         Color::Cyan => {},
33         c if c.is_monochrome() => {},
34         Color::Rgb(_, _, _) => {},
35     };
36     let x: u8 = unimplemented!();
37     match x {
38         0 => {},
39         140 => {},
40         _ => {},
41     };
42 }