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#65414 - davidtwco:issue-65157-non-exhaustiv…
…e-always-useful, r=varkor ignore uninhabited non-exhaustive variant fields Fixes rust-lang#65157. This PR modifies the uninhabitedness checking so that the fields of a non-exhaustive variant (which is not local) are ignored if they are uninhabited. This is an improvement over the previous behaviour which considered all non-local non-exhaustive variants useful because unreachable patterns are now detected. r? @arielb1 cc @varkor
- Loading branch information
Showing
3 changed files
with
75 additions
and
49 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
22 changes: 22 additions & 0 deletions
22
src/test/ui/rfc-2008-non-exhaustive/uninhabited/issue-65157-repeated-match-arm.rs
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,22 @@ | ||
// aux-build:uninhabited.rs | ||
#![deny(unreachable_patterns)] | ||
#![feature(never_type)] | ||
#![feature(non_exhaustive)] | ||
|
||
extern crate uninhabited; | ||
|
||
use uninhabited::PartiallyInhabitedVariants; | ||
|
||
// This test checks a redundant/useless pattern of a non-exhaustive enum/variant is still | ||
// warned against. | ||
|
||
pub fn foo(x: PartiallyInhabitedVariants) { | ||
match x { | ||
PartiallyInhabitedVariants::Struct { .. } => {}, | ||
PartiallyInhabitedVariants::Struct { .. } => {}, | ||
//~^ ERROR unreachable pattern | ||
_ => {}, | ||
} | ||
} | ||
|
||
fn main() { } |
14 changes: 14 additions & 0 deletions
14
src/test/ui/rfc-2008-non-exhaustive/uninhabited/issue-65157-repeated-match-arm.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,14 @@ | ||
error: unreachable pattern | ||
--> $DIR/issue-65157-repeated-match-arm.rs:16:9 | ||
| | ||
LL | PartiallyInhabitedVariants::Struct { .. } => {}, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/issue-65157-repeated-match-arm.rs:2:9 | ||
| | ||
LL | #![deny(unreachable_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|