Skip to content

Commit 12ebc3d

Browse files
committed
Add tests
1 parent 6ed31ab commit 12ebc3d

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

tests/ui/or-patterns/exhaustiveness-unreachable-pattern.rs

+18
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,21 @@ fn main() {
160160
| (y, x) => {} //~ ERROR unreachable
161161
}
162162
}
163+
164+
fn unreachable_in_param((_ | (_, _)): (bool, bool)) {}
165+
166+
fn unreachable_in_binding() {
167+
let bool_pair = (true, true);
168+
let bool_option = Some(true);
169+
170+
let (_ | (_, _)) = bool_pair;
171+
for (_ | (_, _)) in [bool_pair] {}
172+
//~^ ERROR unreachable
173+
174+
let (Some(_) | Some(true)) = bool_option else { return };
175+
//~^ ERROR unreachable
176+
if let Some(_) | Some(true) = bool_option {}
177+
//~^ ERROR unreachable
178+
while let Some(_) | Some(true) = bool_option {}
179+
//~^ ERROR unreachable
180+
}

tests/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr

+25-1
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,29 @@ error: unreachable pattern
184184
LL | | (y, x) => {}
185185
| ^^^^^^
186186

187-
error: aborting due to 29 previous errors
187+
error: unreachable pattern
188+
--> $DIR/exhaustiveness-unreachable-pattern.rs:171:14
189+
|
190+
LL | for (_ | (_, _)) in [bool_pair] {}
191+
| ^^^^^^
192+
193+
error: unreachable pattern
194+
--> $DIR/exhaustiveness-unreachable-pattern.rs:174:20
195+
|
196+
LL | let (Some(_) | Some(true)) = bool_option else { return };
197+
| ^^^^^^^^^^
198+
199+
error: unreachable pattern
200+
--> $DIR/exhaustiveness-unreachable-pattern.rs:176:22
201+
|
202+
LL | if let Some(_) | Some(true) = bool_option {}
203+
| ^^^^^^^^^^
204+
205+
error: unreachable pattern
206+
--> $DIR/exhaustiveness-unreachable-pattern.rs:178:25
207+
|
208+
LL | while let Some(_) | Some(true) = bool_option {}
209+
| ^^^^^^^^^^
210+
211+
error: aborting due to 33 previous errors
188212

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: unreachable pattern
2+
--> $DIR/unreachable.rs:17:9
3+
|
4+
LL | Err(!),
5+
| ^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unreachable.rs:7:9
9+
|
10+
LL | #![deny(unreachable_patterns)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: unreachable pattern
14+
--> $DIR/unreachable.rs:21:12
15+
|
16+
LL | if let Err(!) = res_void {}
17+
| ^^^^^^
18+
19+
error: unreachable pattern
20+
--> $DIR/unreachable.rs:23:24
21+
|
22+
LL | if let (Ok(true) | Err(!)) = res_void {}
23+
| ^^^^^^
24+
25+
error: unreachable pattern
26+
--> $DIR/unreachable.rs:25:23
27+
|
28+
LL | for (Ok(mut _x) | Err(!)) in [res_void] {}
29+
| ^^^^^^
30+
31+
error: aborting due to 4 previous errors
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// revisions: normal exh_pats
2+
//[normal] check-pass
3+
#![feature(never_patterns)]
4+
#![allow(incomplete_features)]
5+
#![cfg_attr(exh_pats, feature(exhaustive_patterns))]
6+
#![allow(dead_code, unreachable_code)]
7+
#![deny(unreachable_patterns)]
8+
9+
#[derive(Copy, Clone)]
10+
enum Void {}
11+
12+
fn main() {
13+
let res_void: Result<bool, Void> = Ok(true);
14+
15+
match res_void {
16+
Ok(_x) => {}
17+
Err(!),
18+
//[exh_pats]~^ ERROR unreachable
19+
}
20+
let (Ok(_x) | Err(!)) = res_void;
21+
if let Err(!) = res_void {}
22+
//[exh_pats]~^ ERROR unreachable
23+
if let (Ok(true) | Err(!)) = res_void {}
24+
//[exh_pats]~^ ERROR unreachable
25+
for (Ok(mut _x) | Err(!)) in [res_void] {}
26+
//[exh_pats]~^ ERROR unreachable
27+
}
28+
29+
fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {}

0 commit comments

Comments
 (0)