-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #69891 - Centril:fix-69875, r=varkor
Exhaustiveness checking, `Matrix::push`: recursively expand or-patterns > There's an implicit invariant that there should be no or-patterns directly in the first column of the matrix, but this invariant is broken exactly when an or-pattern has a child that is itself an or-pattern. Here we preserve this broken invariant by recursively expanding `PatKind::Or`s in `Matrix::push`. Fixes #69875. r? @varkor cc @Nadrieril cc #54883
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
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
9 changes: 9 additions & 0 deletions
9
src/test/ui/or-patterns/issue-69875-should-have-been-expanded-earlier-non-exhaustive.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,9 @@ | ||
#![feature(or_patterns)] | ||
|
||
fn main() { | ||
let 0 | (1 | 2) = 0; //~ ERROR refutable pattern in local binding | ||
match 0 { | ||
//~^ ERROR non-exhaustive patterns | ||
0 | (1 | 2) => {} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/ui/or-patterns/issue-69875-should-have-been-expanded-earlier-non-exhaustive.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,25 @@ | ||
error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` and `3i32..=std::i32::MAX` not covered | ||
--> $DIR/issue-69875-should-have-been-expanded-earlier-non-exhaustive.rs:4:9 | ||
| | ||
LL | let 0 | (1 | 2) = 0; | ||
| ^^^^^^^^^^^ patterns `std::i32::MIN..=-1i32` and `3i32..=std::i32::MAX` not covered | ||
| | ||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
help: you might want to use `if let` to ignore the variant that isn't matched | ||
| | ||
LL | if let 0 | (1 | 2) = 0 { /* */ } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0004]: non-exhaustive patterns: `std::i32::MIN..=-1i32` and `3i32..=std::i32::MAX` not covered | ||
--> $DIR/issue-69875-should-have-been-expanded-earlier-non-exhaustive.rs:5:11 | ||
| | ||
LL | match 0 { | ||
| ^ patterns `std::i32::MIN..=-1i32` and `3i32..=std::i32::MAX` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0004, E0005. | ||
For more information about an error, try `rustc --explain E0004`. |
9 changes: 9 additions & 0 deletions
9
src/test/ui/or-patterns/issue-69875-should-have-been-expanded-earlier.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,9 @@ | ||
// check-pass | ||
|
||
#![feature(or_patterns)] | ||
|
||
fn main() { | ||
let 0 | (1 | _) = 0; | ||
if let 0 | (1 | 2) = 0 {} | ||
if let x @ 0 | x @ (1 | 2) = 0 {} | ||
} |