8261: Fix expansion of OR-patterns in match check r=Veykril a=Jesse-Bakker

Fixes #8249


Co-authored-by: Jesse Bakker <github@jessebakker.com>
This commit is contained in:
bors[bot] 2021-03-30 16:34:53 +00:00 committed by GitHub
commit 277db63a08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -539,7 +539,7 @@ impl Matrix {
if let Some(Pat::Or(pat_ids)) = row.get_head().map(|pat_id| pat_id.as_pat(cx)) {
// Or patterns are expanded here
for pat_id in pat_ids {
self.0.push(PatStack::from_pattern(pat_id));
self.0.push(row.replace_head_with([pat_id].iter()));
}
} else {
self.0.push(row);
@ -1084,6 +1084,20 @@ fn main() {
);
}
#[test]
fn or_pattern_no_diagnostic() {
check_diagnostics(
r#"
enum Either {A, B}
fn main() {
match (Either::A, Either::B) {
(Either::A | Either::B, _) => (),
}
}"#,
)
}
#[test]
fn mismatched_types() {
// Match statements with arms that don't match the
@ -1335,30 +1349,6 @@ fn bang(never: !) {
);
}
#[test]
fn or_pattern_panic() {
check_diagnostics(
r#"
pub enum Category { Infinity, Zero }
fn panic(a: Category, b: Category) {
match (a, b) {
(Category::Zero | Category::Infinity, _) => (),
(_, Category::Zero | Category::Infinity) => (),
}
// FIXME: This is a false positive, but the code used to cause a panic in the match checker,
// so this acts as a regression test for that.
match (a, b) {
//^^^^^^ Missing match arm
(Category::Infinity, Category::Infinity) | (Category::Zero, Category::Zero) => (),
(Category::Infinity | Category::Zero, _) => (),
}
}
"#,
);
}
#[test]
fn unknown_type() {
check_diagnostics(