Skip to content

Commit 80fe038

Browse files
committed
Fix expansion of OR-patterns in match check
1 parent 2490ab7 commit 80fe038

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

crates/hir_ty/src/diagnostics/match_check.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ impl Matrix {
539539
if let Some(Pat::Or(pat_ids)) = row.get_head().map(|pat_id| pat_id.as_pat(cx)) {
540540
// Or patterns are expanded here
541541
for pat_id in pat_ids {
542-
self.0.push(PatStack::from_pattern(pat_id));
542+
self.0.push(row.replace_head_with([pat_id].iter()));
543543
}
544544
} else {
545545
self.0.push(row);
@@ -1084,6 +1084,20 @@ fn main() {
10841084
);
10851085
}
10861086

1087+
#[test]
1088+
fn or_pattern_no_diagnostic() {
1089+
check_diagnostics(
1090+
r#"
1091+
enum Either {A, B}
1092+
1093+
fn main() {
1094+
match (Either::A, Either::B) {
1095+
(Either::A | Either::B, _) => (),
1096+
}
1097+
}"#,
1098+
)
1099+
}
1100+
10871101
#[test]
10881102
fn mismatched_types() {
10891103
// Match statements with arms that don't match the
@@ -1335,30 +1349,6 @@ fn bang(never: !) {
13351349
);
13361350
}
13371351

1338-
#[test]
1339-
fn or_pattern_panic() {
1340-
check_diagnostics(
1341-
r#"
1342-
pub enum Category { Infinity, Zero }
1343-
1344-
fn panic(a: Category, b: Category) {
1345-
match (a, b) {
1346-
(Category::Zero | Category::Infinity, _) => (),
1347-
(_, Category::Zero | Category::Infinity) => (),
1348-
}
1349-
1350-
// FIXME: This is a false positive, but the code used to cause a panic in the match checker,
1351-
// so this acts as a regression test for that.
1352-
match (a, b) {
1353-
//^^^^^^ Missing match arm
1354-
(Category::Infinity, Category::Infinity) | (Category::Zero, Category::Zero) => (),
1355-
(Category::Infinity | Category::Zero, _) => (),
1356-
}
1357-
}
1358-
"#,
1359-
);
1360-
}
1361-
13621352
#[test]
13631353
fn unknown_type() {
13641354
check_diagnostics(

0 commit comments

Comments
 (0)