forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#120097 - Nadrieril:consistent_unreachable_s…
…ubpats, r=compiler-errors Report unreachable subpatterns consistently We weren't reporting unreachable subpatterns in function arguments and `let` expressions. This wasn't very important, but never patterns make it more relevant: a user might write `let (Ok(x) | Err(!)) = ...` in a case where `let Ok(x) = ...` is accepted, so we should report the `Err(!)` as redundant. r? ``@compiler-errors``
- Loading branch information
Showing
6 changed files
with
182 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/ui/rfcs/rfc-0000-never_patterns/unreachable.exh_pats.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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: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:24:24 | ||
| | ||
LL | if let (Ok(true) | Err(!)) = res_void {} | ||
| ^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/unreachable.rs:26:23 | ||
| | ||
LL | for (Ok(mut _x) | Err(!)) in [res_void] {} | ||
| ^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/unreachable.rs:30:18 | ||
| | ||
LL | fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {} | ||
| ^^^^^^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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; | ||
//[exh_pats]~^ ERROR unreachable | ||
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>) {} | ||
//[exh_pats]~^ ERROR unreachable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// run-pass | ||
#![allow(unreachable_patterns)] | ||
|
||
#[derive(Copy, Clone)] | ||
#[allow(dead_code)] | ||
|