Skip to content

Commit d906253

Browse files
committed
Add more test cases for match_wildcard_for_single_variants
1 parent 2620d24 commit d906253

3 files changed

+104
-4
lines changed

tests/ui/match_wildcard_for_single_variants.fixed

+42-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,51 @@ enum Foo {
99
C,
1010
}
1111

12+
enum Color {
13+
Red,
14+
Green,
15+
Blue,
16+
Rgb(u8, u8, u8),
17+
}
18+
1219
fn main() {
13-
match Foo::A {
20+
let f = Foo::A;
21+
match f {
1422
Foo::A => {},
1523
Foo::B => {},
1624
Foo::C => {},
1725
}
26+
27+
let color = Color::Red;
28+
29+
// check exhaustive bindings
30+
match color {
31+
Color::Red => {},
32+
Color::Green => {},
33+
Color::Rgb(_r, _g, _b) => {},
34+
Color::Blue => {},
35+
}
36+
37+
// check exhaustive wild
38+
match color {
39+
Color::Red => {},
40+
Color::Green => {},
41+
Color::Rgb(..) => {},
42+
Color::Blue => {},
43+
}
44+
match color {
45+
Color::Red => {},
46+
Color::Green => {},
47+
Color::Rgb(_, _, _) => {},
48+
Color::Blue => {},
49+
}
50+
51+
// shouldn't lint as there is one missing variant
52+
// and one that isn't exhaustively covered
53+
match color {
54+
Color::Red => {},
55+
Color::Green => {},
56+
Color::Rgb(255, _, _) => {},
57+
_ => {},
58+
}
1859
}

tests/ui/match_wildcard_for_single_variants.rs

+42-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,51 @@ enum Foo {
99
C,
1010
}
1111

12+
enum Color {
13+
Red,
14+
Green,
15+
Blue,
16+
Rgb(u8, u8, u8),
17+
}
18+
1219
fn main() {
13-
match Foo::A {
20+
let f = Foo::A;
21+
match f {
1422
Foo::A => {},
1523
Foo::B => {},
1624
_ => {},
1725
}
26+
27+
let color = Color::Red;
28+
29+
// check exhaustive bindings
30+
match color {
31+
Color::Red => {},
32+
Color::Green => {},
33+
Color::Rgb(_r, _g, _b) => {},
34+
_ => {},
35+
}
36+
37+
// check exhaustive wild
38+
match color {
39+
Color::Red => {},
40+
Color::Green => {},
41+
Color::Rgb(..) => {},
42+
_ => {},
43+
}
44+
match color {
45+
Color::Red => {},
46+
Color::Green => {},
47+
Color::Rgb(_, _, _) => {},
48+
_ => {},
49+
}
50+
51+
// shouldn't lint as there is one missing variant
52+
// and one that isn't exhaustively covered
53+
match color {
54+
Color::Red => {},
55+
Color::Green => {},
56+
Color::Rgb(255, _, _) => {},
57+
_ => {},
58+
}
1859
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
error: wildcard match will miss any future added variants
2-
--> $DIR/match_wildcard_for_single_variants.rs:16:9
2+
--> $DIR/match_wildcard_for_single_variants.rs:24:9
33
|
44
LL | _ => {},
55
| ^ help: try this: `Foo::C`
66
|
77
= note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings`
88

9-
error: aborting due to previous error
9+
error: wildcard match will miss any future added variants
10+
--> $DIR/match_wildcard_for_single_variants.rs:34:9
11+
|
12+
LL | _ => {},
13+
| ^ help: try this: `Color::Blue`
14+
15+
error: wildcard match will miss any future added variants
16+
--> $DIR/match_wildcard_for_single_variants.rs:42:9
17+
|
18+
LL | _ => {},
19+
| ^ help: try this: `Color::Blue`
20+
21+
error: wildcard match will miss any future added variants
22+
--> $DIR/match_wildcard_for_single_variants.rs:48:9
23+
|
24+
LL | _ => {},
25+
| ^ help: try this: `Color::Blue`
26+
27+
error: aborting due to 4 previous errors
1028

0 commit comments

Comments
 (0)