From 678d85ca7e4d7e631a450b8c050fe7696da0cac3 Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Thu, 29 Apr 2021 23:28:43 +0500 Subject: Implement struct ctor application --- crates/hir_ty/src/diagnostics/pattern.rs | 55 ++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src/diagnostics/pattern.rs') diff --git a/crates/hir_ty/src/diagnostics/pattern.rs b/crates/hir_ty/src/diagnostics/pattern.rs index 28c7a244d..4dcbd7f9f 100644 --- a/crates/hir_ty/src/diagnostics/pattern.rs +++ b/crates/hir_ty/src/diagnostics/pattern.rs @@ -11,24 +11,67 @@ mod tests { use super::*; #[test] - fn unit_exhaustive() { + fn unit() { check_diagnostics( r#" fn main() { - match () { () => {} } - match () { _ => {} } + match () { () => {} } + match () { _ => {} } + match () { } + //^^ Missing match arm } "#, ); } #[test] - fn unit_non_exhaustive() { + fn tuple_of_units() { check_diagnostics( r#" fn main() { - match () { } - //^^ Missing match arm + match ((), ()) { ((), ()) => {} } + match ((), ()) { ((), _) => {} } + match ((), ()) { (_, _) => {} } + match ((), ()) { _ => {} } + match ((), ()) { } + //^^^^^^^^ Missing match arm +} +"#, + ); + } + + #[test] + fn tuple_with_ellipsis() { + // TODO: test non-exhaustive match with ellipsis in the middle + // of a pattern, check reported witness + check_diagnostics( + r#" +struct A; struct B; +fn main(v: (A, (), B)) { + match v { (A, ..) => {} } + match v { (.., B) => {} } + match v { (A, .., B) => {} } + match v { (..) => {} } + match v { } + //^ Missing match arm +} +"#, + ); + } + + #[test] + fn strukt() { + check_diagnostics( + r#" +struct A; struct B; +struct S { a: A, b: B} +fn main(v: S) { + match v { S { a, b } => {} } + match v { S { a: _, b: _ } => {} } + match v { S { .. } => {} } + match v { _ => {} } + match v { } + //^ Missing match arm } "#, ); -- cgit v1.2.3