diff options
author | uHOOCCOOHu <[email protected]> | 2019-09-25 22:56:55 +0100 |
---|---|---|
committer | uHOOCCOOHu <[email protected]> | 2019-09-25 23:16:58 +0100 |
commit | 29e56b8ee480828b81011cfa16c055fa0c9c89fe (patch) | |
tree | 45f901e9a92ffc8cf1d90a3fef1db45a70df632a /crates/ra_hir/src/ty/tests | |
parent | 5807e261c27e4964fc6a8d2b8cf02e548292b940 (diff) |
Support all coercion places
Diffstat (limited to 'crates/ra_hir/src/ty/tests')
-rw-r--r-- | crates/ra_hir/src/ty/tests/coercion.rs | 103 |
1 files changed, 97 insertions, 6 deletions
diff --git a/crates/ra_hir/src/ty/tests/coercion.rs b/crates/ra_hir/src/ty/tests/coercion.rs index d80d3fb6f..1530fcc63 100644 --- a/crates/ra_hir/src/ty/tests/coercion.rs +++ b/crates/ra_hir/src/ty/tests/coercion.rs | |||
@@ -20,6 +20,97 @@ fn infer(source: &str) -> String { | |||
20 | } | 20 | } |
21 | 21 | ||
22 | #[test] | 22 | #[test] |
23 | fn infer_block_expr_type_mismatch() { | ||
24 | assert_snapshot!( | ||
25 | infer(r#" | ||
26 | fn test() { | ||
27 | let a: i32 = { 1i64 }; | ||
28 | } | ||
29 | "#), | ||
30 | @r###" | ||
31 | [11; 41) '{ ...4 }; }': () | ||
32 | [21; 22) 'a': i32 | ||
33 | [30; 38) '{ 1i64 }': i64 | ||
34 | [32; 36) '1i64': i64 | ||
35 | "###); | ||
36 | } | ||
37 | |||
38 | #[test] | ||
39 | fn coerce_places() { | ||
40 | assert_snapshot!( | ||
41 | infer(r#" | ||
42 | struct S<T> { a: T } | ||
43 | |||
44 | fn f<T>(_: &[T]) -> T { loop {} } | ||
45 | fn g<T>(_: S<&[T]>) -> T { loop {} } | ||
46 | |||
47 | fn gen<T>() -> *mut [T; 2] { loop {} } | ||
48 | fn test1<U>() -> *mut [U] { | ||
49 | gen() | ||
50 | } | ||
51 | |||
52 | fn test2() { | ||
53 | let arr: &[u8; 1] = &[1]; | ||
54 | |||
55 | let a: &[_] = arr; | ||
56 | let b = f(arr); | ||
57 | let c: &[_] = { arr }; | ||
58 | let d = g(S { a: arr }); | ||
59 | let e: [&[_]; 1] = [arr]; | ||
60 | let f: [&[_]; 2] = [arr; 2]; | ||
61 | let g: (&[_], &[_]) = (arr, arr); | ||
62 | } | ||
63 | "#), | ||
64 | @r###" | ||
65 | [31; 32) '_': &[T] | ||
66 | [45; 56) '{ loop {} }': T | ||
67 | [47; 54) 'loop {}': ! | ||
68 | [52; 54) '{}': () | ||
69 | [65; 66) '_': S<&[T]> | ||
70 | [82; 93) '{ loop {} }': T | ||
71 | [84; 91) 'loop {}': ! | ||
72 | [89; 91) '{}': () | ||
73 | [122; 133) '{ loop {} }': *mut [T;_] | ||
74 | [124; 131) 'loop {}': ! | ||
75 | [129; 131) '{}': () | ||
76 | [160; 173) '{ gen() }': *mut [U] | ||
77 | [166; 169) 'gen': fn gen<U>() -> *mut [T;_] | ||
78 | [166; 171) 'gen()': *mut [U;_] | ||
79 | [186; 420) '{ ...rr); }': () | ||
80 | [196; 199) 'arr': &[u8;_] | ||
81 | [212; 216) '&[1]': &[u8;_] | ||
82 | [213; 216) '[1]': [u8;_] | ||
83 | [214; 215) '1': u8 | ||
84 | [227; 228) 'a': &[u8] | ||
85 | [237; 240) 'arr': &[u8;_] | ||
86 | [250; 251) 'b': u8 | ||
87 | [254; 255) 'f': fn f<u8>(&[T]) -> T | ||
88 | [254; 260) 'f(arr)': u8 | ||
89 | [256; 259) 'arr': &[u8;_] | ||
90 | [270; 271) 'c': &[u8] | ||
91 | [280; 287) '{ arr }': &[u8] | ||
92 | [282; 285) 'arr': &[u8;_] | ||
93 | [297; 298) 'd': u8 | ||
94 | [301; 302) 'g': fn g<u8>(S<&[T]>) -> T | ||
95 | [301; 316) 'g(S { a: arr })': u8 | ||
96 | [303; 315) 'S { a: arr }': S<&[u8]> | ||
97 | [310; 313) 'arr': &[u8;_] | ||
98 | [326; 327) 'e': [&[u8];_] | ||
99 | [341; 346) '[arr]': [&[u8];_] | ||
100 | [342; 345) 'arr': &[u8;_] | ||
101 | [356; 357) 'f': [&[u8];_] | ||
102 | [371; 379) '[arr; 2]': [&[u8];_] | ||
103 | [372; 375) 'arr': &[u8;_] | ||
104 | [377; 378) '2': usize | ||
105 | [389; 390) 'g': (&[u8], &[u8]) | ||
106 | [407; 417) '(arr, arr)': (&[u8], &[u8]) | ||
107 | [408; 411) 'arr': &[u8;_] | ||
108 | [413; 416) 'arr': &[u8;_] | ||
109 | "### | ||
110 | ); | ||
111 | } | ||
112 | |||
113 | #[test] | ||
23 | fn infer_let_stmt_coerce() { | 114 | fn infer_let_stmt_coerce() { |
24 | assert_snapshot!( | 115 | assert_snapshot!( |
25 | infer(r#" | 116 | infer(r#" |
@@ -102,7 +193,7 @@ fn test() { | |||
102 | "#), | 193 | "#), |
103 | @r###" | 194 | @r###" |
104 | [11; 12) 'x': &[T] | 195 | [11; 12) 'x': &[T] |
105 | [28; 39) '{ loop {} }': ! | 196 | [28; 39) '{ loop {} }': &[T] |
106 | [30; 37) 'loop {}': ! | 197 | [30; 37) 'loop {}': ! |
107 | [35; 37) '{}': () | 198 | [35; 37) '{}': () |
108 | [50; 126) '{ ... }; }': () | 199 | [50; 126) '{ ... }; }': () |
@@ -119,7 +210,7 @@ fn test() { | |||
119 | [113; 117) '&[1]': &[i32;_] | 210 | [113; 117) '&[1]': &[i32;_] |
120 | [114; 117) '[1]': [i32;_] | 211 | [114; 117) '[1]': [i32;_] |
121 | [115; 116) '1': i32 | 212 | [115; 116) '1': i32 |
122 | "### | 213 | "### |
123 | ); | 214 | ); |
124 | } | 215 | } |
125 | 216 | ||
@@ -138,7 +229,7 @@ fn test() { | |||
138 | "#), | 229 | "#), |
139 | @r###" | 230 | @r###" |
140 | [11; 12) 'x': &[T] | 231 | [11; 12) 'x': &[T] |
141 | [28; 39) '{ loop {} }': ! | 232 | [28; 39) '{ loop {} }': &[T] |
142 | [30; 37) 'loop {}': ! | 233 | [30; 37) 'loop {}': ! |
143 | [35; 37) '{}': () | 234 | [35; 37) '{}': () |
144 | [50; 126) '{ ... }; }': () | 235 | [50; 126) '{ ... }; }': () |
@@ -155,7 +246,7 @@ fn test() { | |||
155 | [112; 116) '&[1]': &[i32;_] | 246 | [112; 116) '&[1]': &[i32;_] |
156 | [113; 116) '[1]': [i32;_] | 247 | [113; 116) '[1]': [i32;_] |
157 | [114; 115) '1': i32 | 248 | [114; 115) '1': i32 |
158 | "### | 249 | "### |
159 | ); | 250 | ); |
160 | } | 251 | } |
161 | 252 | ||
@@ -174,7 +265,7 @@ fn test(i: i32) { | |||
174 | "#), | 265 | "#), |
175 | @r###" | 266 | @r###" |
176 | [11; 12) 'x': &[T] | 267 | [11; 12) 'x': &[T] |
177 | [28; 39) '{ loop {} }': ! | 268 | [28; 39) '{ loop {} }': &[T] |
178 | [30; 37) 'loop {}': ! | 269 | [30; 37) 'loop {}': ! |
179 | [35; 37) '{}': () | 270 | [35; 37) '{}': () |
180 | [48; 49) 'i': i32 | 271 | [48; 49) 'i': i32 |
@@ -215,7 +306,7 @@ fn test(i: i32) { | |||
215 | "#), | 306 | "#), |
216 | @r###" | 307 | @r###" |
217 | [11; 12) 'x': &[T] | 308 | [11; 12) 'x': &[T] |
218 | [28; 39) '{ loop {} }': ! | 309 | [28; 39) '{ loop {} }': &[T] |
219 | [30; 37) 'loop {}': ! | 310 | [30; 37) 'loop {}': ! |
220 | [35; 37) '{}': () | 311 | [35; 37) '{}': () |
221 | [48; 49) 'i': i32 | 312 | [48; 49) 'i': i32 |