From a59179ac2d0894dc45d614242816665b9bd6ef8a Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sat, 11 Apr 2020 20:50:54 -0700 Subject: missing match arms add test cases to demonstrate behavior of tuple with pattern --- crates/ra_hir_ty/src/_match.rs | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/crates/ra_hir_ty/src/_match.rs b/crates/ra_hir_ty/src/_match.rs index 596194dcf..c9a6551ab 100644 --- a/crates/ra_hir_ty/src/_match.rs +++ b/crates/ra_hir_ty/src/_match.rs @@ -972,6 +972,47 @@ mod tests { check_no_diagnostic(content); } + #[test] + fn tuple_of_bools_with_ellipsis_at_end_no_diagnostic() { + let content = r" + fn test_fn() { + match (false, true, false) { + (false, ..) => {}, + (true, ..) => {}, + } + } + "; + + check_no_diagnostic(content); + } + + #[test] + fn tuple_of_bools_with_ellipsis_at_beginning_no_diagnostic() { + let content = r" + fn test_fn() { + match (false, true, false) { + (.., false) => {}, + (.., true) => {}, + } + } + "; + + check_no_diagnostic(content); + } + + #[test] + fn tuple_of_bools_with_ellipsis_no_diagnostic() { + let content = r" + fn test_fn() { + match (false, true, false) { + (..) => {}, + } + } + "; + + check_no_diagnostic(content); + } + #[test] fn tuple_of_tuple_and_bools_no_arms() { let content = r" @@ -1553,4 +1594,38 @@ mod false_negatives { // with `!`. check_no_diagnostic(content); } + + #[test] + fn tuple_of_bools_with_ellipsis_at_end_missing_arm() { + let content = r" + fn test_fn() { + match (false, true, false) { + (false, ..) => {}, + } + } + "; + + // This is a false negative. + // The `..` pattern is currently lowered to a single `Pat::Wild` + // no matter how many fields the `..` pattern is covering. This + // causes the match arm in this test not to type check against + // the match expression, which causes this diagnostic not to + // fire. + check_no_diagnostic(content); + } + + #[test] + fn tuple_of_bools_with_ellipsis_at_beginning_missing_arm() { + let content = r" + fn test_fn() { + match (false, true, false) { + (.., false) => {}, + } + } + "; + + // This is a false negative. + // See comments on `tuple_of_bools_with_ellipsis_at_end_missing_arm`. + check_no_diagnostic(content); + } } -- cgit v1.2.3