aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/regression.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-21 11:36:04 +0100
committerGitHub <[email protected]>2020-07-21 11:36:04 +0100
commit9307c7f36396c4429bea434608cb5643135ae49d (patch)
treedae0469fcd4a29b480dd2332b58f9941c96a59a5 /crates/ra_hir_ty/src/tests/regression.rs
parent9518e2f9d69dbb4a9ddd4a8bab87cf16a41fca03 (diff)
parentdaab8b2fd03340ea0be91281673c256b02ad8a90 (diff)
Merge #5472
5472: Replace insta with expect r=matklad a=lnicola Co-authored-by: LaurenČ›iu Nicola <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests/regression.rs')
-rw-r--r--crates/ra_hir_ty/src/tests/regression.rs1172
1 files changed, 588 insertions, 584 deletions
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs
index 4367621fc..b9ab0f357 100644
--- a/crates/ra_hir_ty/src/tests/regression.rs
+++ b/crates/ra_hir_ty/src/tests/regression.rs
@@ -1,87 +1,87 @@
1use insta::assert_snapshot; 1use expect::expect;
2use test_utils::mark; 2use test_utils::mark;
3 3
4use super::{check_types, infer}; 4use super::{check_infer, check_types};
5 5
6#[test] 6#[test]
7fn bug_484() { 7fn bug_484() {
8 assert_snapshot!( 8 check_infer(
9 infer(r#" 9 r#"
10fn test() { 10 fn test() {
11 let x = if true {}; 11 let x = if true {};
12} 12 }
13"#), 13 "#,
14 @r###" 14 expect![[r#"
15 10..36 '{ l... {}; }': () 15 10..37 '{ ... {}; }': ()
16 19..20 'x': () 16 20..21 'x': ()
17 23..33 'if true {}': () 17 24..34 'if true {}': ()
18 26..30 'true': bool 18 27..31 'true': bool
19 31..33 '{}': () 19 32..34 '{}': ()
20 "### 20 "#]],
21 ); 21 );
22} 22}
23 23
24#[test] 24#[test]
25fn no_panic_on_field_of_enum() { 25fn no_panic_on_field_of_enum() {
26 assert_snapshot!( 26 check_infer(
27 infer(r#" 27 r#"
28enum X {} 28 enum X {}
29 29
30fn test(x: X) { 30 fn test(x: X) {
31 x.some_field; 31 x.some_field;
32} 32 }
33"#), 33 "#,
34 @r###" 34 expect![[r#"
35 19..20 'x': X 35 19..20 'x': X
36 25..46 '{ ...eld; }': () 36 25..46 '{ ...eld; }': ()
37 31..32 'x': X 37 31..32 'x': X
38 31..43 'x.some_field': {unknown} 38 31..43 'x.some_field': {unknown}
39 "### 39 "#]],
40 ); 40 );
41} 41}
42 42
43#[test] 43#[test]
44fn bug_585() { 44fn bug_585() {
45 assert_snapshot!( 45 check_infer(
46 infer(r#" 46 r#"
47fn test() { 47 fn test() {
48 X {}; 48 X {};
49 match x { 49 match x {
50 A::B {} => (), 50 A::B {} => (),
51 A::Y() => (), 51 A::Y() => (),
52 } 52 }
53} 53 }
54"#), 54 "#,
55 @r###" 55 expect![[r#"
56 10..88 '{ ... } }': () 56 10..88 '{ ... } }': ()
57 16..20 'X {}': {unknown} 57 16..20 'X {}': {unknown}
58 26..86 'match ... }': () 58 26..86 'match ... }': ()
59 32..33 'x': {unknown} 59 32..33 'x': {unknown}
60 44..51 'A::B {}': {unknown} 60 44..51 'A::B {}': {unknown}
61 55..57 '()': () 61 55..57 '()': ()
62 67..73 'A::Y()': {unknown} 62 67..73 'A::Y()': {unknown}
63 77..79 '()': () 63 77..79 '()': ()
64 "### 64 "#]],
65 ); 65 );
66} 66}
67 67
68#[test] 68#[test]
69fn bug_651() { 69fn bug_651() {
70 assert_snapshot!( 70 check_infer(
71 infer(r#" 71 r#"
72fn quux() { 72 fn quux() {
73 let y = 92; 73 let y = 92;
74 1 + y; 74 1 + y;
75} 75 }
76"#), 76 "#,
77 @r###" 77 expect![[r#"
78 10..40 '{ ...+ y; }': () 78 10..40 '{ ...+ y; }': ()
79 20..21 'y': i32 79 20..21 'y': i32
80 24..26 '92': i32 80 24..26 '92': i32
81 32..33 '1': i32 81 32..33 '1': i32
82 32..37 '1 + y': i32 82 32..37 '1 + y': i32
83 36..37 'y': i32 83 36..37 'y': i32
84 "### 84 "#]],
85 ); 85 );
86} 86}
87 87
@@ -89,78 +89,78 @@ fn quux() {
89fn recursive_vars() { 89fn recursive_vars() {
90 mark::check!(type_var_cycles_resolve_completely); 90 mark::check!(type_var_cycles_resolve_completely);
91 mark::check!(type_var_cycles_resolve_as_possible); 91 mark::check!(type_var_cycles_resolve_as_possible);
92 assert_snapshot!( 92 check_infer(
93 infer(r#" 93 r#"
94fn test() { 94 fn test() {
95 let y = unknown; 95 let y = unknown;
96 [y, &y]; 96 [y, &y];
97} 97 }
98"#), 98 "#,
99 @r###" 99 expect![[r#"
100 10..47 '{ ...&y]; }': () 100 10..47 '{ ...&y]; }': ()
101 20..21 'y': &{unknown} 101 20..21 'y': &{unknown}
102 24..31 'unknown': &{unknown} 102 24..31 'unknown': &{unknown}
103 37..44 '[y, &y]': [&&{unknown}; _] 103 37..44 '[y, &y]': [&&{unknown}; _]
104 38..39 'y': &{unknown} 104 38..39 'y': &{unknown}
105 41..43 '&y': &&{unknown} 105 41..43 '&y': &&{unknown}
106 42..43 'y': &{unknown} 106 42..43 'y': &{unknown}
107 "### 107 "#]],
108 ); 108 );
109} 109}
110 110
111#[test] 111#[test]
112fn recursive_vars_2() { 112fn recursive_vars_2() {
113 assert_snapshot!( 113 check_infer(
114 infer(r#" 114 r#"
115fn test() { 115 fn test() {
116 let x = unknown; 116 let x = unknown;
117 let y = unknown; 117 let y = unknown;
118 [(x, y), (&y, &x)]; 118 [(x, y), (&y, &x)];
119} 119 }
120"#), 120 "#,
121 @r###" 121 expect![[r#"
122 10..79 '{ ...x)]; }': () 122 10..79 '{ ...x)]; }': ()
123 20..21 'x': &&{unknown} 123 20..21 'x': &&{unknown}
124 24..31 'unknown': &&{unknown} 124 24..31 'unknown': &&{unknown}
125 41..42 'y': &&{unknown} 125 41..42 'y': &&{unknown}
126 45..52 'unknown': &&{unknown} 126 45..52 'unknown': &&{unknown}
127 58..76 '[(x, y..., &x)]': [(&&&{unknown}, &&&{unknown}); _] 127 58..76 '[(x, y..., &x)]': [(&&&{unknown}, &&&{unknown}); _]
128 59..65 '(x, y)': (&&&{unknown}, &&&{unknown}) 128 59..65 '(x, y)': (&&&{unknown}, &&&{unknown})
129 60..61 'x': &&{unknown} 129 60..61 'x': &&{unknown}
130 63..64 'y': &&{unknown} 130 63..64 'y': &&{unknown}
131 67..75 '(&y, &x)': (&&&{unknown}, &&&{unknown}) 131 67..75 '(&y, &x)': (&&&{unknown}, &&&{unknown})
132 68..70 '&y': &&&{unknown} 132 68..70 '&y': &&&{unknown}
133 69..70 'y': &&{unknown} 133 69..70 'y': &&{unknown}
134 72..74 '&x': &&&{unknown} 134 72..74 '&x': &&&{unknown}
135 73..74 'x': &&{unknown} 135 73..74 'x': &&{unknown}
136 "### 136 "#]],
137 ); 137 );
138} 138}
139 139
140#[test] 140#[test]
141fn infer_std_crash_1() { 141fn infer_std_crash_1() {
142 // caused stack overflow, taken from std 142 // caused stack overflow, taken from std
143 assert_snapshot!( 143 check_infer(
144 infer(r#" 144 r#"
145enum Maybe<T> { 145 enum Maybe<T> {
146 Real(T), 146 Real(T),
147 Fake, 147 Fake,
148} 148 }
149 149
150fn write() { 150 fn write() {
151 match something_unknown { 151 match something_unknown {
152 Maybe::Real(ref mut something) => (), 152 Maybe::Real(ref mut something) => (),
153 } 153 }
154} 154 }
155"#), 155 "#,
156 @r###" 156 expect![[r#"
157 53..138 '{ ... } }': () 157 53..138 '{ ... } }': ()
158 59..136 'match ... }': () 158 59..136 'match ... }': ()
159 65..82 'someth...nknown': Maybe<{unknown}> 159 65..82 'someth...nknown': Maybe<{unknown}>
160 93..123 'Maybe:...thing)': Maybe<{unknown}> 160 93..123 'Maybe:...thing)': Maybe<{unknown}>
161 105..122 'ref mu...ething': &mut {unknown} 161 105..122 'ref mu...ething': &mut {unknown}
162 127..129 '()': () 162 127..129 '()': ()
163 "### 163 "#]],
164 ); 164 );
165} 165}
166 166
@@ -168,234 +168,235 @@ fn write() {
168fn infer_std_crash_2() { 168fn infer_std_crash_2() {
169 mark::check!(type_var_resolves_to_int_var); 169 mark::check!(type_var_resolves_to_int_var);
170 // caused "equating two type variables, ...", taken from std 170 // caused "equating two type variables, ...", taken from std
171 assert_snapshot!( 171 check_infer(
172 infer(r#" 172 r#"
173fn test_line_buffer() { 173 fn test_line_buffer() {
174 &[0, b'\n', 1, b'\n']; 174 &[0, b'\n', 1, b'\n'];
175} 175 }
176"#), 176 "#,
177 @r###" 177 expect![[r#"
178 22..52 '{ ...n']; }': () 178 22..52 '{ ...n']; }': ()
179 28..49 '&[0, b...b'\n']': &[u8; _] 179 28..49 '&[0, b...b'\n']': &[u8; _]
180 29..49 '[0, b'...b'\n']': [u8; _] 180 29..49 '[0, b'...b'\n']': [u8; _]
181 30..31 '0': u8 181 30..31 '0': u8
182 33..38 'b'\n'': u8 182 33..38 'b'\n'': u8
183 40..41 '1': u8 183 40..41 '1': u8
184 43..48 'b'\n'': u8 184 43..48 'b'\n'': u8
185 "### 185 "#]],
186 ); 186 );
187} 187}
188 188
189#[test] 189#[test]
190fn infer_std_crash_3() { 190fn infer_std_crash_3() {
191 // taken from rustc 191 // taken from rustc
192 assert_snapshot!( 192 check_infer(
193 infer(r#" 193 r#"
194pub fn compute() { 194 pub fn compute() {
195 match nope!() { 195 match nope!() {
196 SizeSkeleton::Pointer { non_zero: true, tail } => {} 196 SizeSkeleton::Pointer { non_zero: true, tail } => {}
197 } 197 }
198} 198 }
199"#), 199 "#,
200 @r###" 200 expect![[r#"
201 17..107 '{ ... } }': () 201 17..107 '{ ... } }': ()
202 23..105 'match ... }': () 202 23..105 'match ... }': ()
203 29..36 'nope!()': {unknown} 203 29..36 'nope!()': {unknown}
204 47..93 'SizeSk...tail }': {unknown} 204 47..93 'SizeSk...tail }': {unknown}
205 81..85 'true': bool 205 81..85 'true': bool
206 81..85 'true': bool 206 81..85 'true': bool
207 87..91 'tail': {unknown} 207 87..91 'tail': {unknown}
208 97..99 '{}': () 208 97..99 '{}': ()
209 "### 209 "#]],
210 ); 210 );
211} 211}
212 212
213#[test] 213#[test]
214fn infer_std_crash_4() { 214fn infer_std_crash_4() {
215 // taken from rustc 215 // taken from rustc
216 assert_snapshot!( 216 check_infer(
217 infer(r#" 217 r#"
218pub fn primitive_type() { 218 pub fn primitive_type() {
219 match *self { 219 match *self {
220 BorrowedRef { type_: Primitive(p), ..} => {}, 220 BorrowedRef { type_: Primitive(p), ..} => {},
221 } 221 }
222} 222 }
223"#), 223 "#,
224 @r###" 224 expect![[r#"
225 24..105 '{ ... } }': () 225 24..105 '{ ... } }': ()
226 30..103 'match ... }': () 226 30..103 'match ... }': ()
227 36..41 '*self': {unknown} 227 36..41 '*self': {unknown}
228 37..41 'self': {unknown} 228 37..41 'self': {unknown}
229 52..90 'Borrow...), ..}': {unknown} 229 52..90 'Borrow...), ..}': {unknown}
230 73..85 'Primitive(p)': {unknown} 230 73..85 'Primitive(p)': {unknown}
231 83..84 'p': {unknown} 231 83..84 'p': {unknown}
232 94..96 '{}': () 232 94..96 '{}': ()
233 "### 233 "#]],
234 ); 234 );
235} 235}
236 236
237#[test] 237#[test]
238fn infer_std_crash_5() { 238fn infer_std_crash_5() {
239 // taken from rustc 239 // taken from rustc
240 assert_snapshot!( 240 check_infer(
241 infer(r#" 241 r#"
242fn extra_compiler_flags() { 242 fn extra_compiler_flags() {
243 for content in doesnt_matter { 243 for content in doesnt_matter {
244 let name = if doesnt_matter { 244 let name = if doesnt_matter {
245 first 245 first
246 } else { 246 } else {
247 &content 247 &content
248 }; 248 };
249 249
250 let content = if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&name) { 250 let content = if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&name) {
251 name 251 name
252 } else { 252 } else {
253 content 253 content
254 }; 254 };
255 } 255 }
256} 256 }
257"#), 257 "#,
258 @r###" 258 expect![[r#"
259 26..322 '{ ... } }': () 259 26..322 '{ ... } }': ()
260 32..320 'for co... }': () 260 32..320 'for co... }': ()
261 36..43 'content': &{unknown} 261 36..43 'content': &{unknown}
262 47..60 'doesnt_matter': {unknown} 262 47..60 'doesnt_matter': {unknown}
263 61..320 '{ ... }': () 263 61..320 '{ ... }': ()
264 75..79 'name': &&{unknown} 264 75..79 'name': &&{unknown}
265 82..166 'if doe... }': &&{unknown} 265 82..166 'if doe... }': &&{unknown}
266 85..98 'doesnt_matter': bool 266 85..98 'doesnt_matter': bool
267 99..128 '{ ... }': &&{unknown} 267 99..128 '{ ... }': &&{unknown}
268 113..118 'first': &&{unknown} 268 113..118 'first': &&{unknown}
269 134..166 '{ ... }': &&{unknown} 269 134..166 '{ ... }': &&{unknown}
270 148..156 '&content': &&{unknown} 270 148..156 '&content': &&{unknown}
271 149..156 'content': &{unknown} 271 149..156 'content': &{unknown}
272 181..188 'content': &{unknown} 272 181..188 'content': &{unknown}
273 191..313 'if ICE... }': &{unknown} 273 191..313 'if ICE... }': &{unknown}
274 194..231 'ICE_RE..._VALUE': {unknown} 274 194..231 'ICE_RE..._VALUE': {unknown}
275 194..247 'ICE_RE...&name)': bool 275 194..247 'ICE_RE...&name)': bool
276 241..246 '&name': &&&{unknown} 276 241..246 '&name': &&&{unknown}
277 242..246 'name': &&{unknown} 277 242..246 'name': &&{unknown}
278 248..276 '{ ... }': &&{unknown} 278 248..276 '{ ... }': &&{unknown}
279 262..266 'name': &&{unknown} 279 262..266 'name': &&{unknown}
280 282..313 '{ ... }': &{unknown} 280 282..313 '{ ... }': &{unknown}
281 296..303 'content': &{unknown} 281 296..303 'content': &{unknown}
282 "### 282 "#]],
283 ); 283 );
284} 284}
285 285
286#[test] 286#[test]
287fn infer_nested_generics_crash() { 287fn infer_nested_generics_crash() {
288 // another crash found typechecking rustc 288 // another crash found typechecking rustc
289 assert_snapshot!( 289 check_infer(
290 infer(r#" 290 r#"
291struct Canonical<V> { 291 struct Canonical<V> {
292 value: V, 292 value: V,
293} 293 }
294struct QueryResponse<V> { 294 struct QueryResponse<V> {
295 value: V, 295 value: V,
296} 296 }
297fn test<R>(query_response: Canonical<QueryResponse<R>>) { 297 fn test<R>(query_response: Canonical<QueryResponse<R>>) {
298 &query_response.value; 298 &query_response.value;
299} 299 }
300"#), 300 "#,
301 @r###" 301 expect![[r#"
302 91..105 'query_response': Canonical<QueryResponse<R>> 302 91..105 'query_response': Canonical<QueryResponse<R>>
303 136..166 '{ ...lue; }': () 303 136..166 '{ ...lue; }': ()
304 142..163 '&query....value': &QueryResponse<R> 304 142..163 '&query....value': &QueryResponse<R>
305 143..157 'query_response': Canonical<QueryResponse<R>> 305 143..157 'query_response': Canonical<QueryResponse<R>>
306 143..163 'query_....value': QueryResponse<R> 306 143..163 'query_....value': QueryResponse<R>
307 "### 307 "#]],
308 ); 308 );
309} 309}
310 310
311#[test] 311#[test]
312fn infer_paren_macro_call() { 312fn infer_paren_macro_call() {
313 assert_snapshot!( 313 check_infer(
314 infer(r#" 314 r#"
315macro_rules! bar { () => {0u32} } 315 macro_rules! bar { () => {0u32} }
316fn test() { 316 fn test() {
317 let a = (bar!()); 317 let a = (bar!());
318} 318 }
319"#), 319 "#,
320 @r###" 320 expect![[r#"
321 !0..4 '0u32': u32 321 !0..4 '0u32': u32
322 44..69 '{ ...()); }': () 322 44..69 '{ ...()); }': ()
323 54..55 'a': u32 323 54..55 'a': u32
324 "### 324 "#]],
325 ); 325 );
326} 326}
327 327
328#[test] 328#[test]
329fn bug_1030() { 329fn bug_1030() {
330 assert_snapshot!(infer(r#" 330 check_infer(
331struct HashSet<T, H>; 331 r#"
332struct FxHasher; 332 struct HashSet<T, H>;
333type FxHashSet<T> = HashSet<T, FxHasher>; 333 struct FxHasher;
334 type FxHashSet<T> = HashSet<T, FxHasher>;
334 335
335impl<T, H> HashSet<T, H> { 336 impl<T, H> HashSet<T, H> {
336 fn default() -> HashSet<T, H> {} 337 fn default() -> HashSet<T, H> {}
337} 338 }
338 339
339pub fn main_loop() { 340 pub fn main_loop() {
340 FxHashSet::default(); 341 FxHashSet::default();
341} 342 }
342"#), 343 "#,
343 @r###" 344 expect![[r#"
344 143..145 '{}': () 345 143..145 '{}': ()
345 168..197 '{ ...t(); }': () 346 168..197 '{ ...t(); }': ()
346 174..192 'FxHash...efault': fn default<{unknown}, FxHasher>() -> HashSet<{unknown}, FxHasher> 347 174..192 'FxHash...efault': fn default<{unknown}, FxHasher>() -> HashSet<{unknown}, FxHasher>
347 174..194 'FxHash...ault()': HashSet<{unknown}, FxHasher> 348 174..194 'FxHash...ault()': HashSet<{unknown}, FxHasher>
348 "### 349 "#]],
349 ); 350 );
350} 351}
351 352
352#[test] 353#[test]
353fn issue_2669() { 354fn issue_2669() {
354 assert_snapshot!( 355 check_infer(
355 infer( 356 r#"
356 r#"trait A {} 357 trait A {}
357 trait Write {} 358 trait Write {}
358 struct Response<T> {} 359 struct Response<T> {}
359 360
360 trait D { 361 trait D {
361 fn foo(); 362 fn foo();
362 } 363 }
363 364
364 impl<T:A> D for Response<T> { 365 impl<T:A> D for Response<T> {
365 fn foo() { 366 fn foo() {
366 end(); 367 end();
367 fn end<W: Write>() { 368 fn end<W: Write>() {
368 let _x: T = loop {}; 369 let _x: T = loop {};
370 }
369 } 371 }
370 } 372 }
371 }"# 373 "#,
372 ), 374 expect![[r#"
373 @r###" 375 119..214 '{ ... }': ()
374 147..262 '{ ... }': () 376 129..132 'end': fn end<{unknown}>()
375 161..164 'end': fn end<{unknown}>() 377 129..134 'end()': ()
376 161..166 'end()': () 378 163..208 '{ ... }': ()
377 199..252 '{ ... }': () 379 181..183 '_x': !
378 221..223 '_x': ! 380 190..197 'loop {}': !
379 230..237 'loop {}': ! 381 195..197 '{}': ()
380 235..237 '{}': () 382 "#]],
381 "###
382 ) 383 )
383} 384}
384 385
385#[test] 386#[test]
386fn issue_2705() { 387fn issue_2705() {
387 assert_snapshot!( 388 check_infer(
388 infer(r#" 389 r#"
389trait Trait {} 390 trait Trait {}
390fn test() { 391 fn test() {
391 <Trait<u32>>::foo() 392 <Trait<u32>>::foo()
392} 393 }
393"#), 394 "#,
394 @r###" 395 expect![[r#"
395 25..52 '{ ...oo() }': () 396 25..52 '{ ...oo() }': ()
396 31..48 '<Trait...>::foo': {unknown} 397 31..48 '<Trait...>::foo': {unknown}
397 31..50 '<Trait...:foo()': () 398 31..50 '<Trait...:foo()': ()
398 "### 399 "#]],
399 ); 400 );
400} 401}
401 402
@@ -479,25 +480,25 @@ fn main() {
479 480
480#[test] 481#[test]
481fn issue_3999_slice() { 482fn issue_3999_slice() {
482 assert_snapshot!( 483 check_infer(
483 infer(r#" 484 r#"
484fn foo(params: &[usize]) { 485 fn foo(params: &[usize]) {
485 match params { 486 match params {
486 [ps @ .., _] => {} 487 [ps @ .., _] => {}
487 } 488 }
488} 489 }
489"#), 490 "#,
490 @r###" 491 expect![[r#"
491 7..13 'params': &[usize] 492 7..13 'params': &[usize]
492 25..80 '{ ... } }': () 493 25..80 '{ ... } }': ()
493 31..78 'match ... }': () 494 31..78 'match ... }': ()
494 37..43 'params': &[usize] 495 37..43 'params': &[usize]
495 54..66 '[ps @ .., _]': [usize] 496 54..66 '[ps @ .., _]': [usize]
496 55..62 'ps @ ..': &[usize] 497 55..62 'ps @ ..': &[usize]
497 60..62 '..': [usize] 498 60..62 '..': [usize]
498 64..65 '_': usize 499 64..65 '_': usize
499 70..72 '{}': () 500 70..72 '{}': ()
500 "### 501 "#]],
501 ); 502 );
502} 503}
503 504
@@ -505,334 +506,337 @@ fn foo(params: &[usize]) {
505fn issue_3999_struct() { 506fn issue_3999_struct() {
506 // rust-analyzer should not panic on seeing this malformed 507 // rust-analyzer should not panic on seeing this malformed
507 // record pattern. 508 // record pattern.
508 assert_snapshot!( 509 check_infer(
509 infer(r#" 510 r#"
510struct Bar { 511 struct Bar {
511 a: bool, 512 a: bool,
512} 513 }
513fn foo(b: Bar) { 514 fn foo(b: Bar) {
514 match b { 515 match b {
515 Bar { a: .. } => {}, 516 Bar { a: .. } => {},
516 } 517 }
517} 518 }
518"#), 519 "#,
519 @r###" 520 expect![[r#"
520 35..36 'b': Bar 521 35..36 'b': Bar
521 43..95 '{ ... } }': () 522 43..95 '{ ... } }': ()
522 49..93 'match ... }': () 523 49..93 'match ... }': ()
523 55..56 'b': Bar 524 55..56 'b': Bar
524 67..80 'Bar { a: .. }': Bar 525 67..80 'Bar { a: .. }': Bar
525 76..78 '..': bool 526 76..78 '..': bool
526 84..86 '{}': () 527 84..86 '{}': ()
527 "### 528 "#]],
528 ); 529 );
529} 530}
530 531
531#[test] 532#[test]
532fn issue_4235_name_conflicts() { 533fn issue_4235_name_conflicts() {
533 assert_snapshot!( 534 check_infer(
534 infer(r#" 535 r#"
535struct FOO {} 536 struct FOO {}
536static FOO:FOO = FOO {}; 537 static FOO:FOO = FOO {};
537 538
538impl FOO { 539 impl FOO {
539 fn foo(&self) {} 540 fn foo(&self) {}
540} 541 }
541 542
542fn main() { 543 fn main() {
543 let a = &FOO; 544 let a = &FOO;
544 a.foo(); 545 a.foo();
545} 546 }
546"#), @r###" 547 "#,
547 31..37 'FOO {}': FOO 548 expect![[r#"
548 63..67 'self': &FOO 549 31..37 'FOO {}': FOO
549 69..71 '{}': () 550 63..67 'self': &FOO
550 85..119 '{ ...o(); }': () 551 69..71 '{}': ()
551 95..96 'a': &FOO 552 85..119 '{ ...o(); }': ()
552 99..103 '&FOO': &FOO 553 95..96 'a': &FOO
553 100..103 'FOO': FOO 554 99..103 '&FOO': &FOO
554 109..110 'a': &FOO 555 100..103 'FOO': FOO
555 109..116 'a.foo()': () 556 109..110 'a': &FOO
556 "### 557 109..116 'a.foo()': ()
558 "#]],
557 ); 559 );
558} 560}
559 561
560#[test] 562#[test]
561fn issue_4465_dollar_crate_at_type() { 563fn issue_4465_dollar_crate_at_type() {
562 assert_snapshot!( 564 check_infer(
563 infer(r#" 565 r#"
564pub struct Foo {} 566 pub struct Foo {}
565pub fn anything<T>() -> T { 567 pub fn anything<T>() -> T {
566 loop {} 568 loop {}
567} 569 }
568macro_rules! foo { 570 macro_rules! foo {
569 () => {{ 571 () => {{
570 let r: $crate::Foo = anything(); 572 let r: $crate::Foo = anything();
571 r 573 r
572 }}; 574 }};
573} 575 }
574fn main() { 576 fn main() {
575 let _a = foo!(); 577 let _a = foo!();
576} 578 }
577"#), @r###" 579 "#,
578 44..59 '{ loop {} }': T 580 expect![[r#"
579 50..57 'loop {}': ! 581 44..59 '{ loop {} }': T
580 55..57 '{}': () 582 50..57 'loop {}': !
581 !0..31 '{letr:...g();r}': Foo 583 55..57 '{}': ()
582 !4..5 'r': Foo 584 !0..31 '{letr:...g();r}': Foo
583 !18..26 'anything': fn anything<Foo>() -> Foo 585 !4..5 'r': Foo
584 !18..28 'anything()': Foo 586 !18..26 'anything': fn anything<Foo>() -> Foo
585 !29..30 'r': Foo 587 !18..28 'anything()': Foo
586 163..187 '{ ...!(); }': () 588 !29..30 'r': Foo
587 173..175 '_a': Foo 589 163..187 '{ ...!(); }': ()
588 "###); 590 173..175 '_a': Foo
591 "#]],
592 );
589} 593}
590 594
591#[test] 595#[test]
592fn issue_4053_diesel_where_clauses() { 596fn issue_4053_diesel_where_clauses() {
593 assert_snapshot!( 597 check_infer(
594 infer(r#" 598 r#"
595trait BoxedDsl<DB> { 599 trait BoxedDsl<DB> {
596 type Output; 600 type Output;
597 fn internal_into_boxed(self) -> Self::Output; 601 fn internal_into_boxed(self) -> Self::Output;
598} 602 }
599 603
600struct SelectStatement<From, Select, Distinct, Where, Order, LimitOffset, GroupBy, Locking> { 604 struct SelectStatement<From, Select, Distinct, Where, Order, LimitOffset, GroupBy, Locking> {
601 order: Order, 605 order: Order,
602} 606 }
603 607
604trait QueryFragment<DB: Backend> {} 608 trait QueryFragment<DB: Backend> {}
605 609
606trait Into<T> { fn into(self) -> T; } 610 trait Into<T> { fn into(self) -> T; }
607 611
608impl<F, S, D, W, O, LOf, DB> BoxedDsl<DB> 612 impl<F, S, D, W, O, LOf, DB> BoxedDsl<DB>
609 for SelectStatement<F, S, D, W, O, LOf, G> 613 for SelectStatement<F, S, D, W, O, LOf, G>
610where 614 where
611 O: Into<dyn QueryFragment<DB>>, 615 O: Into<dyn QueryFragment<DB>>,
612{ 616 {
613 type Output = XXX; 617 type Output = XXX;
614 618
615 fn internal_into_boxed(self) -> Self::Output { 619 fn internal_into_boxed(self) -> Self::Output {
616 self.order.into(); 620 self.order.into();
617 } 621 }
618} 622 }
619"#), 623 "#,
620 @r###" 624 expect![[r#"
621 65..69 'self': Self 625 65..69 'self': Self
622 267..271 'self': Self 626 267..271 'self': Self
623 466..470 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}> 627 466..470 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
624 488..522 '{ ... }': () 628 488..522 '{ ... }': ()
625 498..502 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}> 629 498..502 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
626 498..508 'self.order': O 630 498..508 'self.order': O
627 498..515 'self.o...into()': dyn QueryFragment<DB> 631 498..515 'self.o...into()': dyn QueryFragment<DB>
628 "### 632 "#]],
629 ); 633 );
630} 634}
631 635
632#[test] 636#[test]
633fn issue_4953() { 637fn issue_4953() {
634 assert_snapshot!( 638 check_infer(
635 infer(r#" 639 r#"
636pub struct Foo(pub i64); 640 pub struct Foo(pub i64);
637impl Foo { 641 impl Foo {
638 fn test() -> Self { Self(0i64) } 642 fn test() -> Self { Self(0i64) }
639} 643 }
640"#), 644 "#,
641 @r###" 645 expect![[r#"
642 58..72 '{ Self(0i64) }': Foo 646 58..72 '{ Self(0i64) }': Foo
643 60..64 'Self': Foo(i64) -> Foo 647 60..64 'Self': Foo(i64) -> Foo
644 60..70 'Self(0i64)': Foo 648 60..70 'Self(0i64)': Foo
645 65..69 '0i64': i64 649 65..69 '0i64': i64
646 "### 650 "#]],
647 ); 651 );
648 assert_snapshot!( 652 check_infer(
649 infer(r#" 653 r#"
650pub struct Foo<T>(pub T); 654 pub struct Foo<T>(pub T);
651impl Foo<i64> { 655 impl Foo<i64> {
652 fn test() -> Self { Self(0i64) } 656 fn test() -> Self { Self(0i64) }
653} 657 }
654"#), 658 "#,
655 @r###" 659 expect![[r#"
656 64..78 '{ Self(0i64) }': Foo<i64> 660 64..78 '{ Self(0i64) }': Foo<i64>
657 66..70 'Self': Foo<i64>(i64) -> Foo<i64> 661 66..70 'Self': Foo<i64>(i64) -> Foo<i64>
658 66..76 'Self(0i64)': Foo<i64> 662 66..76 'Self(0i64)': Foo<i64>
659 71..75 '0i64': i64 663 71..75 '0i64': i64
660 "### 664 "#]],
661 ); 665 );
662} 666}
663 667
664#[test] 668#[test]
665fn issue_4931() { 669fn issue_4931() {
666 assert_snapshot!( 670 check_infer(
667 infer(r#" 671 r#"
668trait Div<T> { 672 trait Div<T> {
669 type Output; 673 type Output;
670} 674 }
671 675
672trait CheckedDiv: Div<()> {} 676 trait CheckedDiv: Div<()> {}
673 677
674trait PrimInt: CheckedDiv<Output = ()> { 678 trait PrimInt: CheckedDiv<Output = ()> {
675 fn pow(self); 679 fn pow(self);
676} 680 }
677 681
678fn check<T: PrimInt>(i: T) { 682 fn check<T: PrimInt>(i: T) {
679 i.pow(); 683 i.pow();
680} 684 }
681"#), 685 "#,
682 @r###" 686 expect![[r#"
683 117..121 'self': Self 687 117..121 'self': Self
684 148..149 'i': T 688 148..149 'i': T
685 154..170 '{ ...w(); }': () 689 154..170 '{ ...w(); }': ()
686 160..161 'i': T 690 160..161 'i': T
687 160..167 'i.pow()': () 691 160..167 'i.pow()': ()
688 "### 692 "#]],
689 ); 693 );
690} 694}
691 695
692#[test] 696#[test]
693fn issue_4885() { 697fn issue_4885() {
694 assert_snapshot!( 698 check_infer(
695 infer(r#" 699 r#"
696#[lang = "coerce_unsized"] 700 #[lang = "coerce_unsized"]
697pub trait CoerceUnsized<T> {} 701 pub trait CoerceUnsized<T> {}
698 702
699trait Future { 703 trait Future {
700 type Output; 704 type Output;
701} 705 }
702trait Foo<R> { 706 trait Foo<R> {
703 type Bar; 707 type Bar;
704} 708 }
705fn foo<R, K>(key: &K) -> impl Future<Output = K::Bar> 709 fn foo<R, K>(key: &K) -> impl Future<Output = K::Bar>
706where 710 where
707 K: Foo<R>, 711 K: Foo<R>,
708{ 712 {
709 bar(key) 713 bar(key)
710} 714 }
711fn bar<R, K>(key: &K) -> impl Future<Output = K::Bar> 715 fn bar<R, K>(key: &K) -> impl Future<Output = K::Bar>
712where 716 where
713 K: Foo<R>, 717 K: Foo<R>,
714{ 718 {
715} 719 }
716"#), 720 "#,
717 @r###" 721 expect![[r#"
718 136..139 'key': &K 722 136..139 'key': &K
719 198..214 '{ ...key) }': impl Future<Output = <K as Foo<R>>::Bar> 723 198..214 '{ ...key) }': impl Future<Output = <K as Foo<R>>::Bar>
720 204..207 'bar': fn bar<R, K>(&K) -> impl Future<Output = <K as Foo<R>>::Bar> 724 204..207 'bar': fn bar<R, K>(&K) -> impl Future<Output = <K as Foo<R>>::Bar>
721 204..212 'bar(key)': impl Future<Output = <K as Foo<R>>::Bar> 725 204..212 'bar(key)': impl Future<Output = <K as Foo<R>>::Bar>
722 208..211 'key': &K 726 208..211 'key': &K
723 228..231 'key': &K 727 228..231 'key': &K
724 290..293 '{ }': () 728 290..293 '{ }': ()
725 "### 729 "#]],
726 ); 730 );
727} 731}
728 732
729#[test] 733#[test]
730fn issue_4800() { 734fn issue_4800() {
731 assert_snapshot!( 735 check_infer(
732 infer(r#" 736 r#"
733trait Debug {} 737 trait Debug {}
734 738
735struct Foo<T>; 739 struct Foo<T>;
736 740
737type E1<T> = (T, T, T); 741 type E1<T> = (T, T, T);
738type E2<T> = E1<E1<E1<(T, T, T)>>>; 742 type E2<T> = E1<E1<E1<(T, T, T)>>>;
739 743
740impl Debug for Foo<E2<()>> {} 744 impl Debug for Foo<E2<()>> {}
741 745
742struct Request; 746 struct Request;
743 747
744pub trait Future { 748 pub trait Future {
745 type Output; 749 type Output;
746} 750 }
747 751
748pub struct PeerSet<D>; 752 pub struct PeerSet<D>;
749 753
750impl<D> Service<Request> for PeerSet<D> 754 impl<D> Service<Request> for PeerSet<D>
751where 755 where
752 D: Discover, 756 D: Discover,
753 D::Key: Debug, 757 D::Key: Debug,
754{ 758 {
755 type Error = (); 759 type Error = ();
756 type Future = dyn Future<Output = Self::Error>; 760 type Future = dyn Future<Output = Self::Error>;
757 761
758 fn call(&mut self) -> Self::Future { 762 fn call(&mut self) -> Self::Future {
759 loop {} 763 loop {}
760 } 764 }
761} 765 }
762 766
763pub trait Discover { 767 pub trait Discover {
764 type Key; 768 type Key;
765} 769 }
766 770
767pub trait Service<Request> { 771 pub trait Service<Request> {
768 type Error; 772 type Error;
769 type Future: Future<Output = Self::Error>; 773 type Future: Future<Output = Self::Error>;
770 fn call(&mut self) -> Self::Future; 774 fn call(&mut self) -> Self::Future;
771} 775 }
772"#), 776 "#,
773 @r###" 777 expect![[r#"
774 379..383 'self': &mut PeerSet<D> 778 379..383 'self': &mut PeerSet<D>
775 401..424 '{ ... }': dyn Future<Output = ()> 779 401..424 '{ ... }': dyn Future<Output = ()>
776 411..418 'loop {}': ! 780 411..418 'loop {}': !
777 416..418 '{}': () 781 416..418 '{}': ()
778 575..579 'self': &mut Self 782 575..579 'self': &mut Self
779 "### 783 "#]],
780 ); 784 );
781} 785}
782 786
783#[test] 787#[test]
784fn issue_4966() { 788fn issue_4966() {
785 assert_snapshot!( 789 check_infer(
786 infer(r#" 790 r#"
787pub trait IntoIterator { 791 pub trait IntoIterator {
788 type Item; 792 type Item;
789} 793 }
790 794
791struct Repeat<A> { element: A } 795 struct Repeat<A> { element: A }
792 796
793struct Map<F> { f: F } 797 struct Map<F> { f: F }
794 798
795struct Vec<T> {} 799 struct Vec<T> {}
796 800
797#[lang = "deref"] 801 #[lang = "deref"]
798pub trait Deref { 802 pub trait Deref {
799 type Target; 803 type Target;
800} 804 }
801 805
802impl<T> Deref for Vec<T> { 806 impl<T> Deref for Vec<T> {
803 type Target = [T]; 807 type Target = [T];
804} 808 }
805 809
806fn from_iter<A, T: IntoIterator<Item = A>>(iter: T) -> Vec<A> {} 810 fn from_iter<A, T: IntoIterator<Item = A>>(iter: T) -> Vec<A> {}
807 811
808fn main() { 812 fn main() {
809 let inner = Map { f: |_: &f64| 0.0 }; 813 let inner = Map { f: |_: &f64| 0.0 };
810 814
811 let repeat = Repeat { element: inner }; 815 let repeat = Repeat { element: inner };
812 816
813 let vec = from_iter(repeat); 817 let vec = from_iter(repeat);
814 818
815 vec.foo_bar(); 819 vec.foo_bar();
816} 820 }
817"#), 821 "#,
818 @r###" 822 expect![[r#"
819 270..274 'iter': T 823 270..274 'iter': T
820 289..291 '{}': () 824 289..291 '{}': ()
821 303..447 '{ ...r(); }': () 825 303..447 '{ ...r(); }': ()
822 313..318 'inner': Map<|&f64| -> f64> 826 313..318 'inner': Map<|&f64| -> f64>
823 321..345 'Map { ... 0.0 }': Map<|&f64| -> f64> 827 321..345 'Map { ... 0.0 }': Map<|&f64| -> f64>
824 330..343 '|_: &f64| 0.0': |&f64| -> f64 828 330..343 '|_: &f64| 0.0': |&f64| -> f64
825 331..332 '_': &f64 829 331..332 '_': &f64
826 340..343 '0.0': f64 830 340..343 '0.0': f64
827 356..362 'repeat': Repeat<Map<|&f64| -> f64>> 831 356..362 'repeat': Repeat<Map<|&f64| -> f64>>
828 365..390 'Repeat...nner }': Repeat<Map<|&f64| -> f64>> 832 365..390 'Repeat...nner }': Repeat<Map<|&f64| -> f64>>
829 383..388 'inner': Map<|&f64| -> f64> 833 383..388 'inner': Map<|&f64| -> f64>
830 401..404 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> 834 401..404 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
831 407..416 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> 835 407..416 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
832 407..424 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> 836 407..424 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
833 417..423 'repeat': Repeat<Map<|&f64| -> f64>> 837 417..423 'repeat': Repeat<Map<|&f64| -> f64>>
834 431..434 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> 838 431..434 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
835 431..444 'vec.foo_bar()': {unknown} 839 431..444 'vec.foo_bar()': {unknown}
836 "### 840 "#]],
837 ); 841 );
838} 842}