Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2309783

Browse files
committed
Add tests
1 parent 2225ee1 commit 2309783

File tree

7 files changed

+95
-19
lines changed

7 files changed

+95
-19
lines changed

src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ fn main() {
6464
| 2, ..] => {}
6565
_ => {}
6666
}
67+
// FIXME: incorrect
68+
match &[][..] {
69+
[true] => {}
70+
[true //~ ERROR unreachable
71+
| false, ..] => {}
72+
_ => {}
73+
}
74+
match &[][..] {
75+
[false] => {}
76+
[true, ..] => {}
77+
[true //~ ERROR unreachable
78+
| false, ..] => {}
79+
_ => {}
80+
}
81+
match (true, None) {
82+
(true, Some(_)) => {}
83+
(false, Some(true)) => {}
84+
(true | false, None | Some(true // FIXME: should be unreachable
85+
| false)) => {}
86+
}
87+
macro_rules! t_or_f {
88+
() => {
89+
(true // FIXME: should be unreachable
90+
| false)
91+
};
92+
}
93+
match (true, None) {
94+
(true, Some(_)) => {}
95+
(false, Some(true)) => {}
96+
(true | false, None | Some(t_or_f!())) => {}
97+
}
6798
match Some(0) {
6899
Some(0) => {}
69100
Some(0 //~ ERROR unreachable

src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,40 @@ LL | [1
9595
| ^
9696

9797
error: unreachable pattern
98-
--> $DIR/exhaustiveness-unreachable-pattern.rs:69:14
98+
--> $DIR/exhaustiveness-unreachable-pattern.rs:70:10
99+
|
100+
LL | [true
101+
| ^^^^
102+
103+
error: unreachable pattern
104+
--> $DIR/exhaustiveness-unreachable-pattern.rs:77:10
105+
|
106+
LL | [true
107+
| ^^^^
108+
109+
error: unreachable pattern
110+
--> $DIR/exhaustiveness-unreachable-pattern.rs:100:14
99111
|
100112
LL | Some(0
101113
| ^
102114

103115
error: unreachable pattern
104-
--> $DIR/exhaustiveness-unreachable-pattern.rs:88:19
116+
--> $DIR/exhaustiveness-unreachable-pattern.rs:119:19
105117
|
106118
LL | | false) => {}
107119
| ^^^^^
108120

109121
error: unreachable pattern
110-
--> $DIR/exhaustiveness-unreachable-pattern.rs:96:15
122+
--> $DIR/exhaustiveness-unreachable-pattern.rs:127:15
111123
|
112124
LL | | true) => {}
113125
| ^^^^
114126

115127
error: unreachable pattern
116-
--> $DIR/exhaustiveness-unreachable-pattern.rs:102:15
128+
--> $DIR/exhaustiveness-unreachable-pattern.rs:133:15
117129
|
118130
LL | | true,
119131
| ^^^^
120132

121-
error: aborting due to 19 previous errors
133+
error: aborting due to 21 previous errors
122134

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
pub enum T {
22
T1(()),
3-
T2(())
3+
T2(()),
44
}
55

66
pub enum V {
77
V1(isize),
8-
V2(bool)
8+
V2(bool),
99
}
1010

1111
fn main() {
1212
match (T::T1(()), V::V2(true)) {
13-
//~^ ERROR non-exhaustive patterns: `(T1(()), V2(_))` not covered
13+
//~^ ERROR non-exhaustive patterns: `(T1(()), V2(_))` not covered
1414
(T::T1(()), V::V1(i)) => (),
15-
(T::T2(()), V::V2(b)) => ()
15+
(T::T2(()), V::V2(b)) => (),
1616
}
1717
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
fn foo(a: Option<usize>, b: Option<usize>) {
2-
match (a,b) {
3-
//~^ ERROR: non-exhaustive patterns: `(None, None)` not covered
4-
(Some(a), Some(b)) if a == b => { }
5-
(Some(_), None) |
6-
(None, Some(_)) => { }
7-
}
2+
match (a, b) {
3+
//~^ ERROR: non-exhaustive patterns: `(None, None)` not covered
4+
(Some(a), Some(b)) if a == b => {}
5+
(Some(_), None) | (None, Some(_)) => {}
6+
}
87
}
98

109
fn main() {
11-
foo(None, None);
10+
foo(None, None);
1211
}

src/test/ui/pattern/usefulness/issue-2111.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0004]: non-exhaustive patterns: `(None, None)` not covered
2-
--> $DIR/issue-2111.rs:2:9
2+
--> $DIR/issue-2111.rs:2:11
33
|
4-
LL | match (a,b) {
5-
| ^^^^^ pattern `(None, None)` not covered
4+
LL | match (a, b) {
5+
| ^^^^^^ pattern `(None, None)` not covered
66
|
77
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
88
= note: the matched value is of type `(Option<usize>, Option<usize>)`
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
enum Foo {
2+
A(bool),
3+
B(bool),
4+
C(bool),
5+
}
6+
7+
fn main() {
8+
match Foo::A(true) {
9+
//~^ ERROR non-exhaustive patterns: `A(false)` not covered
10+
Foo::A(true) => {}
11+
Foo::B(true) => {}
12+
Foo::C(true) => {}
13+
}
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0004]: non-exhaustive patterns: `A(false)` not covered
2+
--> $DIR/issue-56379.rs:8:11
3+
|
4+
LL | / enum Foo {
5+
LL | | A(bool),
6+
| | - not covered
7+
LL | | B(bool),
8+
LL | | C(bool),
9+
LL | | }
10+
| |_- `Foo` defined here
11+
...
12+
LL | match Foo::A(true) {
13+
| ^^^^^^^^^^^^ pattern `A(false)` not covered
14+
|
15+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
16+
= note: the matched value is of type `Foo`
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)