diff options
Diffstat (limited to 'crates/hir_ty/src/diagnostics/pattern.rs')
-rw-r--r-- | crates/hir_ty/src/diagnostics/pattern.rs | 55 |
1 files changed, 49 insertions, 6 deletions
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 { | |||
11 | use super::*; | 11 | use super::*; |
12 | 12 | ||
13 | #[test] | 13 | #[test] |
14 | fn unit_exhaustive() { | 14 | fn unit() { |
15 | check_diagnostics( | 15 | check_diagnostics( |
16 | r#" | 16 | r#" |
17 | fn main() { | 17 | fn main() { |
18 | match () { () => {} } | 18 | match () { () => {} } |
19 | match () { _ => {} } | 19 | match () { _ => {} } |
20 | match () { } | ||
21 | //^^ Missing match arm | ||
20 | } | 22 | } |
21 | "#, | 23 | "#, |
22 | ); | 24 | ); |
23 | } | 25 | } |
24 | 26 | ||
25 | #[test] | 27 | #[test] |
26 | fn unit_non_exhaustive() { | 28 | fn tuple_of_units() { |
27 | check_diagnostics( | 29 | check_diagnostics( |
28 | r#" | 30 | r#" |
29 | fn main() { | 31 | fn main() { |
30 | match () { } | 32 | match ((), ()) { ((), ()) => {} } |
31 | //^^ Missing match arm | 33 | match ((), ()) { ((), _) => {} } |
34 | match ((), ()) { (_, _) => {} } | ||
35 | match ((), ()) { _ => {} } | ||
36 | match ((), ()) { } | ||
37 | //^^^^^^^^ Missing match arm | ||
38 | } | ||
39 | "#, | ||
40 | ); | ||
41 | } | ||
42 | |||
43 | #[test] | ||
44 | fn tuple_with_ellipsis() { | ||
45 | // TODO: test non-exhaustive match with ellipsis in the middle | ||
46 | // of a pattern, check reported witness | ||
47 | check_diagnostics( | ||
48 | r#" | ||
49 | struct A; struct B; | ||
50 | fn main(v: (A, (), B)) { | ||
51 | match v { (A, ..) => {} } | ||
52 | match v { (.., B) => {} } | ||
53 | match v { (A, .., B) => {} } | ||
54 | match v { (..) => {} } | ||
55 | match v { } | ||
56 | //^ Missing match arm | ||
57 | } | ||
58 | "#, | ||
59 | ); | ||
60 | } | ||
61 | |||
62 | #[test] | ||
63 | fn strukt() { | ||
64 | check_diagnostics( | ||
65 | r#" | ||
66 | struct A; struct B; | ||
67 | struct S { a: A, b: B} | ||
68 | fn main(v: S) { | ||
69 | match v { S { a, b } => {} } | ||
70 | match v { S { a: _, b: _ } => {} } | ||
71 | match v { S { .. } => {} } | ||
72 | match v { _ => {} } | ||
73 | match v { } | ||
74 | //^ Missing match arm | ||
32 | } | 75 | } |
33 | "#, | 76 | "#, |
34 | ); | 77 | ); |