aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests/patterns.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests/patterns.rs')
-rw-r--r--crates/hir_ty/src/tests/patterns.rs104
1 files changed, 45 insertions, 59 deletions
diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs
index cd08b5c7a..aa513c56d 100644
--- a/crates/hir_ty/src/tests/patterns.rs
+++ b/crates/hir_ty/src/tests/patterns.rs
@@ -1,6 +1,6 @@
1use expect_test::expect; 1use expect_test::expect;
2 2
3use super::{check_infer, check_infer_with_mismatches, check_types}; 3use super::{check_infer, check_infer_with_mismatches, check_mismatches, check_types};
4 4
5#[test] 5#[test]
6fn infer_pattern() { 6fn infer_pattern() {
@@ -20,6 +20,8 @@ fn infer_pattern() {
20 let h = val; 20 let h = val;
21 } 21 }
22 22
23 if let x @ true = &true {}
24
23 let lambda = |a: u64, b, c: i32| { a + b; c }; 25 let lambda = |a: u64, b, c: i32| { a + b; c };
24 26
25 let ref ref_to_x = x; 27 let ref ref_to_x = x;
@@ -30,7 +32,7 @@ fn infer_pattern() {
30 "#, 32 "#,
31 expect![[r#" 33 expect![[r#"
32 8..9 'x': &i32 34 8..9 'x': &i32
33 17..368 '{ ...o_x; }': () 35 17..400 '{ ...o_x; }': ()
34 27..28 'y': &i32 36 27..28 'y': &i32
35 31..32 'x': &i32 37 31..32 'x': &i32
36 42..44 '&z': &i32 38 42..44 '&z': &i32
@@ -59,24 +61,31 @@ fn infer_pattern() {
59 176..204 '{ ... }': () 61 176..204 '{ ... }': ()
60 190..191 'h': {unknown} 62 190..191 'h': {unknown}
61 194..197 'val': {unknown} 63 194..197 'val': {unknown}
62 214..220 'lambda': |u64, u64, i32| -> i32 64 210..236 'if let...rue {}': ()
63 223..255 '|a: u6...b; c }': |u64, u64, i32| -> i32 65 217..225 'x @ true': &bool
64 224..225 'a': u64 66 221..225 'true': bool
65 232..233 'b': u64 67 221..225 'true': bool
66 235..236 'c': i32 68 228..233 '&true': &bool
67 243..255 '{ a + b; c }': i32 69 229..233 'true': bool
68 245..246 'a': u64 70 234..236 '{}': ()
69 245..250 'a + b': u64 71 246..252 'lambda': |u64, u64, i32| -> i32
70 249..250 'b': u64 72 255..287 '|a: u6...b; c }': |u64, u64, i32| -> i32
71 252..253 'c': i32 73 256..257 'a': u64
72 266..278 'ref ref_to_x': &&i32 74 264..265 'b': u64
73 281..282 'x': &i32 75 267..268 'c': i32
74 292..301 'mut mut_x': &i32 76 275..287 '{ a + b; c }': i32
75 304..305 'x': &i32 77 277..278 'a': u64
76 315..335 'ref mu...f_to_x': &mut &i32 78 277..282 'a + b': u64
77 338..339 'x': &i32 79 281..282 'b': u64
78 349..350 'k': &mut &i32 80 284..285 'c': i32
79 353..365 'mut_ref_to_x': &mut &i32 81 298..310 'ref ref_to_x': &&i32
82 313..314 'x': &i32
83 324..333 'mut mut_x': &i32
84 336..337 'x': &i32
85 347..367 'ref mu...f_to_x': &mut &i32
86 370..371 'x': &i32
87 381..382 'k': &mut &i32
88 385..397 'mut_ref_to_x': &mut &i32
80 "#]], 89 "#]],
81 ); 90 );
82} 91}
@@ -509,47 +518,24 @@ fn infer_generics_in_patterns() {
509 518
510#[test] 519#[test]
511fn infer_const_pattern() { 520fn infer_const_pattern() {
512 check_infer_with_mismatches( 521 check_mismatches(
513 r#" 522 r#"
514 enum Option<T> { None } 523enum Option<T> { None }
515 use Option::None; 524use Option::None;
516 struct Foo; 525struct Foo;
517 const Bar: usize = 1; 526const Bar: usize = 1;
518 527
519 fn test() { 528fn test() {
520 let a: Option<u32> = None; 529 let a: Option<u32> = None;
521 let b: Option<i64> = match a { 530 let b: Option<i64> = match a {
522 None => None, 531 None => None,
523 }; 532 };
524 let _: () = match () { Foo => Foo }; // Expected mismatch 533 let _: () = match () { Foo => () };
525 let _: () = match () { Bar => Bar }; // Expected mismatch 534 // ^^^ expected (), got Foo
526 } 535 let _: () = match () { Bar => () };
536 // ^^^ expected (), got usize
537}
527 "#, 538 "#,
528 expect![[r#"
529 73..74 '1': usize
530 87..309 '{ ...atch }': ()
531 97..98 'a': Option<u32>
532 114..118 'None': Option<u32>
533 128..129 'b': Option<i64>
534 145..182 'match ... }': Option<i64>
535 151..152 'a': Option<u32>
536 163..167 'None': Option<u32>
537 171..175 'None': Option<i64>
538 192..193 '_': ()
539 200..223 'match ... Foo }': Foo
540 206..208 '()': ()
541 211..214 'Foo': Foo
542 218..221 'Foo': Foo
543 254..255 '_': ()
544 262..285 'match ... Bar }': usize
545 268..270 '()': ()
546 273..276 'Bar': usize
547 280..283 'Bar': usize
548 200..223: expected (), got Foo
549 211..214: expected (), got Foo
550 262..285: expected (), got usize
551 273..276: expected (), got usize
552 "#]],
553 ); 539 );
554} 540}
555 541