diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-21 20:47:50 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-21 20:47:50 +0000 |
commit | bb665a70627cbc2f4fb930fefb04899941b6afa6 (patch) | |
tree | e63b8aa30ec149dbff97d5dbf45fed998fdaf744 /crates/ra_hir/src/ty | |
parent | 5100aeac429919d1758908efb2f9cbe0d02c7510 (diff) | |
parent | db9a5a9ac047ed13aebd136edaabd4309f442e99 (diff) |
Merge #864
864: Fix handling of generics in tuple variants and refactor a bit r=matklad a=flodiebold
(The problem was that we created separate substitutions for the return value, so we lost the connection between the type arguments in the constructor call and the type arguments of the result.)
Also make them display a tiny bit nicer.
Fixes #860.
Co-authored-by: Florian Diebold <[email protected]>
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap | 23 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 21 |
3 files changed, 47 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap index 294186b06..32f1fa108 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap | |||
@@ -1,19 +1,19 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-02-17T16:16:58.863630956Z" | 2 | created: "2019-02-20T21:31:12.910924715Z" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | source: crates/ra_hir/src/ty/tests.rs | 4 | source: crates/ra_hir/src/ty/tests.rs |
5 | expression: "&result" | 5 | expression: "&result" |
6 | --- | 6 | --- |
7 | [72; 154) '{ ...a.c; }': () | 7 | [72; 154) '{ ...a.c; }': () |
8 | [82; 83) 'c': C | 8 | [82; 83) 'c': C |
9 | [86; 87) 'C': fn C(usize) -> C | 9 | [86; 87) 'C': C(usize) -> C |
10 | [86; 90) 'C(1)': C | 10 | [86; 90) 'C(1)': C |
11 | [88; 89) '1': usize | 11 | [88; 89) '1': usize |
12 | [96; 97) 'B': B | 12 | [96; 97) 'B': B |
13 | [107; 108) 'a': A | 13 | [107; 108) 'a': A |
14 | [114; 133) 'A { b:...C(1) }': A | 14 | [114; 133) 'A { b:...C(1) }': A |
15 | [121; 122) 'B': B | 15 | [121; 122) 'B': B |
16 | [127; 128) 'C': fn C(usize) -> C | 16 | [127; 128) 'C': C(usize) -> C |
17 | [127; 131) 'C(1)': C | 17 | [127; 131) 'C(1)': C |
18 | [129; 130) '1': usize | 18 | [129; 130) '1': usize |
19 | [139; 140) 'a': A | 19 | [139; 140) 'a': A |
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap new file mode 100644 index 000000000..783795cfd --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap | |||
@@ -0,0 +1,23 @@ | |||
1 | --- | ||
2 | created: "2019-02-20T21:31:12.911275141Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_hir/src/ty/tests.rs | ||
5 | expression: "&result" | ||
6 | --- | ||
7 | [77; 185) '{ ...one; }': () | ||
8 | [83; 84) 'A': A<i32>(T) -> A<T> | ||
9 | [83; 88) 'A(42)': A<i32> | ||
10 | [85; 87) '42': i32 | ||
11 | [94; 95) 'A': A<u128>(T) -> A<T> | ||
12 | [94; 103) 'A(42u128)': A<u128> | ||
13 | [96; 102) '42u128': u128 | ||
14 | [109; 113) 'Some': Some<&str>(T) -> Option<T> | ||
15 | [109; 118) 'Some("x")': Option<&str> | ||
16 | [114; 117) '"x"': &str | ||
17 | [124; 136) 'Option::Some': Some<&str>(T) -> Option<T> | ||
18 | [124; 141) 'Option...e("x")': Option<&str> | ||
19 | [137; 140) '"x"': &str | ||
20 | [147; 151) 'None': Option<[unknown]> | ||
21 | [161; 162) 'x': Option<i64> | ||
22 | [178; 182) 'None': Option<i64> | ||
23 | |||
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 4ab442b8a..3affcb4fe 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -466,6 +466,27 @@ fn test(a1: A<u32>, i: i32) { | |||
466 | } | 466 | } |
467 | 467 | ||
468 | #[test] | 468 | #[test] |
469 | fn infer_tuple_struct_generics() { | ||
470 | check_inference( | ||
471 | "infer_tuple_struct_generics", | ||
472 | r#" | ||
473 | struct A<T>(T); | ||
474 | enum Option<T> { Some(T), None }; | ||
475 | use Option::*; | ||
476 | |||
477 | fn test() { | ||
478 | A(42); | ||
479 | A(42u128); | ||
480 | Some("x"); | ||
481 | Option::Some("x"); | ||
482 | None; | ||
483 | let x: Option<i64> = None; | ||
484 | } | ||
485 | "#, | ||
486 | ); | ||
487 | } | ||
488 | |||
489 | #[test] | ||
469 | fn infer_generics_in_patterns() { | 490 | fn infer_generics_in_patterns() { |
470 | check_inference( | 491 | check_inference( |
471 | "infer_generics_in_patterns", | 492 | "infer_generics_in_patterns", |