Skip to content

Commit bb2e530

Browse files
committed
missing match arm add test cases to demonstrate enum tuple struct with ellipsis behavior
1 parent a59179a commit bb2e530

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

crates/ra_hir_ty/src/_match.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,45 @@ mod tests {
14841484

14851485
check_no_diagnostic(content);
14861486
}
1487+
1488+
#[test]
1489+
fn enum_tuple_partial_ellipsis_no_diagnostic() {
1490+
let content = r"
1491+
enum Either {
1492+
A(bool, bool, bool, bool),
1493+
B,
1494+
}
1495+
fn test_fn() {
1496+
match Either::B {
1497+
Either::A(true, .., true) => {},
1498+
Either::A(true, .., false) => {},
1499+
Either::A(false, .., true) => {},
1500+
Either::A(false, .., false) => {},
1501+
Either::B => {},
1502+
}
1503+
}
1504+
";
1505+
1506+
check_no_diagnostic(content);
1507+
}
1508+
1509+
#[test]
1510+
fn enum_tuple_ellipsis_no_diagnostic() {
1511+
let content = r"
1512+
enum Either {
1513+
A(bool, bool, bool, bool),
1514+
B,
1515+
}
1516+
fn test_fn() {
1517+
match Either::B {
1518+
Either::A(..) => {},
1519+
Either::B => {},
1520+
}
1521+
}
1522+
";
1523+
1524+
check_no_diagnostic(content);
1525+
}
14871526
}
14881527

14891528
#[cfg(test)]
@@ -1628,4 +1667,29 @@ mod false_negatives {
16281667
// See comments on `tuple_of_bools_with_ellipsis_at_end_missing_arm`.
16291668
check_no_diagnostic(content);
16301669
}
1670+
1671+
#[test]
1672+
fn enum_tuple_partial_ellipsis_missing_arm() {
1673+
let content = r"
1674+
enum Either {
1675+
A(bool, bool, bool, bool),
1676+
B,
1677+
}
1678+
fn test_fn() {
1679+
match Either::B {
1680+
Either::A(true, .., true) => {},
1681+
Either::A(true, .., false) => {},
1682+
Either::A(false, .., false) => {},
1683+
Either::B => {},
1684+
}
1685+
}
1686+
";
1687+
1688+
// This is a false negative.
1689+
// The `..` pattern is currently lowered to a single `Pat::Wild`
1690+
// no matter how many fields the `..` pattern is covering. This
1691+
// causes us to return a `MatchCheckErr::MalformedMatchArm` in
1692+
// `Pat::specialize_constructor`.
1693+
check_no_diagnostic(content);
1694+
}
16311695
}

0 commit comments

Comments
 (0)