Skip to content

Commit a59179a

Browse files
committed
missing match arms add test cases to demonstrate behavior of tuple with pattern
1 parent aec20e5 commit a59179a

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

crates/ra_hir_ty/src/_match.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,47 @@ mod tests {
972972
check_no_diagnostic(content);
973973
}
974974

975+
#[test]
976+
fn tuple_of_bools_with_ellipsis_at_end_no_diagnostic() {
977+
let content = r"
978+
fn test_fn() {
979+
match (false, true, false) {
980+
(false, ..) => {},
981+
(true, ..) => {},
982+
}
983+
}
984+
";
985+
986+
check_no_diagnostic(content);
987+
}
988+
989+
#[test]
990+
fn tuple_of_bools_with_ellipsis_at_beginning_no_diagnostic() {
991+
let content = r"
992+
fn test_fn() {
993+
match (false, true, false) {
994+
(.., false) => {},
995+
(.., true) => {},
996+
}
997+
}
998+
";
999+
1000+
check_no_diagnostic(content);
1001+
}
1002+
1003+
#[test]
1004+
fn tuple_of_bools_with_ellipsis_no_diagnostic() {
1005+
let content = r"
1006+
fn test_fn() {
1007+
match (false, true, false) {
1008+
(..) => {},
1009+
}
1010+
}
1011+
";
1012+
1013+
check_no_diagnostic(content);
1014+
}
1015+
9751016
#[test]
9761017
fn tuple_of_tuple_and_bools_no_arms() {
9771018
let content = r"
@@ -1553,4 +1594,38 @@ mod false_negatives {
15531594
// with `!`.
15541595
check_no_diagnostic(content);
15551596
}
1597+
1598+
#[test]
1599+
fn tuple_of_bools_with_ellipsis_at_end_missing_arm() {
1600+
let content = r"
1601+
fn test_fn() {
1602+
match (false, true, false) {
1603+
(false, ..) => {},
1604+
}
1605+
}
1606+
";
1607+
1608+
// This is a false negative.
1609+
// The `..` pattern is currently lowered to a single `Pat::Wild`
1610+
// no matter how many fields the `..` pattern is covering. This
1611+
// causes the match arm in this test not to type check against
1612+
// the match expression, which causes this diagnostic not to
1613+
// fire.
1614+
check_no_diagnostic(content);
1615+
}
1616+
1617+
#[test]
1618+
fn tuple_of_bools_with_ellipsis_at_beginning_missing_arm() {
1619+
let content = r"
1620+
fn test_fn() {
1621+
match (false, true, false) {
1622+
(.., false) => {},
1623+
}
1624+
}
1625+
";
1626+
1627+
// This is a false negative.
1628+
// See comments on `tuple_of_bools_with_ellipsis_at_end_missing_arm`.
1629+
check_no_diagnostic(content);
1630+
}
15561631
}

0 commit comments

Comments
 (0)