Skip to content

Commit d07d001

Browse files
committed
Auto merge of #4562 - phansch:wildcard_enum_match_rustfix, r=llogiq
Add run-rustfix for wildcard_enum_match_arm lint changelog: none cc #3630
2 parents f21cd81 + afd7b18 commit d07d001

3 files changed

+73
-5
lines changed
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// run-rustfix
2+
3+
#![deny(clippy::wildcard_enum_match_arm)]
4+
#![allow(unreachable_code, unused_variables)]
5+
6+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7+
enum Color {
8+
Red,
9+
Green,
10+
Blue,
11+
Rgb(u8, u8, u8),
12+
Cyan,
13+
}
14+
15+
impl Color {
16+
fn is_monochrome(self) -> bool {
17+
match self {
18+
Color::Red | Color::Green | Color::Blue => true,
19+
Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0,
20+
Color::Cyan => false,
21+
}
22+
}
23+
}
24+
25+
fn main() {
26+
let color = Color::Rgb(0, 0, 127);
27+
match color {
28+
Color::Red => println!("Red"),
29+
Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => eprintln!("Not red"),
30+
};
31+
match color {
32+
Color::Red => println!("Red"),
33+
_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan => eprintln!("Not red"),
34+
};
35+
let _str = match color {
36+
Color::Red => "Red".to_owned(),
37+
not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan => format!("{:?}", not_red),
38+
};
39+
match color {
40+
Color::Red => {},
41+
Color::Green => {},
42+
Color::Blue => {},
43+
Color::Cyan => {},
44+
c if c.is_monochrome() => {},
45+
Color::Rgb(_, _, _) => {},
46+
};
47+
let _str = match color {
48+
Color::Red => "Red",
49+
c @ Color::Green | c @ Color::Blue | c @ Color::Rgb(_, _, _) | c @ Color::Cyan => "Not red",
50+
};
51+
match color {
52+
Color::Rgb(r, _, _) if r > 0 => "Some red",
53+
Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => "No red",
54+
};
55+
match color {
56+
Color::Red | Color::Green | Color::Blue | Color::Cyan => {},
57+
Color::Rgb(..) => {},
58+
};
59+
let x: u8 = unimplemented!();
60+
match x {
61+
0 => {},
62+
140 => {},
63+
_ => {},
64+
};
65+
}

tests/ui/wildcard_enum_match_arm.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// run-rustfix
2+
13
#![deny(clippy::wildcard_enum_match_arm)]
4+
#![allow(unreachable_code, unused_variables)]
25

36
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
47
enum Color {

tests/ui/wildcard_enum_match_arm.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error: wildcard match will miss any future added variants.
2-
--> $DIR/wildcard_enum_match_arm.rs:26:9
2+
--> $DIR/wildcard_enum_match_arm.rs:29:9
33
|
44
LL | _ => eprintln!("Not red"),
55
| ^ help: try this: `Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
66
|
77
note: lint level defined here
8-
--> $DIR/wildcard_enum_match_arm.rs:1:9
8+
--> $DIR/wildcard_enum_match_arm.rs:3:9
99
|
1010
LL | #![deny(clippy::wildcard_enum_match_arm)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: wildcard match will miss any future added variants.
14-
--> $DIR/wildcard_enum_match_arm.rs:30:9
14+
--> $DIR/wildcard_enum_match_arm.rs:33:9
1515
|
1616
LL | _not_red => eprintln!("Not red"),
1717
| ^^^^^^^^ help: try this: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan`
1818

1919
error: wildcard match will miss any future added variants.
20-
--> $DIR/wildcard_enum_match_arm.rs:34:9
20+
--> $DIR/wildcard_enum_match_arm.rs:37:9
2121
|
2222
LL | not_red => format!("{:?}", not_red),
2323
| ^^^^^^^ help: try this: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan`
2424

2525
error: wildcard match will miss any future added variants.
26-
--> $DIR/wildcard_enum_match_arm.rs:50:9
26+
--> $DIR/wildcard_enum_match_arm.rs:53:9
2727
|
2828
LL | _ => "No red",
2929
| ^ help: try this: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`

0 commit comments

Comments
 (0)