Consistently warn unreachable subpatterns

This commit is contained in:
Nadrieril 2024-01-18 14:59:48 +01:00
parent 753680afe8
commit 0a9bb97229
6 changed files with 74 additions and 39 deletions

View file

@ -162,12 +162,14 @@ fn main() {
}
fn unreachable_in_param((_ | (_, _)): (bool, bool)) {}
//~^ ERROR unreachable
fn unreachable_in_binding() {
let bool_pair = (true, true);
let bool_option = Some(true);
let (_ | (_, _)) = bool_pair;
//~^ ERROR unreachable
for (_ | (_, _)) in [bool_pair] {}
//~^ ERROR unreachable

View file

@ -184,29 +184,41 @@ error: unreachable pattern
LL | | (y, x) => {}
| ^^^^^^
error: unreachable pattern
--> $DIR/exhaustiveness-unreachable-pattern.rs:164:30
|
LL | fn unreachable_in_param((_ | (_, _)): (bool, bool)) {}
| ^^^^^^
error: unreachable pattern
--> $DIR/exhaustiveness-unreachable-pattern.rs:171:14
|
LL | let (_ | (_, _)) = bool_pair;
| ^^^^^^
error: unreachable pattern
--> $DIR/exhaustiveness-unreachable-pattern.rs:173:14
|
LL | for (_ | (_, _)) in [bool_pair] {}
| ^^^^^^
error: unreachable pattern
--> $DIR/exhaustiveness-unreachable-pattern.rs:174:20
--> $DIR/exhaustiveness-unreachable-pattern.rs:176:20
|
LL | let (Some(_) | Some(true)) = bool_option else { return };
| ^^^^^^^^^^
error: unreachable pattern
--> $DIR/exhaustiveness-unreachable-pattern.rs:176:22
--> $DIR/exhaustiveness-unreachable-pattern.rs:178:22
|
LL | if let Some(_) | Some(true) = bool_option {}
| ^^^^^^^^^^
error: unreachable pattern
--> $DIR/exhaustiveness-unreachable-pattern.rs:178:25
--> $DIR/exhaustiveness-unreachable-pattern.rs:180:25
|
LL | while let Some(_) | Some(true) = bool_option {}
| ^^^^^^^^^^
error: aborting due to 33 previous errors
error: aborting due to 35 previous errors

View file

@ -11,22 +11,34 @@ LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
error: unreachable pattern
--> $DIR/unreachable.rs:21:12
--> $DIR/unreachable.rs:20:19
|
LL | let (Ok(_x) | Err(!)) = res_void;
| ^^^^^^
error: unreachable pattern
--> $DIR/unreachable.rs:22:12
|
LL | if let Err(!) = res_void {}
| ^^^^^^
error: unreachable pattern
--> $DIR/unreachable.rs:23:24
--> $DIR/unreachable.rs:24:24
|
LL | if let (Ok(true) | Err(!)) = res_void {}
| ^^^^^^
error: unreachable pattern
--> $DIR/unreachable.rs:25:23
--> $DIR/unreachable.rs:26:23
|
LL | for (Ok(mut _x) | Err(!)) in [res_void] {}
| ^^^^^^
error: aborting due to 4 previous errors
error: unreachable pattern
--> $DIR/unreachable.rs:30:18
|
LL | fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {}
| ^^^^^^
error: aborting due to 6 previous errors

View file

@ -18,6 +18,7 @@ fn main() {
//[exh_pats]~^ ERROR unreachable
}
let (Ok(_x) | Err(!)) = res_void;
//[exh_pats]~^ ERROR unreachable
if let Err(!) = res_void {}
//[exh_pats]~^ ERROR unreachable
if let (Ok(true) | Err(!)) = res_void {}
@ -27,3 +28,4 @@ fn main() {
}
fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {}
//[exh_pats]~^ ERROR unreachable

View file

@ -1,4 +1,5 @@
// run-pass
#![allow(unreachable_patterns)]
#[derive(Copy, Clone)]
#[allow(dead_code)]