From bb2e5308b77e5d115df17411aaa2dd26be171b0a Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sat, 11 Apr 2020 21:20:52 -0700 Subject: missing match arm add test cases to demonstrate enum tuple struct with ellipsis behavior --- crates/ra_hir_ty/src/_match.rs | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'crates/ra_hir_ty/src') diff --git a/crates/ra_hir_ty/src/_match.rs b/crates/ra_hir_ty/src/_match.rs index c9a6551ab..c482cf619 100644 --- a/crates/ra_hir_ty/src/_match.rs +++ b/crates/ra_hir_ty/src/_match.rs @@ -1484,6 +1484,45 @@ mod tests { check_no_diagnostic(content); } + + #[test] + fn enum_tuple_partial_ellipsis_no_diagnostic() { + let content = r" + enum Either { + A(bool, bool, bool, bool), + B, + } + fn test_fn() { + match Either::B { + Either::A(true, .., true) => {}, + Either::A(true, .., false) => {}, + Either::A(false, .., true) => {}, + Either::A(false, .., false) => {}, + Either::B => {}, + } + } + "; + + check_no_diagnostic(content); + } + + #[test] + fn enum_tuple_ellipsis_no_diagnostic() { + let content = r" + enum Either { + A(bool, bool, bool, bool), + B, + } + fn test_fn() { + match Either::B { + Either::A(..) => {}, + Either::B => {}, + } + } + "; + + check_no_diagnostic(content); + } } #[cfg(test)] @@ -1628,4 +1667,29 @@ mod false_negatives { // See comments on `tuple_of_bools_with_ellipsis_at_end_missing_arm`. check_no_diagnostic(content); } + + #[test] + fn enum_tuple_partial_ellipsis_missing_arm() { + let content = r" + enum Either { + A(bool, bool, bool, bool), + B, + } + fn test_fn() { + match Either::B { + Either::A(true, .., true) => {}, + Either::A(true, .., false) => {}, + Either::A(false, .., false) => {}, + Either::B => {}, + } + } + "; + + // 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 us to return a `MatchCheckErr::MalformedMatchArm` in + // `Pat::specialize_constructor`. + check_no_diagnostic(content); + } } -- cgit v1.2.3