diff options
author | Marcus Klaas de Vries <[email protected]> | 2019-01-16 16:47:59 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-19 12:37:25 +0000 |
commit | 9c2d83a4c809b0b11ca389bb454e197859e5116c (patch) | |
tree | 36fd28ab25e05276559d5a1086e63cb58aae8673 /crates/ra_hir/src/ty | |
parent | 3b0de53904e560f85ccfdc38e66e6d6c9e997b7a (diff) |
Add crude implementation of tuplestruct pattern inference
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 36 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/adt_pattern.txt | 12 |
2 files changed, 34 insertions, 14 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index ff2c8b0d4..75fe2cc6e 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -359,31 +359,39 @@ fn test(x: &str, y: isize) { | |||
359 | } | 359 | } |
360 | 360 | ||
361 | #[test] | 361 | #[test] |
362 | fn infer_pattern() { | 362 | fn infer_simple_pattern() { |
363 | check_inference( | 363 | check_inference( |
364 | r#" | 364 | r#" |
365 | enum E { | ||
366 | A { x: usize }, | ||
367 | B | ||
368 | } | ||
369 | |||
370 | fn test(x: &i32) { | 365 | fn test(x: &i32) { |
371 | let y = x; | 366 | let y = x; |
372 | let &z = x; | 367 | let &z = x; |
373 | let a = z; | 368 | let a = z; |
374 | let (c, d) = (1, "hello"); | 369 | let (c, d) = (1, "hello"); |
370 | } | ||
371 | "#, | ||
372 | "pattern.txt", | ||
373 | ); | ||
374 | } | ||
375 | |||
376 | #[test] | ||
377 | fn infer_adt_pattern() { | ||
378 | check_inference( | ||
379 | r#" | ||
380 | enum E { | ||
381 | A { x: usize }, | ||
382 | B | ||
383 | } | ||
384 | |||
385 | struct S(u32, E); | ||
375 | 386 | ||
387 | fn test() { | ||
376 | let e = E::A { x: 3 }; | 388 | let e = E::A { x: 3 }; |
377 | if let E::A { x: x } = e { | 389 | |
378 | x | 390 | let S(y, z) = foo; |
379 | }; | 391 | let E::A { x: new_var } = e; |
380 | match e { | ||
381 | E::A { x } => x, | ||
382 | E::B => 1, | ||
383 | }; | ||
384 | } | 392 | } |
385 | "#, | 393 | "#, |
386 | "pattern.txt", | 394 | "adt_pattern.txt", |
387 | ); | 395 | ); |
388 | } | 396 | } |
389 | 397 | ||
diff --git a/crates/ra_hir/src/ty/tests/data/adt_pattern.txt b/crates/ra_hir/src/ty/tests/data/adt_pattern.txt new file mode 100644 index 000000000..d23b865a0 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/adt_pattern.txt | |||
@@ -0,0 +1,12 @@ | |||
1 | [49; 192) '{ ... }; }': () | ||
2 | [59; 60) 'e': E | ||
3 | [63; 76) 'E::A { x: 3 }': E | ||
4 | [73; 74) '3': usize | ||
5 | [82; 124) 'if let... }': [unknown] | ||
6 | [105; 106) 'e': E | ||
7 | [107; 124) '{ ... }': [unknown] | ||
8 | [117; 118) 'x': [unknown] | ||
9 | [130; 189) 'match ... }': [unknown] | ||
10 | [136; 137) 'e': E | ||
11 | [162; 163) 'x': [unknown] | ||
12 | [181; 182) '1': i32 | ||