diff options
author | Florian Diebold <[email protected]> | 2019-12-03 12:38:54 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-12-03 17:00:29 +0000 |
commit | 9747156f6c5c9b5cccc347a68042e6d9a6b0f704 (patch) | |
tree | 2c4807d138af0c2f9acc054f7bbcee93faefb628 /crates/ra_hir_ty/src/tests/regression.rs | |
parent | 96b9d5b44ed50160c7a4eb07a31bee5f05b1ecf3 (diff) |
Split up ty tests a bit
Diffstat (limited to 'crates/ra_hir_ty/src/tests/regression.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/regression.rs | 333 |
1 files changed, 333 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs new file mode 100644 index 000000000..09d684ac2 --- /dev/null +++ b/crates/ra_hir_ty/src/tests/regression.rs | |||
@@ -0,0 +1,333 @@ | |||
1 | use super::infer; | ||
2 | use insta::assert_snapshot; | ||
3 | use test_utils::covers; | ||
4 | |||
5 | #[test] | ||
6 | fn bug_484() { | ||
7 | assert_snapshot!( | ||
8 | infer(r#" | ||
9 | fn test() { | ||
10 | let x = if true {}; | ||
11 | } | ||
12 | "#), | ||
13 | @r###" | ||
14 | [11; 37) '{ l... {}; }': () | ||
15 | [20; 21) 'x': () | ||
16 | [24; 34) 'if true {}': () | ||
17 | [27; 31) 'true': bool | ||
18 | [32; 34) '{}': () | ||
19 | "### | ||
20 | ); | ||
21 | } | ||
22 | |||
23 | #[test] | ||
24 | fn no_panic_on_field_of_enum() { | ||
25 | assert_snapshot!( | ||
26 | infer(r#" | ||
27 | enum X {} | ||
28 | |||
29 | fn test(x: X) { | ||
30 | x.some_field; | ||
31 | } | ||
32 | "#), | ||
33 | @r###" | ||
34 | [20; 21) 'x': X | ||
35 | [26; 47) '{ ...eld; }': () | ||
36 | [32; 33) 'x': X | ||
37 | [32; 44) 'x.some_field': {unknown} | ||
38 | "### | ||
39 | ); | ||
40 | } | ||
41 | |||
42 | #[test] | ||
43 | fn bug_585() { | ||
44 | assert_snapshot!( | ||
45 | infer(r#" | ||
46 | fn test() { | ||
47 | X {}; | ||
48 | match x { | ||
49 | A::B {} => (), | ||
50 | A::Y() => (), | ||
51 | } | ||
52 | } | ||
53 | "#), | ||
54 | @r###" | ||
55 | [11; 89) '{ ... } }': () | ||
56 | [17; 21) 'X {}': {unknown} | ||
57 | [27; 87) 'match ... }': () | ||
58 | [33; 34) 'x': {unknown} | ||
59 | [45; 52) 'A::B {}': {unknown} | ||
60 | [56; 58) '()': () | ||
61 | [68; 74) 'A::Y()': {unknown} | ||
62 | [78; 80) '()': () | ||
63 | "### | ||
64 | ); | ||
65 | } | ||
66 | |||
67 | #[test] | ||
68 | fn bug_651() { | ||
69 | assert_snapshot!( | ||
70 | infer(r#" | ||
71 | fn quux() { | ||
72 | let y = 92; | ||
73 | 1 + y; | ||
74 | } | ||
75 | "#), | ||
76 | @r###" | ||
77 | [11; 41) '{ ...+ y; }': () | ||
78 | [21; 22) 'y': i32 | ||
79 | [25; 27) '92': i32 | ||
80 | [33; 34) '1': i32 | ||
81 | [33; 38) '1 + y': i32 | ||
82 | [37; 38) 'y': i32 | ||
83 | "### | ||
84 | ); | ||
85 | } | ||
86 | |||
87 | #[test] | ||
88 | fn recursive_vars() { | ||
89 | covers!(type_var_cycles_resolve_completely); | ||
90 | covers!(type_var_cycles_resolve_as_possible); | ||
91 | assert_snapshot!( | ||
92 | infer(r#" | ||
93 | fn test() { | ||
94 | let y = unknown; | ||
95 | [y, &y]; | ||
96 | } | ||
97 | "#), | ||
98 | @r###" | ||
99 | [11; 48) '{ ...&y]; }': () | ||
100 | [21; 22) 'y': &{unknown} | ||
101 | [25; 32) 'unknown': &{unknown} | ||
102 | [38; 45) '[y, &y]': [&&{unknown};_] | ||
103 | [39; 40) 'y': &{unknown} | ||
104 | [42; 44) '&y': &&{unknown} | ||
105 | [43; 44) 'y': &{unknown} | ||
106 | "### | ||
107 | ); | ||
108 | } | ||
109 | |||
110 | #[test] | ||
111 | fn recursive_vars_2() { | ||
112 | covers!(type_var_cycles_resolve_completely); | ||
113 | covers!(type_var_cycles_resolve_as_possible); | ||
114 | assert_snapshot!( | ||
115 | infer(r#" | ||
116 | fn test() { | ||
117 | let x = unknown; | ||
118 | let y = unknown; | ||
119 | [(x, y), (&y, &x)]; | ||
120 | } | ||
121 | "#), | ||
122 | @r###" | ||
123 | [11; 80) '{ ...x)]; }': () | ||
124 | [21; 22) 'x': &&{unknown} | ||
125 | [25; 32) 'unknown': &&{unknown} | ||
126 | [42; 43) 'y': &&{unknown} | ||
127 | [46; 53) 'unknown': &&{unknown} | ||
128 | [59; 77) '[(x, y..., &x)]': [(&&&{unknown}, &&&{unknown});_] | ||
129 | [60; 66) '(x, y)': (&&&{unknown}, &&&{unknown}) | ||
130 | [61; 62) 'x': &&{unknown} | ||
131 | [64; 65) 'y': &&{unknown} | ||
132 | [68; 76) '(&y, &x)': (&&&{unknown}, &&&{unknown}) | ||
133 | [69; 71) '&y': &&&{unknown} | ||
134 | [70; 71) 'y': &&{unknown} | ||
135 | [73; 75) '&x': &&&{unknown} | ||
136 | [74; 75) 'x': &&{unknown} | ||
137 | "### | ||
138 | ); | ||
139 | } | ||
140 | |||
141 | #[test] | ||
142 | fn infer_std_crash_1() { | ||
143 | // caused stack overflow, taken from std | ||
144 | assert_snapshot!( | ||
145 | infer(r#" | ||
146 | enum Maybe<T> { | ||
147 | Real(T), | ||
148 | Fake, | ||
149 | } | ||
150 | |||
151 | fn write() { | ||
152 | match something_unknown { | ||
153 | Maybe::Real(ref mut something) => (), | ||
154 | } | ||
155 | } | ||
156 | "#), | ||
157 | @r###" | ||
158 | [54; 139) '{ ... } }': () | ||
159 | [60; 137) 'match ... }': () | ||
160 | [66; 83) 'someth...nknown': Maybe<{unknown}> | ||
161 | [94; 124) 'Maybe:...thing)': Maybe<{unknown}> | ||
162 | [106; 123) 'ref mu...ething': &mut {unknown} | ||
163 | [128; 130) '()': () | ||
164 | "### | ||
165 | ); | ||
166 | } | ||
167 | |||
168 | #[test] | ||
169 | fn infer_std_crash_2() { | ||
170 | covers!(type_var_resolves_to_int_var); | ||
171 | // caused "equating two type variables, ...", taken from std | ||
172 | assert_snapshot!( | ||
173 | infer(r#" | ||
174 | fn test_line_buffer() { | ||
175 | &[0, b'\n', 1, b'\n']; | ||
176 | } | ||
177 | "#), | ||
178 | @r###" | ||
179 | [23; 53) '{ ...n']; }': () | ||
180 | [29; 50) '&[0, b...b'\n']': &[u8;_] | ||
181 | [30; 50) '[0, b'...b'\n']': [u8;_] | ||
182 | [31; 32) '0': u8 | ||
183 | [34; 39) 'b'\n'': u8 | ||
184 | [41; 42) '1': u8 | ||
185 | [44; 49) 'b'\n'': u8 | ||
186 | "### | ||
187 | ); | ||
188 | } | ||
189 | |||
190 | #[test] | ||
191 | fn infer_std_crash_3() { | ||
192 | // taken from rustc | ||
193 | assert_snapshot!( | ||
194 | infer(r#" | ||
195 | pub fn compute() { | ||
196 | match nope!() { | ||
197 | SizeSkeleton::Pointer { non_zero: true, tail } => {} | ||
198 | } | ||
199 | } | ||
200 | "#), | ||
201 | @r###" | ||
202 | [18; 108) '{ ... } }': () | ||
203 | [24; 106) 'match ... }': () | ||
204 | [30; 37) 'nope!()': {unknown} | ||
205 | [48; 94) 'SizeSk...tail }': {unknown} | ||
206 | [82; 86) 'true': {unknown} | ||
207 | [88; 92) 'tail': {unknown} | ||
208 | [98; 100) '{}': () | ||
209 | "### | ||
210 | ); | ||
211 | } | ||
212 | |||
213 | #[test] | ||
214 | fn infer_std_crash_4() { | ||
215 | // taken from rustc | ||
216 | assert_snapshot!( | ||
217 | infer(r#" | ||
218 | pub fn primitive_type() { | ||
219 | match *self { | ||
220 | BorrowedRef { type_: Primitive(p), ..} => {}, | ||
221 | } | ||
222 | } | ||
223 | "#), | ||
224 | @r###" | ||
225 | [25; 106) '{ ... } }': () | ||
226 | [31; 104) 'match ... }': () | ||
227 | [37; 42) '*self': {unknown} | ||
228 | [38; 42) 'self': {unknown} | ||
229 | [53; 91) 'Borrow...), ..}': {unknown} | ||
230 | [74; 86) 'Primitive(p)': {unknown} | ||
231 | [84; 85) 'p': {unknown} | ||
232 | [95; 97) '{}': () | ||
233 | "### | ||
234 | ); | ||
235 | } | ||
236 | |||
237 | #[test] | ||
238 | fn infer_std_crash_5() { | ||
239 | // taken from rustc | ||
240 | assert_snapshot!( | ||
241 | infer(r#" | ||
242 | fn extra_compiler_flags() { | ||
243 | for content in doesnt_matter { | ||
244 | let name = if doesnt_matter { | ||
245 | first | ||
246 | } else { | ||
247 | &content | ||
248 | }; | ||
249 | |||
250 | let content = if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&name) { | ||
251 | name | ||
252 | } else { | ||
253 | content | ||
254 | }; | ||
255 | } | ||
256 | } | ||
257 | "#), | ||
258 | @r###" | ||
259 | [27; 323) '{ ... } }': () | ||
260 | [33; 321) 'for co... }': () | ||
261 | [37; 44) 'content': &{unknown} | ||
262 | [48; 61) 'doesnt_matter': {unknown} | ||
263 | [62; 321) '{ ... }': () | ||
264 | [76; 80) 'name': &&{unknown} | ||
265 | [83; 167) 'if doe... }': &&{unknown} | ||
266 | [86; 99) 'doesnt_matter': bool | ||
267 | [100; 129) '{ ... }': &&{unknown} | ||
268 | [114; 119) 'first': &&{unknown} | ||
269 | [135; 167) '{ ... }': &&{unknown} | ||
270 | [149; 157) '&content': &&{unknown} | ||
271 | [150; 157) 'content': &{unknown} | ||
272 | [182; 189) 'content': &{unknown} | ||
273 | [192; 314) 'if ICE... }': &{unknown} | ||
274 | [195; 232) 'ICE_RE..._VALUE': {unknown} | ||
275 | [195; 248) 'ICE_RE...&name)': bool | ||
276 | [242; 247) '&name': &&&{unknown} | ||
277 | [243; 247) 'name': &&{unknown} | ||
278 | [249; 277) '{ ... }': &&{unknown} | ||
279 | [263; 267) 'name': &&{unknown} | ||
280 | [283; 314) '{ ... }': &{unknown} | ||
281 | [297; 304) 'content': &{unknown} | ||
282 | "### | ||
283 | ); | ||
284 | } | ||
285 | |||
286 | #[test] | ||
287 | fn infer_nested_generics_crash() { | ||
288 | // another crash found typechecking rustc | ||
289 | assert_snapshot!( | ||
290 | infer(r#" | ||
291 | struct Canonical<V> { | ||
292 | value: V, | ||
293 | } | ||
294 | struct QueryResponse<V> { | ||
295 | value: V, | ||
296 | } | ||
297 | fn test<R>(query_response: Canonical<QueryResponse<R>>) { | ||
298 | &query_response.value; | ||
299 | } | ||
300 | "#), | ||
301 | @r###" | ||
302 | [92; 106) 'query_response': Canonical<QueryResponse<R>> | ||
303 | [137; 167) '{ ...lue; }': () | ||
304 | [143; 164) '&query....value': &QueryResponse<R> | ||
305 | [144; 158) 'query_response': Canonical<QueryResponse<R>> | ||
306 | [144; 164) 'query_....value': QueryResponse<R> | ||
307 | "### | ||
308 | ); | ||
309 | } | ||
310 | |||
311 | #[test] | ||
312 | fn bug_1030() { | ||
313 | assert_snapshot!(infer(r#" | ||
314 | struct HashSet<T, H>; | ||
315 | struct FxHasher; | ||
316 | type FxHashSet<T> = HashSet<T, FxHasher>; | ||
317 | |||
318 | impl<T, H> HashSet<T, H> { | ||
319 | fn default() -> HashSet<T, H> {} | ||
320 | } | ||
321 | |||
322 | pub fn main_loop() { | ||
323 | FxHashSet::default(); | ||
324 | } | ||
325 | "#), | ||
326 | @r###" | ||
327 | [144; 146) '{}': () | ||
328 | [169; 198) '{ ...t(); }': () | ||
329 | [175; 193) 'FxHash...efault': fn default<{unknown}, FxHasher>() -> HashSet<T, H> | ||
330 | [175; 195) 'FxHash...ault()': HashSet<{unknown}, FxHasher> | ||
331 | "### | ||
332 | ); | ||
333 | } | ||