Skip to content

Commit 2099dd1

Browse files
committed
Add tests
1 parent 5628d4a commit 2099dd1

File tree

4 files changed

+104
-16
lines changed

4 files changed

+104
-16
lines changed

src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
enum Foo {}
55

66
struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
7+
union NonEmptyUnion1 {
8+
foo: (),
9+
}
10+
union NonEmptyUnion2 {
11+
foo: (),
12+
bar: (),
13+
}
714
enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here
815
Foo(bool), //~ variant not covered
916
}
@@ -36,6 +43,10 @@ fn main() {
3643
//~^ ERROR type `u8` is non-empty
3744
match NonEmptyStruct(true) {}
3845
//~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled
46+
match (NonEmptyUnion1 { foo: () }) {}
47+
//~^ ERROR pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled
48+
match (NonEmptyUnion2 { foo: () }) {}
49+
//~^ ERROR pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled
3950
match NonEmptyEnum1::Foo(true) {}
4051
//~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled
4152
match NonEmptyEnum2::Foo(true) {}

src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unreachable pattern
2-
--> $DIR/match-empty-exhaustive_patterns.rs:21:9
2+
--> $DIR/match-empty-exhaustive_patterns.rs:28:9
33
|
44
LL | _ => {},
55
| ^
@@ -11,27 +11,27 @@ LL | #![deny(unreachable_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: unreachable pattern
14-
--> $DIR/match-empty-exhaustive_patterns.rs:28:9
14+
--> $DIR/match-empty-exhaustive_patterns.rs:35:9
1515
|
1616
LL | Some(_) => {}
1717
| ^^^^^^^
1818

1919
error: unreachable pattern
20-
--> $DIR/match-empty-exhaustive_patterns.rs:32:9
20+
--> $DIR/match-empty-exhaustive_patterns.rs:39:9
2121
|
2222
LL | Some(_) => {}
2323
| ^^^^^^^
2424

2525
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
26-
--> $DIR/match-empty-exhaustive_patterns.rs:35:11
26+
--> $DIR/match-empty-exhaustive_patterns.rs:42:11
2727
|
2828
LL | match 0u8 {}
2929
| ^^^
3030
|
3131
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
3232

3333
error[E0004]: non-exhaustive patterns: pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled
34-
--> $DIR/match-empty-exhaustive_patterns.rs:37:11
34+
--> $DIR/match-empty-exhaustive_patterns.rs:44:11
3535
|
3636
LL | struct NonEmptyStruct(bool);
3737
| ----------------------------
@@ -44,8 +44,41 @@ LL | match NonEmptyStruct(true) {}
4444
|
4545
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
4646

47+
error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled
48+
--> $DIR/match-empty-exhaustive_patterns.rs:46:11
49+
|
50+
LL | union NonEmptyUnion1 {
51+
| - -------------- variant not covered
52+
| _|
53+
| |
54+
LL | | foo: (),
55+
LL | | }
56+
| |_- `NonEmptyUnion1` defined here
57+
...
58+
LL | match (NonEmptyUnion1 { foo: () }) {}
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
|
61+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
62+
63+
error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled
64+
--> $DIR/match-empty-exhaustive_patterns.rs:48:11
65+
|
66+
LL | union NonEmptyUnion2 {
67+
| - -------------- variant not covered
68+
| _|
69+
| |
70+
LL | | foo: (),
71+
LL | | bar: (),
72+
LL | | }
73+
| |_- `NonEmptyUnion2` defined here
74+
...
75+
LL | match (NonEmptyUnion2 { foo: () }) {}
76+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77+
|
78+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
79+
4780
error[E0004]: non-exhaustive patterns: pattern `Foo` of type `NonEmptyEnum1` is not handled
48-
--> $DIR/match-empty-exhaustive_patterns.rs:39:11
81+
--> $DIR/match-empty-exhaustive_patterns.rs:50:11
4982
|
5083
LL | / enum NonEmptyEnum1 {
5184
LL | | Foo(bool),
@@ -59,7 +92,7 @@ LL | match NonEmptyEnum1::Foo(true) {}
5992
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
6093

6194
error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum2` are not handled
62-
--> $DIR/match-empty-exhaustive_patterns.rs:41:11
95+
--> $DIR/match-empty-exhaustive_patterns.rs:52:11
6396
|
6497
LL | / enum NonEmptyEnum2 {
6598
LL | | Foo(bool),
@@ -75,7 +108,7 @@ LL | match NonEmptyEnum2::Foo(true) {}
75108
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
76109

77110
error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum5` are not handled
78-
--> $DIR/match-empty-exhaustive_patterns.rs:43:11
111+
--> $DIR/match-empty-exhaustive_patterns.rs:54:11
79112
|
80113
LL | / enum NonEmptyEnum5 {
81114
LL | | V1, V2, V3, V4, V5,
@@ -87,6 +120,6 @@ LL | match NonEmptyEnum5::V1 {}
87120
|
88121
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
89122

90-
error: aborting due to 8 previous errors
123+
error: aborting due to 10 previous errors
91124

92125
For more information about this error, try `rustc --explain E0004`.

src/test/ui/pattern/usefulness/match-empty.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
enum Foo {}
44

55
struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
6+
union NonEmptyUnion1 {
7+
foo: (),
8+
}
9+
union NonEmptyUnion2 {
10+
foo: (),
11+
bar: (),
12+
}
613
enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here
714
Foo(bool), //~ variant not covered
815
}
@@ -20,7 +27,7 @@ fn foo1(x: Foo) {
2027

2128
fn foo2(x: Foo) {
2229
match x {
23-
_ => {}, // FIXME: should be unreachable
30+
_ => {}, // Not detected as unreachable, see #55123.
2431
}
2532
}
2633

@@ -39,6 +46,10 @@ fn main() {
3946
//~^ ERROR type `u8` is non-empty
4047
match NonEmptyStruct(true) {}
4148
//~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled
49+
match (NonEmptyUnion1 { foo: () }) {}
50+
//~^ ERROR pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled
51+
match (NonEmptyUnion2 { foo: () }) {}
52+
//~^ ERROR pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled
4253
match NonEmptyEnum1::Foo(true) {}
4354
//~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled
4455
match NonEmptyEnum2::Foo(true) {}

src/test/ui/pattern/usefulness/match-empty.stderr

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
2-
--> $DIR/match-empty.rs:38:11
2+
--> $DIR/match-empty.rs:45:11
33
|
44
LL | match 0u8 {}
55
| ^^^
66
|
77
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
88

99
error[E0004]: non-exhaustive patterns: pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled
10-
--> $DIR/match-empty.rs:40:11
10+
--> $DIR/match-empty.rs:47:11
1111
|
1212
LL | struct NonEmptyStruct(bool);
1313
| ----------------------------
@@ -20,8 +20,41 @@ LL | match NonEmptyStruct(true) {}
2020
|
2121
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
2222

23+
error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled
24+
--> $DIR/match-empty.rs:49:11
25+
|
26+
LL | union NonEmptyUnion1 {
27+
| - -------------- variant not covered
28+
| _|
29+
| |
30+
LL | | foo: (),
31+
LL | | }
32+
| |_- `NonEmptyUnion1` defined here
33+
...
34+
LL | match (NonEmptyUnion1 { foo: () }) {}
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
|
37+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
38+
39+
error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled
40+
--> $DIR/match-empty.rs:51:11
41+
|
42+
LL | union NonEmptyUnion2 {
43+
| - -------------- variant not covered
44+
| _|
45+
| |
46+
LL | | foo: (),
47+
LL | | bar: (),
48+
LL | | }
49+
| |_- `NonEmptyUnion2` defined here
50+
...
51+
LL | match (NonEmptyUnion2 { foo: () }) {}
52+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53+
|
54+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
55+
2356
error[E0004]: non-exhaustive patterns: pattern `Foo` of type `NonEmptyEnum1` is not handled
24-
--> $DIR/match-empty.rs:42:11
57+
--> $DIR/match-empty.rs:53:11
2558
|
2659
LL | / enum NonEmptyEnum1 {
2760
LL | | Foo(bool),
@@ -35,7 +68,7 @@ LL | match NonEmptyEnum1::Foo(true) {}
3568
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
3669

3770
error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum2` are not handled
38-
--> $DIR/match-empty.rs:44:11
71+
--> $DIR/match-empty.rs:55:11
3972
|
4073
LL | / enum NonEmptyEnum2 {
4174
LL | | Foo(bool),
@@ -51,7 +84,7 @@ LL | match NonEmptyEnum2::Foo(true) {}
5184
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
5285

5386
error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum5` are not handled
54-
--> $DIR/match-empty.rs:46:11
87+
--> $DIR/match-empty.rs:57:11
5588
|
5689
LL | / enum NonEmptyEnum5 {
5790
LL | | V1, V2, V3, V4, V5,
@@ -63,6 +96,6 @@ LL | match NonEmptyEnum5::V1 {}
6396
|
6497
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
6598

66-
error: aborting due to 5 previous errors
99+
error: aborting due to 7 previous errors
67100

68101
For more information about this error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)