Add tests
This commit is contained in:
parent
6ed31aba1a
commit
12ebc3dd96
@ -160,3 +160,21 @@ fn main() {
|
||||
| (y, x) => {} //~ ERROR unreachable
|
||||
}
|
||||
}
|
||||
|
||||
fn unreachable_in_param((_ | (_, _)): (bool, bool)) {}
|
||||
|
||||
fn unreachable_in_binding() {
|
||||
let bool_pair = (true, true);
|
||||
let bool_option = Some(true);
|
||||
|
||||
let (_ | (_, _)) = bool_pair;
|
||||
for (_ | (_, _)) in [bool_pair] {}
|
||||
//~^ ERROR unreachable
|
||||
|
||||
let (Some(_) | Some(true)) = bool_option else { return };
|
||||
//~^ ERROR unreachable
|
||||
if let Some(_) | Some(true) = bool_option {}
|
||||
//~^ ERROR unreachable
|
||||
while let Some(_) | Some(true) = bool_option {}
|
||||
//~^ ERROR unreachable
|
||||
}
|
||||
|
@ -184,5 +184,29 @@ error: unreachable pattern
|
||||
LL | | (y, x) => {}
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 29 previous errors
|
||||
error: unreachable pattern
|
||||
--> $DIR/exhaustiveness-unreachable-pattern.rs:171:14
|
||||
|
|
||||
LL | for (_ | (_, _)) in [bool_pair] {}
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/exhaustiveness-unreachable-pattern.rs:174:20
|
||||
|
|
||||
LL | let (Some(_) | Some(true)) = bool_option else { return };
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/exhaustiveness-unreachable-pattern.rs:176:22
|
||||
|
|
||||
LL | if let Some(_) | Some(true) = bool_option {}
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/exhaustiveness-unreachable-pattern.rs:178:25
|
||||
|
|
||||
LL | while let Some(_) | Some(true) = bool_option {}
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 33 previous errors
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
error: unreachable pattern
|
||||
--> $DIR/unreachable.rs:17:9
|
||||
|
|
||||
LL | Err(!),
|
||||
| ^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unreachable.rs:7:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/unreachable.rs:21:12
|
||||
|
|
||||
LL | if let Err(!) = res_void {}
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/unreachable.rs:23:24
|
||||
|
|
||||
LL | if let (Ok(true) | Err(!)) = res_void {}
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/unreachable.rs:25:23
|
||||
|
|
||||
LL | for (Ok(mut _x) | Err(!)) in [res_void] {}
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
29
tests/ui/rfcs/rfc-0000-never_patterns/unreachable.rs
Normal file
29
tests/ui/rfcs/rfc-0000-never_patterns/unreachable.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// revisions: normal exh_pats
|
||||
//[normal] check-pass
|
||||
#![feature(never_patterns)]
|
||||
#![allow(incomplete_features)]
|
||||
#![cfg_attr(exh_pats, feature(exhaustive_patterns))]
|
||||
#![allow(dead_code, unreachable_code)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum Void {}
|
||||
|
||||
fn main() {
|
||||
let res_void: Result<bool, Void> = Ok(true);
|
||||
|
||||
match res_void {
|
||||
Ok(_x) => {}
|
||||
Err(!),
|
||||
//[exh_pats]~^ ERROR unreachable
|
||||
}
|
||||
let (Ok(_x) | Err(!)) = res_void;
|
||||
if let Err(!) = res_void {}
|
||||
//[exh_pats]~^ ERROR unreachable
|
||||
if let (Ok(true) | Err(!)) = res_void {}
|
||||
//[exh_pats]~^ ERROR unreachable
|
||||
for (Ok(mut _x) | Err(!)) in [res_void] {}
|
||||
//[exh_pats]~^ ERROR unreachable
|
||||
}
|
||||
|
||||
fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {}
|
Loading…
x
Reference in New Issue
Block a user