Skip to content

Commit 3e39ebe

Browse files
committed
wildcard_match_arm: add simple ui test.
1 parent bbab157 commit 3e39ebe

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/ui/wildcard_match_arm.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![deny(clippy::wildcard_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+
}

tests/ui/wildcard_match_arm.stderr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: wildcard match will miss any future added variants.
2+
--> $DIR/wildcard_match_arm.rs:26:3
3+
|
4+
LL | _ => eprintln!("Not red"),
5+
| ^
6+
|
7+
note: lint level defined here
8+
--> $DIR/wildcard_match_arm.rs:1:9
9+
|
10+
LL | #![deny(clippy::wildcard_match_arm)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: to resolve, match each variant explicitly
13+
14+
error: aborting due to previous error
15+

0 commit comments

Comments
 (0)