aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/simple.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests/simple.rs')
-rw-r--r--crates/ra_hir_ty/src/tests/simple.rs3413
1 files changed, 1707 insertions, 1706 deletions
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs
index 6d3e264af..3fd7d5cd4 100644
--- a/crates/ra_hir_ty/src/tests/simple.rs
+++ b/crates/ra_hir_ty/src/tests/simple.rs
@@ -1,6 +1,6 @@
1use insta::assert_snapshot; 1use expect::expect;
2 2
3use super::{check_types, infer}; 3use super::{check_infer, check_types};
4 4
5#[test] 5#[test]
6fn infer_box() { 6fn infer_box() {
@@ -45,43 +45,44 @@ fn test() {
45 45
46#[test] 46#[test]
47fn self_in_struct_lit() { 47fn self_in_struct_lit() {
48 assert_snapshot!(infer( 48 check_infer(
49 r#" 49 r#"
50//- /main.rs 50 //- /main.rs
51struct S<T> { x: T } 51 struct S<T> { x: T }
52 52
53impl S<u32> { 53 impl S<u32> {
54 fn foo() { 54 fn foo() {
55 Self { x: 1 }; 55 Self { x: 1 };
56 } 56 }
57} 57 }
58"#, 58 "#,
59 ), @r###" 59 expect![[r#"
60 49..79 '{ ... }': () 60 49..79 '{ ... }': ()
61 59..72 'Self { x: 1 }': S<u32> 61 59..72 'Self { x: 1 }': S<u32>
62 69..70 '1': u32 62 69..70 '1': u32
63 "###); 63 "#]],
64 );
64} 65}
65 66
66#[test] 67#[test]
67fn type_alias_in_struct_lit() { 68fn type_alias_in_struct_lit() {
68 assert_snapshot!(infer( 69 check_infer(
69 r#" 70 r#"
70//- /main.rs 71 //- /main.rs
71struct S<T> { x: T } 72 struct S<T> { x: T }
72 73
73type SS = S<u32>; 74 type SS = S<u32>;
74 75
75fn foo() { 76 fn foo() {
76 SS { x: 1 }; 77 SS { x: 1 };
77} 78 }
78 79 "#,
79"#, 80 expect![[r#"
80 ), @r###" 81 50..70 '{ ...1 }; }': ()
81 50..70 '{ ...1 }; }': () 82 56..67 'SS { x: 1 }': S<u32>
82 56..67 'SS { x: 1 }': S<u32> 83 64..65 '1': u32
83 64..65 '1': u32 84 "#]],
84 "###); 85 );
85} 86}
86 87
87#[test] 88#[test]
@@ -148,1549 +149,1549 @@ fn test() {
148 149
149#[test] 150#[test]
150fn infer_basics() { 151fn infer_basics() {
151 assert_snapshot!( 152 check_infer(
152 infer(r#" 153 r#"
153fn test(a: u32, b: isize, c: !, d: &str) { 154 fn test(a: u32, b: isize, c: !, d: &str) {
154 a; 155 a;
155 b; 156 b;
156 c; 157 c;
157 d; 158 d;
158 1usize; 159 1usize;
159 1isize; 160 1isize;
160 "test"; 161 "test";
161 1.0f32; 162 1.0f32;
162}"#), 163 }"#,
163 @r###" 164 expect![[r#"
164 8..9 'a': u32 165 8..9 'a': u32
165 16..17 'b': isize 166 16..17 'b': isize
166 26..27 'c': ! 167 26..27 'c': !
167 32..33 'd': &str 168 32..33 'd': &str
168 41..120 '{ ...f32; }': () 169 41..120 '{ ...f32; }': ()
169 47..48 'a': u32 170 47..48 'a': u32
170 54..55 'b': isize 171 54..55 'b': isize
171 61..62 'c': ! 172 61..62 'c': !
172 68..69 'd': &str 173 68..69 'd': &str
173 75..81 '1usize': usize 174 75..81 '1usize': usize
174 87..93 '1isize': isize 175 87..93 '1isize': isize
175 99..105 '"test"': &str 176 99..105 '"test"': &str
176 111..117 '1.0f32': f32 177 111..117 '1.0f32': f32
177 "### 178 "#]],
178 ); 179 );
179} 180}
180 181
181#[test] 182#[test]
182fn infer_let() { 183fn infer_let() {
183 assert_snapshot!( 184 check_infer(
184 infer(r#" 185 r#"
185fn test() { 186 fn test() {
186 let a = 1isize; 187 let a = 1isize;
187 let b: usize = 1; 188 let b: usize = 1;
188 let c = b; 189 let c = b;
189 let d: u32; 190 let d: u32;
190 let e; 191 let e;
191 let f: i32 = e; 192 let f: i32 = e;
192} 193 }
193"#), 194 "#,
194 @r###" 195 expect![[r#"
195 10..117 '{ ...= e; }': () 196 10..117 '{ ...= e; }': ()
196 20..21 'a': isize 197 20..21 'a': isize
197 24..30 '1isize': isize 198 24..30 '1isize': isize
198 40..41 'b': usize 199 40..41 'b': usize
199 51..52 '1': usize 200 51..52 '1': usize
200 62..63 'c': usize 201 62..63 'c': usize
201 66..67 'b': usize 202 66..67 'b': usize
202 77..78 'd': u32 203 77..78 'd': u32
203 93..94 'e': i32 204 93..94 'e': i32
204 104..105 'f': i32 205 104..105 'f': i32
205 113..114 'e': i32 206 113..114 'e': i32
206 "### 207 "#]],
207 ); 208 );
208} 209}
209 210
210#[test] 211#[test]
211fn infer_paths() { 212fn infer_paths() {
212 assert_snapshot!( 213 check_infer(
213 infer(r#" 214 r#"
214fn a() -> u32 { 1 } 215 fn a() -> u32 { 1 }
215 216
216mod b { 217 mod b {
217 fn c() -> u32 { 1 } 218 fn c() -> u32 { 1 }
218} 219 }
219 220
220fn test() { 221 fn test() {
221 a(); 222 a();
222 b::c(); 223 b::c();
223} 224 }
224"#), 225 "#,
225 @r###" 226 expect![[r#"
226 14..19 '{ 1 }': u32 227 14..19 '{ 1 }': u32
227 16..17 '1': u32 228 16..17 '1': u32
228 47..52 '{ 1 }': u32 229 47..52 '{ 1 }': u32
229 49..50 '1': u32 230 49..50 '1': u32
230 66..90 '{ ...c(); }': () 231 66..90 '{ ...c(); }': ()
231 72..73 'a': fn a() -> u32 232 72..73 'a': fn a() -> u32
232 72..75 'a()': u32 233 72..75 'a()': u32
233 81..85 'b::c': fn c() -> u32 234 81..85 'b::c': fn c() -> u32
234 81..87 'b::c()': u32 235 81..87 'b::c()': u32
235 "### 236 "#]],
236 ); 237 );
237} 238}
238 239
239#[test] 240#[test]
240fn infer_path_type() { 241fn infer_path_type() {
241 assert_snapshot!( 242 check_infer(
242 infer(r#" 243 r#"
243struct S; 244 struct S;
244 245
245impl S { 246 impl S {
246 fn foo() -> i32 { 1 } 247 fn foo() -> i32 { 1 }
247} 248 }
248 249
249fn test() { 250 fn test() {
250 S::foo(); 251 S::foo();
251 <S>::foo(); 252 <S>::foo();
252} 253 }
253"#), 254 "#,
254 @r###" 255 expect![[r#"
255 40..45 '{ 1 }': i32 256 40..45 '{ 1 }': i32
256 42..43 '1': i32 257 42..43 '1': i32
257 59..92 '{ ...o(); }': () 258 59..92 '{ ...o(); }': ()
258 65..71 'S::foo': fn foo() -> i32 259 65..71 'S::foo': fn foo() -> i32
259 65..73 'S::foo()': i32 260 65..73 'S::foo()': i32
260 79..87 '<S>::foo': fn foo() -> i32 261 79..87 '<S>::foo': fn foo() -> i32
261 79..89 '<S>::foo()': i32 262 79..89 '<S>::foo()': i32
262 "### 263 "#]],
263 ); 264 );
264} 265}
265 266
266#[test] 267#[test]
267fn infer_struct() { 268fn infer_struct() {
268 assert_snapshot!( 269 check_infer(
269 infer(r#" 270 r#"
270struct A { 271 struct A {
271 b: B, 272 b: B,
272 c: C, 273 c: C,
273} 274 }
274struct B; 275 struct B;
275struct C(usize); 276 struct C(usize);
276 277
277fn test() { 278 fn test() {
278 let c = C(1); 279 let c = C(1);
279 B; 280 B;
280 let a: A = A { b: B, c: C(1) }; 281 let a: A = A { b: B, c: C(1) };
281 a.b; 282 a.b;
282 a.c; 283 a.c;
283} 284 }
284"#), 285 "#,
285 @r###" 286 expect![[r#"
286 71..153 '{ ...a.c; }': () 287 71..153 '{ ...a.c; }': ()
287 81..82 'c': C 288 81..82 'c': C
288 85..86 'C': C(usize) -> C 289 85..86 'C': C(usize) -> C
289 85..89 'C(1)': C 290 85..89 'C(1)': C
290 87..88 '1': usize 291 87..88 '1': usize
291 95..96 'B': B 292 95..96 'B': B
292 106..107 'a': A 293 106..107 'a': A
293 113..132 'A { b:...C(1) }': A 294 113..132 'A { b:...C(1) }': A
294 120..121 'B': B 295 120..121 'B': B
295 126..127 'C': C(usize) -> C 296 126..127 'C': C(usize) -> C
296 126..130 'C(1)': C 297 126..130 'C(1)': C
297 128..129 '1': usize 298 128..129 '1': usize
298 138..139 'a': A 299 138..139 'a': A
299 138..141 'a.b': B 300 138..141 'a.b': B
300 147..148 'a': A 301 147..148 'a': A
301 147..150 'a.c': C 302 147..150 'a.c': C
302 "### 303 "#]],
303 ); 304 );
304} 305}
305 306
306#[test] 307#[test]
307fn infer_enum() { 308fn infer_enum() {
308 assert_snapshot!( 309 check_infer(
309 infer(r#" 310 r#"
310enum E { 311 enum E {
311 V1 { field: u32 }, 312 V1 { field: u32 },
312 V2 313 V2
313} 314 }
314fn test() { 315 fn test() {
315 E::V1 { field: 1 }; 316 E::V1 { field: 1 };
316 E::V2; 317 E::V2;
317}"#), 318 }"#,
318 @r###" 319 expect![[r#"
319 47..81 '{ E:...:V2; }': () 320 51..89 '{ ...:V2; }': ()
320 51..69 'E::V1 ...d: 1 }': E 321 57..75 'E::V1 ...d: 1 }': E
321 66..67 '1': u32 322 72..73 '1': u32
322 73..78 'E::V2': E 323 81..86 'E::V2': E
323 "### 324 "#]],
324 ); 325 );
325} 326}
326 327
327#[test] 328#[test]
328fn infer_union() { 329fn infer_union() {
329 assert_snapshot!( 330 check_infer(
330 infer(r#" 331 r#"
331union MyUnion { 332 union MyUnion {
332 foo: u32, 333 foo: u32,
333 bar: f32, 334 bar: f32,
334} 335 }
335 336
336unsafe fn baz(u: MyUnion) { 337 unsafe fn baz(u: MyUnion) {
337 let inner = u.foo; 338 let inner = u.foo;
338} 339 }
339"#), 340 "#,
340 @r###" 341 expect![[r#"
341 61..62 'u': MyUnion 342 61..62 'u': MyUnion
342 73..99 '{ ...foo; }': () 343 73..99 '{ ...foo; }': ()
343 83..88 'inner': u32 344 83..88 'inner': u32
344 91..92 'u': MyUnion 345 91..92 'u': MyUnion
345 91..96 'u.foo': u32 346 91..96 'u.foo': u32
346 "### 347 "#]],
347 ); 348 );
348} 349}
349 350
350#[test] 351#[test]
351fn infer_refs() { 352fn infer_refs() {
352 assert_snapshot!( 353 check_infer(
353 infer(r#" 354 r#"
354fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { 355 fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
355 a; 356 a;
356 *a; 357 *a;
357 &a; 358 &a;
358 &mut a; 359 &mut a;
359 b; 360 b;
360 *b; 361 *b;
361 &b; 362 &b;
362 c; 363 c;
363 *c; 364 *c;
364 d; 365 d;
365 *d; 366 *d;
366} 367 }
367"#), 368 "#,
368 @r###" 369 expect![[r#"
369 8..9 'a': &u32 370 8..9 'a': &u32
370 17..18 'b': &mut u32 371 17..18 'b': &mut u32
371 30..31 'c': *const u32 372 30..31 'c': *const u32
372 45..46 'd': *mut u32 373 45..46 'd': *mut u32
373 58..149 '{ ... *d; }': () 374 58..149 '{ ... *d; }': ()
374 64..65 'a': &u32 375 64..65 'a': &u32
375 71..73 '*a': u32 376 71..73 '*a': u32
376 72..73 'a': &u32 377 72..73 'a': &u32
377 79..81 '&a': &&u32 378 79..81 '&a': &&u32
378 80..81 'a': &u32 379 80..81 'a': &u32
379 87..93 '&mut a': &mut &u32 380 87..93 '&mut a': &mut &u32
380 92..93 'a': &u32 381 92..93 'a': &u32
381 99..100 'b': &mut u32 382 99..100 'b': &mut u32
382 106..108 '*b': u32 383 106..108 '*b': u32
383 107..108 'b': &mut u32 384 107..108 'b': &mut u32
384 114..116 '&b': &&mut u32 385 114..116 '&b': &&mut u32
385 115..116 'b': &mut u32 386 115..116 'b': &mut u32
386 122..123 'c': *const u32 387 122..123 'c': *const u32
387 129..131 '*c': u32 388 129..131 '*c': u32
388 130..131 'c': *const u32 389 130..131 'c': *const u32
389 137..138 'd': *mut u32 390 137..138 'd': *mut u32
390 144..146 '*d': u32 391 144..146 '*d': u32
391 145..146 'd': *mut u32 392 145..146 'd': *mut u32
392 "### 393 "#]],
393 ); 394 );
394} 395}
395 396
396#[test] 397#[test]
397fn infer_raw_ref() { 398fn infer_raw_ref() {
398 assert_snapshot!( 399 check_infer(
399 infer(r#" 400 r#"
400fn test(a: i32) { 401 fn test(a: i32) {
401 &raw mut a; 402 &raw mut a;
402 &raw const a; 403 &raw const a;
403} 404 }
404"#), 405 "#,
405 @r###" 406 expect![[r#"
406 8..9 'a': i32 407 8..9 'a': i32
407 16..53 '{ ...t a; }': () 408 16..53 '{ ...t a; }': ()
408 22..32 '&raw mut a': *mut i32 409 22..32 '&raw mut a': *mut i32
409 31..32 'a': i32 410 31..32 'a': i32
410 38..50 '&raw const a': *const i32 411 38..50 '&raw const a': *const i32
411 49..50 'a': i32 412 49..50 'a': i32
412 "### 413 "#]],
413 ); 414 );
414} 415}
415 416
416#[test] 417#[test]
417fn infer_literals() { 418fn infer_literals() {
418 assert_snapshot!( 419 check_infer(
419 infer(r##" 420 r##"
420fn test() { 421 fn test() {
421 5i32; 422 5i32;
422 5f32; 423 5f32;
423 5f64; 424 5f64;
424 "hello"; 425 "hello";
425 b"bytes"; 426 b"bytes";
426 'c'; 427 'c';
427 b'b'; 428 b'b';
428 3.14; 429 3.14;
429 5000; 430 5000;
430 false; 431 false;
431 true; 432 true;
432 r#" 433 r#"
433 //! doc 434 //! doc
434 // non-doc 435 // non-doc
435 mod foo {} 436 mod foo {}
436 "#; 437 "#;
437 br#"yolo"#; 438 br#"yolo"#;
438} 439 }
439"##), 440 "##,
440 @r###" 441 expect![[r##"
441 10..220 '{ ...o"#; }': () 442 10..216 '{ ...o"#; }': ()
442 16..20 '5i32': i32 443 16..20 '5i32': i32
443 26..30 '5f32': f32 444 26..30 '5f32': f32
444 36..40 '5f64': f64 445 36..40 '5f64': f64
445 46..53 '"hello"': &str 446 46..53 '"hello"': &str
446 59..67 'b"bytes"': &[u8; _] 447 59..67 'b"bytes"': &[u8; _]
447 73..76 ''c'': char 448 73..76 ''c'': char
448 82..86 'b'b'': u8 449 82..86 'b'b'': u8
449 92..96 '3.14': f64 450 92..96 '3.14': f64
450 102..106 '5000': i32 451 102..106 '5000': i32
451 112..117 'false': bool 452 112..117 'false': bool
452 123..127 'true': bool 453 123..127 'true': bool
453 133..201 'r#" ... "#': &str 454 133..197 'r#" ... "#': &str
454 207..217 'br#"yolo"#': &[u8; _] 455 203..213 'br#"yolo"#': &[u8; _]
455 "### 456 "##]],
456 ); 457 );
457} 458}
458 459
459#[test] 460#[test]
460fn infer_unary_op() { 461fn infer_unary_op() {
461 assert_snapshot!( 462 check_infer(
462 infer(r#" 463 r#"
463enum SomeType {} 464 enum SomeType {}
464 465
465fn test(x: SomeType) { 466 fn test(x: SomeType) {
466 let b = false; 467 let b = false;
467 let c = !b; 468 let c = !b;
468 let a = 100; 469 let a = 100;
469 let d: i128 = -a; 470 let d: i128 = -a;
470 let e = -100; 471 let e = -100;
471 let f = !!!true; 472 let f = !!!true;
472 let g = !42; 473 let g = !42;
473 let h = !10u32; 474 let h = !10u32;
474 let j = !a; 475 let j = !a;
475 -3.14; 476 -3.14;
476 !3; 477 !3;
477 -x; 478 -x;
478 !x; 479 !x;
479 -"hello"; 480 -"hello";
480 !"hello"; 481 !"hello";
481} 482 }
482"#), 483 "#,
483 @r###" 484 expect![[r#"
484 26..27 'x': SomeType 485 26..27 'x': SomeType
485 39..271 '{ ...lo"; }': () 486 39..271 '{ ...lo"; }': ()
486 49..50 'b': bool 487 49..50 'b': bool
487 53..58 'false': bool 488 53..58 'false': bool
488 68..69 'c': bool 489 68..69 'c': bool
489 72..74 '!b': bool 490 72..74 '!b': bool
490 73..74 'b': bool 491 73..74 'b': bool
491 84..85 'a': i128 492 84..85 'a': i128
492 88..91 '100': i128 493 88..91 '100': i128
493 101..102 'd': i128 494 101..102 'd': i128
494 111..113 '-a': i128 495 111..113 '-a': i128
495 112..113 'a': i128 496 112..113 'a': i128
496 123..124 'e': i32 497 123..124 'e': i32
497 127..131 '-100': i32 498 127..131 '-100': i32
498 128..131 '100': i32 499 128..131 '100': i32
499 141..142 'f': bool 500 141..142 'f': bool
500 145..152 '!!!true': bool 501 145..152 '!!!true': bool
501 146..152 '!!true': bool 502 146..152 '!!true': bool
502 147..152 '!true': bool 503 147..152 '!true': bool
503 148..152 'true': bool 504 148..152 'true': bool
504 162..163 'g': i32 505 162..163 'g': i32
505 166..169 '!42': i32 506 166..169 '!42': i32
506 167..169 '42': i32 507 167..169 '42': i32
507 179..180 'h': u32 508 179..180 'h': u32
508 183..189 '!10u32': u32 509 183..189 '!10u32': u32
509 184..189 '10u32': u32 510 184..189 '10u32': u32
510 199..200 'j': i128 511 199..200 'j': i128
511 203..205 '!a': i128 512 203..205 '!a': i128
512 204..205 'a': i128 513 204..205 'a': i128
513 211..216 '-3.14': f64 514 211..216 '-3.14': f64
514 212..216 '3.14': f64 515 212..216 '3.14': f64
515 222..224 '!3': i32 516 222..224 '!3': i32
516 223..224 '3': i32 517 223..224 '3': i32
517 230..232 '-x': {unknown} 518 230..232 '-x': {unknown}
518 231..232 'x': SomeType 519 231..232 'x': SomeType
519 238..240 '!x': {unknown} 520 238..240 '!x': {unknown}
520 239..240 'x': SomeType 521 239..240 'x': SomeType
521 246..254 '-"hello"': {unknown} 522 246..254 '-"hello"': {unknown}
522 247..254 '"hello"': &str 523 247..254 '"hello"': &str
523 260..268 '!"hello"': {unknown} 524 260..268 '!"hello"': {unknown}
524 261..268 '"hello"': &str 525 261..268 '"hello"': &str
525 "### 526 "#]],
526 ); 527 );
527} 528}
528 529
529#[test] 530#[test]
530fn infer_backwards() { 531fn infer_backwards() {
531 assert_snapshot!( 532 check_infer(
532 infer(r#" 533 r#"
533fn takes_u32(x: u32) {} 534 fn takes_u32(x: u32) {}
534 535
535struct S { i32_field: i32 } 536 struct S { i32_field: i32 }
536 537
537fn test() -> &mut &f64 { 538 fn test() -> &mut &f64 {
538 let a = unknown_function(); 539 let a = unknown_function();
539 takes_u32(a); 540 takes_u32(a);
540 let b = unknown_function(); 541 let b = unknown_function();
541 S { i32_field: b }; 542 S { i32_field: b };
542 let c = unknown_function(); 543 let c = unknown_function();
543 &mut &c 544 &mut &c
544} 545 }
545"#), 546 "#,
546 @r###" 547 expect![[r#"
547 13..14 'x': u32 548 13..14 'x': u32
548 21..23 '{}': () 549 21..23 '{}': ()
549 77..230 '{ ...t &c }': &mut &f64 550 77..230 '{ ...t &c }': &mut &f64
550 87..88 'a': u32 551 87..88 'a': u32
551 91..107 'unknow...nction': {unknown} 552 91..107 'unknow...nction': {unknown}
552 91..109 'unknow...tion()': u32 553 91..109 'unknow...tion()': u32
553 115..124 'takes_u32': fn takes_u32(u32) 554 115..124 'takes_u32': fn takes_u32(u32)
554 115..127 'takes_u32(a)': () 555 115..127 'takes_u32(a)': ()
555 125..126 'a': u32 556 125..126 'a': u32
556 137..138 'b': i32 557 137..138 'b': i32
557 141..157 'unknow...nction': {unknown} 558 141..157 'unknow...nction': {unknown}
558 141..159 'unknow...tion()': i32 559 141..159 'unknow...tion()': i32
559 165..183 'S { i3...d: b }': S 560 165..183 'S { i3...d: b }': S
560 180..181 'b': i32 561 180..181 'b': i32
561 193..194 'c': f64 562 193..194 'c': f64
562 197..213 'unknow...nction': {unknown} 563 197..213 'unknow...nction': {unknown}
563 197..215 'unknow...tion()': f64 564 197..215 'unknow...tion()': f64
564 221..228 '&mut &c': &mut &f64 565 221..228 '&mut &c': &mut &f64
565 226..228 '&c': &f64 566 226..228 '&c': &f64
566 227..228 'c': f64 567 227..228 'c': f64
567 "### 568 "#]],
568 ); 569 );
569} 570}
570 571
571#[test] 572#[test]
572fn infer_self() { 573fn infer_self() {
573 assert_snapshot!( 574 check_infer(
574 infer(r#" 575 r#"
575struct S; 576 struct S;
576 577
577impl S { 578 impl S {
578 fn test(&self) { 579 fn test(&self) {
579 self; 580 self;
580 } 581 }
581 fn test2(self: &Self) { 582 fn test2(self: &Self) {
582 self; 583 self;
583 } 584 }
584 fn test3() -> Self { 585 fn test3() -> Self {
585 S {} 586 S {}
586 } 587 }
587 fn test4() -> Self { 588 fn test4() -> Self {
588 Self {} 589 Self {}
589 } 590 }
590} 591 }
591"#), 592 "#,
592 @r###" 593 expect![[r#"
593 33..37 'self': &S 594 33..37 'self': &S
594 39..60 '{ ... }': () 595 39..60 '{ ... }': ()
595 49..53 'self': &S 596 49..53 'self': &S
596 74..78 'self': &S 597 74..78 'self': &S
597 87..108 '{ ... }': () 598 87..108 '{ ... }': ()
598 97..101 'self': &S 599 97..101 'self': &S
599 132..152 '{ ... }': S 600 132..152 '{ ... }': S
600 142..146 'S {}': S 601 142..146 'S {}': S
601 176..199 '{ ... }': S 602 176..199 '{ ... }': S
602 186..193 'Self {}': S 603 186..193 'Self {}': S
603 "### 604 "#]],
604 ); 605 );
605} 606}
606 607
607#[test] 608#[test]
608fn infer_self_as_path() { 609fn infer_self_as_path() {
609 assert_snapshot!( 610 check_infer(
610 infer(r#" 611 r#"
611struct S1; 612 struct S1;
612struct S2(isize); 613 struct S2(isize);
613enum E { 614 enum E {
614 V1, 615 V1,
615 V2(u32), 616 V2(u32),
616} 617 }
617 618
618impl S1 { 619 impl S1 {
619 fn test() { 620 fn test() {
620 Self; 621 Self;
621 } 622 }
622} 623 }
623impl S2 { 624 impl S2 {
624 fn test() { 625 fn test() {
625 Self(1); 626 Self(1);
626 } 627 }
627} 628 }
628impl E { 629 impl E {
629 fn test() { 630 fn test() {
630 Self::V1; 631 Self::V1;
631 Self::V2(1); 632 Self::V2(1);
632 } 633 }
633} 634 }
634"#), 635 "#,
635 @r###" 636 expect![[r#"
636 86..107 '{ ... }': () 637 86..107 '{ ... }': ()
637 96..100 'Self': S1 638 96..100 'Self': S1
638 134..158 '{ ... }': () 639 134..158 '{ ... }': ()
639 144..148 'Self': S2(isize) -> S2 640 144..148 'Self': S2(isize) -> S2
640 144..151 'Self(1)': S2 641 144..151 'Self(1)': S2
641 149..150 '1': isize 642 149..150 '1': isize
642 184..230 '{ ... }': () 643 184..230 '{ ... }': ()
643 194..202 'Self::V1': E 644 194..202 'Self::V1': E
644 212..220 'Self::V2': V2(u32) -> E 645 212..220 'Self::V2': V2(u32) -> E
645 212..223 'Self::V2(1)': E 646 212..223 'Self::V2(1)': E
646 221..222 '1': u32 647 221..222 '1': u32
647 "### 648 "#]],
648 ); 649 );
649} 650}
650 651
651#[test] 652#[test]
652fn infer_binary_op() { 653fn infer_binary_op() {
653 assert_snapshot!( 654 check_infer(
654 infer(r#" 655 r#"
655fn f(x: bool) -> i32 { 656 fn f(x: bool) -> i32 {
656 0i32 657 0i32
657} 658 }
658 659
659fn test() -> bool { 660 fn test() -> bool {
660 let x = a && b; 661 let x = a && b;
661 let y = true || false; 662 let y = true || false;
662 let z = x == y; 663 let z = x == y;
663 let t = x != y; 664 let t = x != y;
664 let minus_forty: isize = -40isize; 665 let minus_forty: isize = -40isize;
665 let h = minus_forty <= CONST_2; 666 let h = minus_forty <= CONST_2;
666 let c = f(z || y) + 5; 667 let c = f(z || y) + 5;
667 let d = b; 668 let d = b;
668 let g = minus_forty ^= i; 669 let g = minus_forty ^= i;
669 let ten: usize = 10; 670 let ten: usize = 10;
670 let ten_is_eleven = ten == some_num; 671 let ten_is_eleven = ten == some_num;
671 672
672 ten < 3 673 ten < 3
673} 674 }
674"#), 675 "#,
675 @r###" 676 expect![[r#"
676 5..6 'x': bool 677 5..6 'x': bool
677 21..33 '{ 0i32 }': i32 678 21..33 '{ 0i32 }': i32
678 27..31 '0i32': i32 679 27..31 '0i32': i32
679 53..369 '{ ... < 3 }': bool 680 53..369 '{ ... < 3 }': bool
680 63..64 'x': bool 681 63..64 'x': bool
681 67..68 'a': bool 682 67..68 'a': bool
682 67..73 'a && b': bool 683 67..73 'a && b': bool
683 72..73 'b': bool 684 72..73 'b': bool
684 83..84 'y': bool 685 83..84 'y': bool
685 87..91 'true': bool 686 87..91 'true': bool
686 87..100 'true || false': bool 687 87..100 'true || false': bool
687 95..100 'false': bool 688 95..100 'false': bool
688 110..111 'z': bool 689 110..111 'z': bool
689 114..115 'x': bool 690 114..115 'x': bool
690 114..120 'x == y': bool 691 114..120 'x == y': bool
691 119..120 'y': bool 692 119..120 'y': bool
692 130..131 't': bool 693 130..131 't': bool
693 134..135 'x': bool 694 134..135 'x': bool
694 134..140 'x != y': bool 695 134..140 'x != y': bool
695 139..140 'y': bool 696 139..140 'y': bool
696 150..161 'minus_forty': isize 697 150..161 'minus_forty': isize
697 171..179 '-40isize': isize 698 171..179 '-40isize': isize
698 172..179 '40isize': isize 699 172..179 '40isize': isize
699 189..190 'h': bool 700 189..190 'h': bool
700 193..204 'minus_forty': isize 701 193..204 'minus_forty': isize
701 193..215 'minus_...ONST_2': bool 702 193..215 'minus_...ONST_2': bool
702 208..215 'CONST_2': isize 703 208..215 'CONST_2': isize
703 225..226 'c': i32 704 225..226 'c': i32
704 229..230 'f': fn f(bool) -> i32 705 229..230 'f': fn f(bool) -> i32
705 229..238 'f(z || y)': i32 706 229..238 'f(z || y)': i32
706 229..242 'f(z || y) + 5': i32 707 229..242 'f(z || y) + 5': i32
707 231..232 'z': bool 708 231..232 'z': bool
708 231..237 'z || y': bool 709 231..237 'z || y': bool
709 236..237 'y': bool 710 236..237 'y': bool
710 241..242 '5': i32 711 241..242 '5': i32
711 252..253 'd': {unknown} 712 252..253 'd': {unknown}
712 256..257 'b': {unknown} 713 256..257 'b': {unknown}
713 267..268 'g': () 714 267..268 'g': ()
714 271..282 'minus_forty': isize 715 271..282 'minus_forty': isize
715 271..287 'minus_...y ^= i': () 716 271..287 'minus_...y ^= i': ()
716 286..287 'i': isize 717 286..287 'i': isize
717 297..300 'ten': usize 718 297..300 'ten': usize
718 310..312 '10': usize 719 310..312 '10': usize
719 322..335 'ten_is_eleven': bool 720 322..335 'ten_is_eleven': bool
720 338..341 'ten': usize 721 338..341 'ten': usize
721 338..353 'ten == some_num': bool 722 338..353 'ten == some_num': bool
722 345..353 'some_num': usize 723 345..353 'some_num': usize
723 360..363 'ten': usize 724 360..363 'ten': usize
724 360..367 'ten < 3': bool 725 360..367 'ten < 3': bool
725 366..367 '3': usize 726 366..367 '3': usize
726 "### 727 "#]],
727 ); 728 );
728} 729}
729 730
730#[test] 731#[test]
731fn infer_shift_op() { 732fn infer_shift_op() {
732 assert_snapshot!( 733 check_infer(
733 infer(r#" 734 r#"
734fn test() { 735 fn test() {
735 1u32 << 5u8; 736 1u32 << 5u8;
736 1u32 >> 5u8; 737 1u32 >> 5u8;
737} 738 }
738"#), 739 "#,
739 @r###" 740 expect![[r#"
740 10..47 '{ ...5u8; }': () 741 10..47 '{ ...5u8; }': ()
741 16..20 '1u32': u32 742 16..20 '1u32': u32
742 16..27 '1u32 << 5u8': u32 743 16..27 '1u32 << 5u8': u32
743 24..27 '5u8': u8 744 24..27 '5u8': u8
744 33..37 '1u32': u32 745 33..37 '1u32': u32
745 33..44 '1u32 >> 5u8': u32 746 33..44 '1u32 >> 5u8': u32
746 41..44 '5u8': u8 747 41..44 '5u8': u8
747 "### 748 "#]],
748 ); 749 );
749} 750}
750 751
751#[test] 752#[test]
752fn infer_field_autoderef() { 753fn infer_field_autoderef() {
753 assert_snapshot!( 754 check_infer(
754 infer(r#" 755 r#"
755struct A { 756 struct A {
756 b: B, 757 b: B,
757} 758 }
758struct B; 759 struct B;
759 760
760fn test1(a: A) { 761 fn test1(a: A) {
761 let a1 = a; 762 let a1 = a;
762 a1.b; 763 a1.b;
763 let a2 = &a; 764 let a2 = &a;
764 a2.b; 765 a2.b;
765 let a3 = &mut a; 766 let a3 = &mut a;
766 a3.b; 767 a3.b;
767 let a4 = &&&&&&&a; 768 let a4 = &&&&&&&a;
768 a4.b; 769 a4.b;
769 let a5 = &mut &&mut &&mut a; 770 let a5 = &mut &&mut &&mut a;
770 a5.b; 771 a5.b;
771} 772 }
772 773
773fn test2(a1: *const A, a2: *mut A) { 774 fn test2(a1: *const A, a2: *mut A) {
774 a1.b; 775 a1.b;
775 a2.b; 776 a2.b;
776} 777 }
777"#), 778 "#,
778 @r###" 779 expect![[r#"
779 43..44 'a': A 780 43..44 'a': A
780 49..212 '{ ...5.b; }': () 781 49..212 '{ ...5.b; }': ()
781 59..61 'a1': A 782 59..61 'a1': A
782 64..65 'a': A 783 64..65 'a': A
783 71..73 'a1': A 784 71..73 'a1': A
784 71..75 'a1.b': B 785 71..75 'a1.b': B
785 85..87 'a2': &A 786 85..87 'a2': &A
786 90..92 '&a': &A 787 90..92 '&a': &A
787 91..92 'a': A 788 91..92 'a': A
788 98..100 'a2': &A 789 98..100 'a2': &A
789 98..102 'a2.b': B 790 98..102 'a2.b': B
790 112..114 'a3': &mut A 791 112..114 'a3': &mut A
791 117..123 '&mut a': &mut A 792 117..123 '&mut a': &mut A
792 122..123 'a': A 793 122..123 'a': A
793 129..131 'a3': &mut A 794 129..131 'a3': &mut A
794 129..133 'a3.b': B 795 129..133 'a3.b': B
795 143..145 'a4': &&&&&&&A 796 143..145 'a4': &&&&&&&A
796 148..156 '&&&&&&&a': &&&&&&&A 797 148..156 '&&&&&&&a': &&&&&&&A
797 149..156 '&&&&&&a': &&&&&&A 798 149..156 '&&&&&&a': &&&&&&A
798 150..156 '&&&&&a': &&&&&A 799 150..156 '&&&&&a': &&&&&A
799 151..156 '&&&&a': &&&&A 800 151..156 '&&&&a': &&&&A
800 152..156 '&&&a': &&&A 801 152..156 '&&&a': &&&A
801 153..156 '&&a': &&A 802 153..156 '&&a': &&A
802 154..156 '&a': &A 803 154..156 '&a': &A
803 155..156 'a': A 804 155..156 'a': A
804 162..164 'a4': &&&&&&&A 805 162..164 'a4': &&&&&&&A
805 162..166 'a4.b': B 806 162..166 'a4.b': B
806 176..178 'a5': &mut &&mut &&mut A 807 176..178 'a5': &mut &&mut &&mut A
807 181..199 '&mut &...&mut a': &mut &&mut &&mut A 808 181..199 '&mut &...&mut a': &mut &&mut &&mut A
808 186..199 '&&mut &&mut a': &&mut &&mut A 809 186..199 '&&mut &&mut a': &&mut &&mut A
809 187..199 '&mut &&mut a': &mut &&mut A 810 187..199 '&mut &&mut a': &mut &&mut A
810 192..199 '&&mut a': &&mut A 811 192..199 '&&mut a': &&mut A
811 193..199 '&mut a': &mut A 812 193..199 '&mut a': &mut A
812 198..199 'a': A 813 198..199 'a': A
813 205..207 'a5': &mut &&mut &&mut A 814 205..207 'a5': &mut &&mut &&mut A
814 205..209 'a5.b': B 815 205..209 'a5.b': B
815 223..225 'a1': *const A 816 223..225 'a1': *const A
816 237..239 'a2': *mut A 817 237..239 'a2': *mut A
817 249..272 '{ ...2.b; }': () 818 249..272 '{ ...2.b; }': ()
818 255..257 'a1': *const A 819 255..257 'a1': *const A
819 255..259 'a1.b': B 820 255..259 'a1.b': B
820 265..267 'a2': *mut A 821 265..267 'a2': *mut A
821 265..269 'a2.b': B 822 265..269 'a2.b': B
822 "### 823 "#]],
823 ); 824 );
824} 825}
825 826
826#[test] 827#[test]
827fn infer_argument_autoderef() { 828fn infer_argument_autoderef() {
828 assert_snapshot!( 829 check_infer(
829 infer(r#" 830 r#"
830#[lang = "deref"] 831 #[lang = "deref"]
831pub trait Deref { 832 pub trait Deref {
832 type Target; 833 type Target;
833 fn deref(&self) -> &Self::Target; 834 fn deref(&self) -> &Self::Target;
834} 835 }
835 836
836struct A<T>(T); 837 struct A<T>(T);
837 838
838impl<T> A<T> { 839 impl<T> A<T> {
839 fn foo(&self) -> &T { 840 fn foo(&self) -> &T {
840 &self.0 841 &self.0
841 } 842 }
842} 843 }
843 844
844struct B<T>(T); 845 struct B<T>(T);
845 846
846impl<T> Deref for B<T> { 847 impl<T> Deref for B<T> {
847 type Target = T; 848 type Target = T;
848 fn deref(&self) -> &Self::Target { 849 fn deref(&self) -> &Self::Target {
849 &self.0 850 &self.0
850 } 851 }
851} 852 }
852 853
853fn test() { 854 fn test() {
854 let t = A::foo(&&B(B(A(42)))); 855 let t = A::foo(&&B(B(A(42))));
855} 856 }
856"#), 857 "#,
857 @r###" 858 expect![[r#"
858 67..71 'self': &Self 859 67..71 'self': &Self
859 138..142 'self': &A<T> 860 138..142 'self': &A<T>
860 150..173 '{ ... }': &T 861 150..173 '{ ... }': &T
861 160..167 '&self.0': &T 862 160..167 '&self.0': &T
862 161..165 'self': &A<T> 863 161..165 'self': &A<T>
863 161..167 'self.0': T 864 161..167 'self.0': T
864 254..258 'self': &B<T> 865 254..258 'self': &B<T>
865 277..300 '{ ... }': &T 866 277..300 '{ ... }': &T
866 287..294 '&self.0': &T 867 287..294 '&self.0': &T
867 288..292 'self': &B<T> 868 288..292 'self': &B<T>
868 288..294 'self.0': T 869 288..294 'self.0': T
869 314..352 '{ ...))); }': () 870 314..352 '{ ...))); }': ()
870 324..325 't': &i32 871 324..325 't': &i32
871 328..334 'A::foo': fn foo<i32>(&A<i32>) -> &i32 872 328..334 'A::foo': fn foo<i32>(&A<i32>) -> &i32
872 328..349 'A::foo...42))))': &i32 873 328..349 'A::foo...42))))': &i32
873 335..348 '&&B(B(A(42)))': &&B<B<A<i32>>> 874 335..348 '&&B(B(A(42)))': &&B<B<A<i32>>>
874 336..348 '&B(B(A(42)))': &B<B<A<i32>>> 875 336..348 '&B(B(A(42)))': &B<B<A<i32>>>
875 337..338 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> 876 337..338 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
876 337..348 'B(B(A(42)))': B<B<A<i32>>> 877 337..348 'B(B(A(42)))': B<B<A<i32>>>
877 339..340 'B': B<A<i32>>(A<i32>) -> B<A<i32>> 878 339..340 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
878 339..347 'B(A(42))': B<A<i32>> 879 339..347 'B(A(42))': B<A<i32>>
879 341..342 'A': A<i32>(i32) -> A<i32> 880 341..342 'A': A<i32>(i32) -> A<i32>
880 341..346 'A(42)': A<i32> 881 341..346 'A(42)': A<i32>
881 343..345 '42': i32 882 343..345 '42': i32
882 "### 883 "#]],
883 ); 884 );
884} 885}
885 886
886#[test] 887#[test]
887fn infer_method_argument_autoderef() { 888fn infer_method_argument_autoderef() {
888 assert_snapshot!( 889 check_infer(
889 infer(r#" 890 r#"
890#[lang = "deref"] 891 #[lang = "deref"]
891pub trait Deref { 892 pub trait Deref {
892 type Target; 893 type Target;
893 fn deref(&self) -> &Self::Target; 894 fn deref(&self) -> &Self::Target;
894} 895 }
895 896
896struct A<T>(*mut T); 897 struct A<T>(*mut T);
897 898
898impl<T> A<T> { 899 impl<T> A<T> {
899 fn foo(&self, x: &A<T>) -> &T { 900 fn foo(&self, x: &A<T>) -> &T {
900 &*x.0 901 &*x.0
901 } 902 }
902} 903 }
903 904
904struct B<T>(T); 905 struct B<T>(T);
905 906
906impl<T> Deref for B<T> { 907 impl<T> Deref for B<T> {
907 type Target = T; 908 type Target = T;
908 fn deref(&self) -> &Self::Target { 909 fn deref(&self) -> &Self::Target {
909 &self.0 910 &self.0
910 } 911 }
911} 912 }
912 913
913fn test(a: A<i32>) { 914 fn test(a: A<i32>) {
914 let t = A(0 as *mut _).foo(&&B(B(a))); 915 let t = A(0 as *mut _).foo(&&B(B(a)));
915} 916 }
916"#), 917 "#,
917 @r###" 918 expect![[r#"
918 67..71 'self': &Self 919 67..71 'self': &Self
919 143..147 'self': &A<T> 920 143..147 'self': &A<T>
920 149..150 'x': &A<T> 921 149..150 'x': &A<T>
921 165..186 '{ ... }': &T 922 165..186 '{ ... }': &T
922 175..180 '&*x.0': &T 923 175..180 '&*x.0': &T
923 176..180 '*x.0': T 924 176..180 '*x.0': T
924 177..178 'x': &A<T> 925 177..178 'x': &A<T>
925 177..180 'x.0': *mut T 926 177..180 'x.0': *mut T
926 267..271 'self': &B<T> 927 267..271 'self': &B<T>
927 290..313 '{ ... }': &T 928 290..313 '{ ... }': &T
928 300..307 '&self.0': &T 929 300..307 '&self.0': &T
929 301..305 'self': &B<T> 930 301..305 'self': &B<T>
930 301..307 'self.0': T 931 301..307 'self.0': T
931 325..326 'a': A<i32> 932 325..326 'a': A<i32>
932 336..382 '{ ...))); }': () 933 336..382 '{ ...))); }': ()
933 346..347 't': &i32 934 346..347 't': &i32
934 350..351 'A': A<i32>(*mut i32) -> A<i32> 935 350..351 'A': A<i32>(*mut i32) -> A<i32>
935 350..364 'A(0 as *mut _)': A<i32> 936 350..364 'A(0 as *mut _)': A<i32>
936 350..379 'A(0 as...B(a)))': &i32 937 350..379 'A(0 as...B(a)))': &i32
937 352..353 '0': i32 938 352..353 '0': i32
938 352..363 '0 as *mut _': *mut i32 939 352..363 '0 as *mut _': *mut i32
939 369..378 '&&B(B(a))': &&B<B<A<i32>>> 940 369..378 '&&B(B(a))': &&B<B<A<i32>>>
940 370..378 '&B(B(a))': &B<B<A<i32>>> 941 370..378 '&B(B(a))': &B<B<A<i32>>>
941 371..372 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> 942 371..372 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
942 371..378 'B(B(a))': B<B<A<i32>>> 943 371..378 'B(B(a))': B<B<A<i32>>>
943 373..374 'B': B<A<i32>>(A<i32>) -> B<A<i32>> 944 373..374 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
944 373..377 'B(a)': B<A<i32>> 945 373..377 'B(a)': B<A<i32>>
945 375..376 'a': A<i32> 946 375..376 'a': A<i32>
946 "### 947 "#]],
947 ); 948 );
948} 949}
949 950
950#[test] 951#[test]
951fn infer_in_elseif() { 952fn infer_in_elseif() {
952 assert_snapshot!( 953 check_infer(
953 infer(r#" 954 r#"
954struct Foo { field: i32 } 955 struct Foo { field: i32 }
955fn main(foo: Foo) { 956 fn main(foo: Foo) {
956 if true { 957 if true {
957 958
958 } else if false { 959 } else if false {
959 foo.field 960 foo.field
960 } 961 }
961} 962 }
962"#), 963 "#,
963 @r###" 964 expect![[r#"
964 34..37 'foo': Foo 965 34..37 'foo': Foo
965 44..108 '{ ... } }': () 966 44..108 '{ ... } }': ()
966 50..106 'if tru... }': () 967 50..106 'if tru... }': ()
967 53..57 'true': bool 968 53..57 'true': bool
968 58..66 '{ }': () 969 58..66 '{ }': ()
969 72..106 'if fal... }': i32 970 72..106 'if fal... }': i32
970 75..80 'false': bool 971 75..80 'false': bool
971 81..106 '{ ... }': i32 972 81..106 '{ ... }': i32
972 91..94 'foo': Foo 973 91..94 'foo': Foo
973 91..100 'foo.field': i32 974 91..100 'foo.field': i32
974 "### 975 "#]],
975 ) 976 )
976} 977}
977 978
978#[test] 979#[test]
979fn infer_if_match_with_return() { 980fn infer_if_match_with_return() {
980 assert_snapshot!( 981 check_infer(
981 infer(r#" 982 r#"
982fn foo() { 983 fn foo() {
983 let _x1 = if true { 984 let _x1 = if true {
984 1 985 1
985 } else { 986 } else {
986 return; 987 return;
987 }; 988 };
988 let _x2 = if true { 989 let _x2 = if true {
989 2 990 2
990 } else { 991 } else {
991 return 992 return
992 }; 993 };
993 let _x3 = match true { 994 let _x3 = match true {
994 true => 3, 995 true => 3,
995 _ => { 996 _ => {
996 return; 997 return;
997 } 998 }
998 }; 999 };
999 let _x4 = match true { 1000 let _x4 = match true {
1000 true => 4, 1001 true => 4,
1001 _ => return 1002 _ => return
1002 }; 1003 };
1003}"#), 1004 }"#,
1004 @r###" 1005 expect![[r#"
1005 9..322 '{ ... }; }': () 1006 9..322 '{ ... }; }': ()
1006 19..22 '_x1': i32 1007 19..22 '_x1': i32
1007 25..79 'if tru... }': i32 1008 25..79 'if tru... }': i32
1008 28..32 'true': bool 1009 28..32 'true': bool
1009 33..50 '{ ... }': i32 1010 33..50 '{ ... }': i32
1010 43..44 '1': i32 1011 43..44 '1': i32
1011 56..79 '{ ... }': i32 1012 56..79 '{ ... }': i32
1012 66..72 'return': ! 1013 66..72 'return': !
1013 89..92 '_x2': i32 1014 89..92 '_x2': i32
1014 95..148 'if tru... }': i32 1015 95..148 'if tru... }': i32
1015 98..102 'true': bool 1016 98..102 'true': bool
1016 103..120 '{ ... }': i32 1017 103..120 '{ ... }': i32
1017 113..114 '2': i32 1018 113..114 '2': i32
1018 126..148 '{ ... }': ! 1019 126..148 '{ ... }': !
1019 136..142 'return': ! 1020 136..142 'return': !
1020 158..161 '_x3': i32 1021 158..161 '_x3': i32
1021 164..246 'match ... }': i32 1022 164..246 'match ... }': i32
1022 170..174 'true': bool 1023 170..174 'true': bool
1023 185..189 'true': bool 1024 185..189 'true': bool
1024 185..189 'true': bool 1025 185..189 'true': bool
1025 193..194 '3': i32 1026 193..194 '3': i32
1026 204..205 '_': bool 1027 204..205 '_': bool
1027 209..240 '{ ... }': i32 1028 209..240 '{ ... }': i32
1028 223..229 'return': ! 1029 223..229 'return': !
1029 256..259 '_x4': i32 1030 256..259 '_x4': i32
1030 262..319 'match ... }': i32 1031 262..319 'match ... }': i32
1031 268..272 'true': bool 1032 268..272 'true': bool
1032 283..287 'true': bool 1033 283..287 'true': bool
1033 283..287 'true': bool 1034 283..287 'true': bool
1034 291..292 '4': i32 1035 291..292 '4': i32
1035 302..303 '_': bool 1036 302..303 '_': bool
1036 307..313 'return': ! 1037 307..313 'return': !
1037 "### 1038 "#]],
1038 ) 1039 )
1039} 1040}
1040 1041
1041#[test] 1042#[test]
1042fn infer_inherent_method() { 1043fn infer_inherent_method() {
1043 assert_snapshot!( 1044 check_infer(
1044 infer(r#" 1045 r#"
1045struct A; 1046 struct A;
1046 1047
1047impl A { 1048 impl A {
1048 fn foo(self, x: u32) -> i32 {} 1049 fn foo(self, x: u32) -> i32 {}
1049} 1050 }
1050 1051
1051mod b { 1052 mod b {
1052 impl super::A { 1053 impl super::A {
1053 fn bar(&self, x: u64) -> i64 {} 1054 fn bar(&self, x: u64) -> i64 {}
1054 } 1055 }
1055} 1056 }
1056 1057
1057fn test(a: A) { 1058 fn test(a: A) {
1058 a.foo(1); 1059 a.foo(1);
1059 (&a).bar(1); 1060 (&a).bar(1);
1060 a.bar(1); 1061 a.bar(1);
1061} 1062 }
1062"#), 1063 "#,
1063 @r###" 1064 expect![[r#"
1064 31..35 'self': A 1065 31..35 'self': A
1065 37..38 'x': u32 1066 37..38 'x': u32
1066 52..54 '{}': () 1067 52..54 '{}': ()
1067 102..106 'self': &A 1068 102..106 'self': &A
1068 108..109 'x': u64 1069 108..109 'x': u64
1069 123..125 '{}': () 1070 123..125 '{}': ()
1070 143..144 'a': A 1071 143..144 'a': A
1071 149..197 '{ ...(1); }': () 1072 149..197 '{ ...(1); }': ()
1072 155..156 'a': A 1073 155..156 'a': A
1073 155..163 'a.foo(1)': i32 1074 155..163 'a.foo(1)': i32
1074 161..162 '1': u32 1075 161..162 '1': u32
1075 169..180 '(&a).bar(1)': i64 1076 169..180 '(&a).bar(1)': i64
1076 170..172 '&a': &A 1077 170..172 '&a': &A
1077 171..172 'a': A 1078 171..172 'a': A
1078 178..179 '1': u64 1079 178..179 '1': u64
1079 186..187 'a': A 1080 186..187 'a': A
1080 186..194 'a.bar(1)': i64 1081 186..194 'a.bar(1)': i64
1081 192..193 '1': u64 1082 192..193 '1': u64
1082 "### 1083 "#]],
1083 ); 1084 );
1084} 1085}
1085 1086
1086#[test] 1087#[test]
1087fn infer_inherent_method_str() { 1088fn infer_inherent_method_str() {
1088 assert_snapshot!( 1089 check_infer(
1089 infer(r#" 1090 r#"
1090#[lang = "str"] 1091 #[lang = "str"]
1091impl str { 1092 impl str {
1092 fn foo(&self) -> i32 {} 1093 fn foo(&self) -> i32 {}
1093} 1094 }
1094 1095
1095fn test() { 1096 fn test() {
1096 "foo".foo(); 1097 "foo".foo();
1097} 1098 }
1098"#), 1099 "#,
1099 @r###" 1100 expect![[r#"
1100 39..43 'self': &str 1101 39..43 'self': &str
1101 52..54 '{}': () 1102 52..54 '{}': ()
1102 68..88 '{ ...o(); }': () 1103 68..88 '{ ...o(); }': ()
1103 74..79 '"foo"': &str 1104 74..79 '"foo"': &str
1104 74..85 '"foo".foo()': i32 1105 74..85 '"foo".foo()': i32
1105 "### 1106 "#]],
1106 ); 1107 );
1107} 1108}
1108 1109
1109#[test] 1110#[test]
1110fn infer_tuple() { 1111fn infer_tuple() {
1111 assert_snapshot!( 1112 check_infer(
1112 infer(r#" 1113 r#"
1113fn test(x: &str, y: isize) { 1114 fn test(x: &str, y: isize) {
1114 let a: (u32, &str) = (1, "a"); 1115 let a: (u32, &str) = (1, "a");
1115 let b = (a, x); 1116 let b = (a, x);
1116 let c = (y, x); 1117 let c = (y, x);
1117 let d = (c, x); 1118 let d = (c, x);
1118 let e = (1, "e"); 1119 let e = (1, "e");
1119 let f = (e, "d"); 1120 let f = (e, "d");
1120} 1121 }
1121"#), 1122 "#,
1122 @r###" 1123 expect![[r#"
1123 8..9 'x': &str 1124 8..9 'x': &str
1124 17..18 'y': isize 1125 17..18 'y': isize
1125 27..169 '{ ...d"); }': () 1126 27..169 '{ ...d"); }': ()
1126 37..38 'a': (u32, &str) 1127 37..38 'a': (u32, &str)
1127 54..62 '(1, "a")': (u32, &str) 1128 54..62 '(1, "a")': (u32, &str)
1128 55..56 '1': u32 1129 55..56 '1': u32
1129 58..61 '"a"': &str 1130 58..61 '"a"': &str
1130 72..73 'b': ((u32, &str), &str) 1131 72..73 'b': ((u32, &str), &str)
1131 76..82 '(a, x)': ((u32, &str), &str) 1132 76..82 '(a, x)': ((u32, &str), &str)
1132 77..78 'a': (u32, &str) 1133 77..78 'a': (u32, &str)
1133 80..81 'x': &str 1134 80..81 'x': &str
1134 92..93 'c': (isize, &str) 1135 92..93 'c': (isize, &str)
1135 96..102 '(y, x)': (isize, &str) 1136 96..102 '(y, x)': (isize, &str)
1136 97..98 'y': isize 1137 97..98 'y': isize
1137 100..101 'x': &str 1138 100..101 'x': &str
1138 112..113 'd': ((isize, &str), &str) 1139 112..113 'd': ((isize, &str), &str)
1139 116..122 '(c, x)': ((isize, &str), &str) 1140 116..122 '(c, x)': ((isize, &str), &str)
1140 117..118 'c': (isize, &str) 1141 117..118 'c': (isize, &str)
1141 120..121 'x': &str 1142 120..121 'x': &str
1142 132..133 'e': (i32, &str) 1143 132..133 'e': (i32, &str)
1143 136..144 '(1, "e")': (i32, &str) 1144 136..144 '(1, "e")': (i32, &str)
1144 137..138 '1': i32 1145 137..138 '1': i32
1145 140..143 '"e"': &str 1146 140..143 '"e"': &str
1146 154..155 'f': ((i32, &str), &str) 1147 154..155 'f': ((i32, &str), &str)
1147 158..166 '(e, "d")': ((i32, &str), &str) 1148 158..166 '(e, "d")': ((i32, &str), &str)
1148 159..160 'e': (i32, &str) 1149 159..160 'e': (i32, &str)
1149 162..165 '"d"': &str 1150 162..165 '"d"': &str
1150 "### 1151 "#]],
1151 ); 1152 );
1152} 1153}
1153 1154
1154#[test] 1155#[test]
1155fn infer_array() { 1156fn infer_array() {
1156 assert_snapshot!( 1157 check_infer(
1157 infer(r#" 1158 r#"
1158fn test(x: &str, y: isize) { 1159 fn test(x: &str, y: isize) {
1159 let a = [x]; 1160 let a = [x];
1160 let b = [a, a]; 1161 let b = [a, a];
1161 let c = [b, b]; 1162 let c = [b, b];
1162 1163
1163 let d = [y, 1, 2, 3]; 1164 let d = [y, 1, 2, 3];
1164 let d = [1, y, 2, 3]; 1165 let d = [1, y, 2, 3];
1165 let e = [y]; 1166 let e = [y];
1166 let f = [d, d]; 1167 let f = [d, d];
1167 let g = [e, e]; 1168 let g = [e, e];
1168 1169
1169 let h = [1, 2]; 1170 let h = [1, 2];
1170 let i = ["a", "b"]; 1171 let i = ["a", "b"];
1171 1172
1172 let b = [a, ["b"]]; 1173 let b = [a, ["b"]];
1173 let x: [u8; 0] = []; 1174 let x: [u8; 0] = [];
1174} 1175 }
1175"#), 1176 "#,
1176 @r###" 1177 expect![[r#"
1177 8..9 'x': &str 1178 8..9 'x': &str
1178 17..18 'y': isize 1179 17..18 'y': isize
1179 27..292 '{ ... []; }': () 1180 27..292 '{ ... []; }': ()
1180 37..38 'a': [&str; _] 1181 37..38 'a': [&str; _]
1181 41..44 '[x]': [&str; _] 1182 41..44 '[x]': [&str; _]
1182 42..43 'x': &str 1183 42..43 'x': &str
1183 54..55 'b': [[&str; _]; _] 1184 54..55 'b': [[&str; _]; _]
1184 58..64 '[a, a]': [[&str; _]; _] 1185 58..64 '[a, a]': [[&str; _]; _]
1185 59..60 'a': [&str; _] 1186 59..60 'a': [&str; _]
1186 62..63 'a': [&str; _] 1187 62..63 'a': [&str; _]
1187 74..75 'c': [[[&str; _]; _]; _] 1188 74..75 'c': [[[&str; _]; _]; _]
1188 78..84 '[b, b]': [[[&str; _]; _]; _] 1189 78..84 '[b, b]': [[[&str; _]; _]; _]
1189 79..80 'b': [[&str; _]; _] 1190 79..80 'b': [[&str; _]; _]
1190 82..83 'b': [[&str; _]; _] 1191 82..83 'b': [[&str; _]; _]
1191 95..96 'd': [isize; _] 1192 95..96 'd': [isize; _]
1192 99..111 '[y, 1, 2, 3]': [isize; _] 1193 99..111 '[y, 1, 2, 3]': [isize; _]
1193 100..101 'y': isize 1194 100..101 'y': isize
1194 103..104 '1': isize 1195 103..104 '1': isize
1195 106..107 '2': isize 1196 106..107 '2': isize
1196 109..110 '3': isize 1197 109..110 '3': isize
1197 121..122 'd': [isize; _] 1198 121..122 'd': [isize; _]
1198 125..137 '[1, y, 2, 3]': [isize; _] 1199 125..137 '[1, y, 2, 3]': [isize; _]
1199 126..127 '1': isize 1200 126..127 '1': isize
1200 129..130 'y': isize 1201 129..130 'y': isize
1201 132..133 '2': isize 1202 132..133 '2': isize
1202 135..136 '3': isize 1203 135..136 '3': isize
1203 147..148 'e': [isize; _] 1204 147..148 'e': [isize; _]
1204 151..154 '[y]': [isize; _] 1205 151..154 '[y]': [isize; _]
1205 152..153 'y': isize 1206 152..153 'y': isize
1206 164..165 'f': [[isize; _]; _] 1207 164..165 'f': [[isize; _]; _]
1207 168..174 '[d, d]': [[isize; _]; _] 1208 168..174 '[d, d]': [[isize; _]; _]
1208 169..170 'd': [isize; _] 1209 169..170 'd': [isize; _]
1209 172..173 'd': [isize; _] 1210 172..173 'd': [isize; _]
1210 184..185 'g': [[isize; _]; _] 1211 184..185 'g': [[isize; _]; _]
1211 188..194 '[e, e]': [[isize; _]; _] 1212 188..194 '[e, e]': [[isize; _]; _]
1212 189..190 'e': [isize; _] 1213 189..190 'e': [isize; _]
1213 192..193 'e': [isize; _] 1214 192..193 'e': [isize; _]
1214 205..206 'h': [i32; _] 1215 205..206 'h': [i32; _]
1215 209..215 '[1, 2]': [i32; _] 1216 209..215 '[1, 2]': [i32; _]
1216 210..211 '1': i32 1217 210..211 '1': i32
1217 213..214 '2': i32 1218 213..214 '2': i32
1218 225..226 'i': [&str; _] 1219 225..226 'i': [&str; _]
1219 229..239 '["a", "b"]': [&str; _] 1220 229..239 '["a", "b"]': [&str; _]
1220 230..233 '"a"': &str 1221 230..233 '"a"': &str
1221 235..238 '"b"': &str 1222 235..238 '"b"': &str
1222 250..251 'b': [[&str; _]; _] 1223 250..251 'b': [[&str; _]; _]
1223 254..264 '[a, ["b"]]': [[&str; _]; _] 1224 254..264 '[a, ["b"]]': [[&str; _]; _]
1224 255..256 'a': [&str; _] 1225 255..256 'a': [&str; _]
1225 258..263 '["b"]': [&str; _] 1226 258..263 '["b"]': [&str; _]
1226 259..262 '"b"': &str 1227 259..262 '"b"': &str
1227 274..275 'x': [u8; _] 1228 274..275 'x': [u8; _]
1228 287..289 '[]': [u8; _] 1229 287..289 '[]': [u8; _]
1229 "### 1230 "#]],
1230 ); 1231 );
1231} 1232}
1232 1233
1233#[test] 1234#[test]
1234fn infer_struct_generics() { 1235fn infer_struct_generics() {
1235 assert_snapshot!( 1236 check_infer(
1236 infer(r#" 1237 r#"
1237struct A<T> { 1238 struct A<T> {
1238 x: T, 1239 x: T,
1239} 1240 }
1240 1241
1241fn test(a1: A<u32>, i: i32) { 1242 fn test(a1: A<u32>, i: i32) {
1242 a1.x; 1243 a1.x;
1243 let a2 = A { x: i }; 1244 let a2 = A { x: i };
1244 a2.x; 1245 a2.x;
1245 let a3 = A::<i128> { x: 1 }; 1246 let a3 = A::<i128> { x: 1 };
1246 a3.x; 1247 a3.x;
1247} 1248 }
1248"#), 1249 "#,
1249 @r###" 1250 expect![[r#"
1250 35..37 'a1': A<u32> 1251 35..37 'a1': A<u32>
1251 47..48 'i': i32 1252 47..48 'i': i32
1252 55..146 '{ ...3.x; }': () 1253 55..146 '{ ...3.x; }': ()
1253 61..63 'a1': A<u32> 1254 61..63 'a1': A<u32>
1254 61..65 'a1.x': u32 1255 61..65 'a1.x': u32
1255 75..77 'a2': A<i32> 1256 75..77 'a2': A<i32>
1256 80..90 'A { x: i }': A<i32> 1257 80..90 'A { x: i }': A<i32>
1257 87..88 'i': i32 1258 87..88 'i': i32
1258 96..98 'a2': A<i32> 1259 96..98 'a2': A<i32>
1259 96..100 'a2.x': i32 1260 96..100 'a2.x': i32
1260 110..112 'a3': A<i128> 1261 110..112 'a3': A<i128>
1261 115..133 'A::<i1...x: 1 }': A<i128> 1262 115..133 'A::<i1...x: 1 }': A<i128>
1262 130..131 '1': i128 1263 130..131 '1': i128
1263 139..141 'a3': A<i128> 1264 139..141 'a3': A<i128>
1264 139..143 'a3.x': i128 1265 139..143 'a3.x': i128
1265 "### 1266 "#]],
1266 ); 1267 );
1267} 1268}
1268 1269
1269#[test] 1270#[test]
1270fn infer_tuple_struct_generics() { 1271fn infer_tuple_struct_generics() {
1271 assert_snapshot!( 1272 check_infer(
1272 infer(r#" 1273 r#"
1273struct A<T>(T); 1274 struct A<T>(T);
1274enum Option<T> { Some(T), None } 1275 enum Option<T> { Some(T), None }
1275use Option::*; 1276 use Option::*;
1276 1277
1277fn test() { 1278 fn test() {
1278 A(42); 1279 A(42);
1279 A(42u128); 1280 A(42u128);
1280 Some("x"); 1281 Some("x");
1281 Option::Some("x"); 1282 Option::Some("x");
1282 None; 1283 None;
1283 let x: Option<i64> = None; 1284 let x: Option<i64> = None;
1284} 1285 }
1285"#), 1286 "#,
1286 @r###" 1287 expect![[r#"
1287 75..183 '{ ...one; }': () 1288 75..183 '{ ...one; }': ()
1288 81..82 'A': A<i32>(i32) -> A<i32> 1289 81..82 'A': A<i32>(i32) -> A<i32>
1289 81..86 'A(42)': A<i32> 1290 81..86 'A(42)': A<i32>
1290 83..85 '42': i32 1291 83..85 '42': i32
1291 92..93 'A': A<u128>(u128) -> A<u128> 1292 92..93 'A': A<u128>(u128) -> A<u128>
1292 92..101 'A(42u128)': A<u128> 1293 92..101 'A(42u128)': A<u128>
1293 94..100 '42u128': u128 1294 94..100 '42u128': u128
1294 107..111 'Some': Some<&str>(&str) -> Option<&str> 1295 107..111 'Some': Some<&str>(&str) -> Option<&str>
1295 107..116 'Some("x")': Option<&str> 1296 107..116 'Some("x")': Option<&str>
1296 112..115 '"x"': &str 1297 112..115 '"x"': &str
1297 122..134 'Option::Some': Some<&str>(&str) -> Option<&str> 1298 122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
1298 122..139 'Option...e("x")': Option<&str> 1299 122..139 'Option...e("x")': Option<&str>
1299 135..138 '"x"': &str 1300 135..138 '"x"': &str
1300 145..149 'None': Option<{unknown}> 1301 145..149 'None': Option<{unknown}>
1301 159..160 'x': Option<i64> 1302 159..160 'x': Option<i64>
1302 176..180 'None': Option<i64> 1303 176..180 'None': Option<i64>
1303 "### 1304 "#]],
1304 ); 1305 );
1305} 1306}
1306 1307
1307#[test] 1308#[test]
1308fn infer_function_generics() { 1309fn infer_function_generics() {
1309 assert_snapshot!( 1310 check_infer(
1310 infer(r#" 1311 r#"
1311fn id<T>(t: T) -> T { t } 1312 fn id<T>(t: T) -> T { t }
1312 1313
1313fn test() { 1314 fn test() {
1314 id(1u32); 1315 id(1u32);
1315 id::<i128>(1); 1316 id::<i128>(1);
1316 let x: u64 = id(1); 1317 let x: u64 = id(1);
1317} 1318 }
1318"#), 1319 "#,
1319 @r###" 1320 expect![[r#"
1320 9..10 't': T 1321 9..10 't': T
1321 20..25 '{ t }': T 1322 20..25 '{ t }': T
1322 22..23 't': T 1323 22..23 't': T
1323 37..97 '{ ...(1); }': () 1324 37..97 '{ ...(1); }': ()
1324 43..45 'id': fn id<u32>(u32) -> u32 1325 43..45 'id': fn id<u32>(u32) -> u32
1325 43..51 'id(1u32)': u32 1326 43..51 'id(1u32)': u32
1326 46..50 '1u32': u32 1327 46..50 '1u32': u32
1327 57..67 'id::<i128>': fn id<i128>(i128) -> i128 1328 57..67 'id::<i128>': fn id<i128>(i128) -> i128
1328 57..70 'id::<i128>(1)': i128 1329 57..70 'id::<i128>(1)': i128
1329 68..69 '1': i128 1330 68..69 '1': i128
1330 80..81 'x': u64 1331 80..81 'x': u64
1331 89..91 'id': fn id<u64>(u64) -> u64 1332 89..91 'id': fn id<u64>(u64) -> u64
1332 89..94 'id(1)': u64 1333 89..94 'id(1)': u64
1333 92..93 '1': u64 1334 92..93 '1': u64
1334 "### 1335 "#]],
1335 ); 1336 );
1336} 1337}
1337 1338
1338#[test] 1339#[test]
1339fn infer_impl_generics_basic() { 1340fn infer_impl_generics_basic() {
1340 assert_snapshot!( 1341 check_infer(
1341 infer(r#" 1342 r#"
1342struct A<T1, T2> { 1343 struct A<T1, T2> {
1343 x: T1, 1344 x: T1,
1344 y: T2, 1345 y: T2,
1345} 1346 }
1346impl<Y, X> A<X, Y> { 1347 impl<Y, X> A<X, Y> {
1347 fn x(self) -> X { 1348 fn x(self) -> X {
1348 self.x 1349 self.x
1349 } 1350 }
1350 fn y(self) -> Y { 1351 fn y(self) -> Y {
1351 self.y 1352 self.y
1352 } 1353 }
1353 fn z<T>(self, t: T) -> (X, Y, T) { 1354 fn z<T>(self, t: T) -> (X, Y, T) {
1354 (self.x, self.y, t) 1355 (self.x, self.y, t)
1355 } 1356 }
1356} 1357 }
1357 1358
1358fn test() -> i128 { 1359 fn test() -> i128 {
1359 let a = A { x: 1u64, y: 1i64 }; 1360 let a = A { x: 1u64, y: 1i64 };
1360 a.x(); 1361 a.x();
1361 a.y(); 1362 a.y();
1362 a.z(1i128); 1363 a.z(1i128);
1363 a.z::<u128>(1); 1364 a.z::<u128>(1);
1364} 1365 }
1365"#), 1366 "#,
1366 @r###" 1367 expect![[r#"
1367 73..77 'self': A<X, Y> 1368 73..77 'self': A<X, Y>
1368 84..106 '{ ... }': X 1369 84..106 '{ ... }': X
1369 94..98 'self': A<X, Y> 1370 94..98 'self': A<X, Y>
1370 94..100 'self.x': X 1371 94..100 'self.x': X
1371 116..120 'self': A<X, Y> 1372 116..120 'self': A<X, Y>
1372 127..149 '{ ... }': Y 1373 127..149 '{ ... }': Y
1373 137..141 'self': A<X, Y> 1374 137..141 'self': A<X, Y>
1374 137..143 'self.y': Y 1375 137..143 'self.y': Y
1375 162..166 'self': A<X, Y> 1376 162..166 'self': A<X, Y>
1376 168..169 't': T 1377 168..169 't': T
1377 187..222 '{ ... }': (X, Y, T) 1378 187..222 '{ ... }': (X, Y, T)
1378 197..216 '(self.....y, t)': (X, Y, T) 1379 197..216 '(self.....y, t)': (X, Y, T)
1379 198..202 'self': A<X, Y> 1380 198..202 'self': A<X, Y>
1380 198..204 'self.x': X 1381 198..204 'self.x': X
1381 206..210 'self': A<X, Y> 1382 206..210 'self': A<X, Y>
1382 206..212 'self.y': Y 1383 206..212 'self.y': Y
1383 214..215 't': T 1384 214..215 't': T
1384 244..341 '{ ...(1); }': () 1385 244..341 '{ ...(1); }': ()
1385 254..255 'a': A<u64, i64> 1386 254..255 'a': A<u64, i64>
1386 258..280 'A { x:...1i64 }': A<u64, i64> 1387 258..280 'A { x:...1i64 }': A<u64, i64>
1387 265..269 '1u64': u64 1388 265..269 '1u64': u64
1388 274..278 '1i64': i64 1389 274..278 '1i64': i64
1389 286..287 'a': A<u64, i64> 1390 286..287 'a': A<u64, i64>
1390 286..291 'a.x()': u64 1391 286..291 'a.x()': u64
1391 297..298 'a': A<u64, i64> 1392 297..298 'a': A<u64, i64>
1392 297..302 'a.y()': i64 1393 297..302 'a.y()': i64
1393 308..309 'a': A<u64, i64> 1394 308..309 'a': A<u64, i64>
1394 308..318 'a.z(1i128)': (u64, i64, i128) 1395 308..318 'a.z(1i128)': (u64, i64, i128)
1395 312..317 '1i128': i128 1396 312..317 '1i128': i128
1396 324..325 'a': A<u64, i64> 1397 324..325 'a': A<u64, i64>
1397 324..338 'a.z::<u128>(1)': (u64, i64, u128) 1398 324..338 'a.z::<u128>(1)': (u64, i64, u128)
1398 336..337 '1': u128 1399 336..337 '1': u128
1399 "### 1400 "#]],
1400 ); 1401 );
1401} 1402}
1402 1403
1403#[test] 1404#[test]
1404fn infer_impl_generics_with_autoderef() { 1405fn infer_impl_generics_with_autoderef() {
1405 assert_snapshot!( 1406 check_infer(
1406 infer(r#" 1407 r#"
1407enum Option<T> { 1408 enum Option<T> {
1408 Some(T), 1409 Some(T),
1409 None, 1410 None,
1410} 1411 }
1411impl<T> Option<T> { 1412 impl<T> Option<T> {
1412 fn as_ref(&self) -> Option<&T> {} 1413 fn as_ref(&self) -> Option<&T> {}
1413} 1414 }
1414fn test(o: Option<u32>) { 1415 fn test(o: Option<u32>) {
1415 (&o).as_ref(); 1416 (&o).as_ref();
1416 o.as_ref(); 1417 o.as_ref();
1417} 1418 }
1418"#), 1419 "#,
1419 @r###" 1420 expect![[r#"
1420 77..81 'self': &Option<T> 1421 77..81 'self': &Option<T>
1421 97..99 '{}': () 1422 97..99 '{}': ()
1422 110..111 'o': Option<u32> 1423 110..111 'o': Option<u32>
1423 126..164 '{ ...f(); }': () 1424 126..164 '{ ...f(); }': ()
1424 132..145 '(&o).as_ref()': Option<&u32> 1425 132..145 '(&o).as_ref()': Option<&u32>
1425 133..135 '&o': &Option<u32> 1426 133..135 '&o': &Option<u32>
1426 134..135 'o': Option<u32> 1427 134..135 'o': Option<u32>
1427 151..152 'o': Option<u32> 1428 151..152 'o': Option<u32>
1428 151..161 'o.as_ref()': Option<&u32> 1429 151..161 'o.as_ref()': Option<&u32>
1429 "### 1430 "#]],
1430 ); 1431 );
1431} 1432}
1432 1433
1433#[test] 1434#[test]
1434fn infer_generic_chain() { 1435fn infer_generic_chain() {
1435 assert_snapshot!( 1436 check_infer(
1436 infer(r#" 1437 r#"
1437struct A<T> { 1438 struct A<T> {
1438 x: T, 1439 x: T,
1439} 1440 }
1440impl<T2> A<T2> { 1441 impl<T2> A<T2> {
1441 fn x(self) -> T2 { 1442 fn x(self) -> T2 {
1442 self.x 1443 self.x
1443 } 1444 }
1444} 1445 }
1445fn id<T>(t: T) -> T { t } 1446 fn id<T>(t: T) -> T { t }
1446 1447
1447fn test() -> i128 { 1448 fn test() -> i128 {
1448 let x = 1; 1449 let x = 1;
1449 let y = id(x); 1450 let y = id(x);
1450 let a = A { x: id(y) }; 1451 let a = A { x: id(y) };
1451 let z = id(a.x); 1452 let z = id(a.x);
1452 let b = A { x: z }; 1453 let b = A { x: z };
1453 b.x() 1454 b.x()
1454} 1455 }
1455"#), 1456 "#,
1456 @r###" 1457 expect![[r#"
1457 52..56 'self': A<T2> 1458 52..56 'self': A<T2>
1458 64..86 '{ ... }': T2 1459 64..86 '{ ... }': T2
1459 74..78 'self': A<T2> 1460 74..78 'self': A<T2>
1460 74..80 'self.x': T2 1461 74..80 'self.x': T2
1461 98..99 't': T 1462 98..99 't': T
1462 109..114 '{ t }': T 1463 109..114 '{ t }': T
1463 111..112 't': T 1464 111..112 't': T
1464 134..260 '{ ....x() }': i128 1465 134..254 '{ ....x() }': i128
1465 145..146 'x': i128 1466 144..145 'x': i128
1466 149..150 '1': i128 1467 148..149 '1': i128
1467 161..162 'y': i128 1468 159..160 'y': i128
1468 165..167 'id': fn id<i128>(i128) -> i128 1469 163..165 'id': fn id<i128>(i128) -> i128
1469 165..170 'id(x)': i128 1470 163..168 'id(x)': i128
1470 168..169 'x': i128 1471 166..167 'x': i128
1471 181..182 'a': A<i128> 1472 178..179 'a': A<i128>
1472 185..199 'A { x: id(y) }': A<i128> 1473 182..196 'A { x: id(y) }': A<i128>
1473 192..194 'id': fn id<i128>(i128) -> i128 1474 189..191 'id': fn id<i128>(i128) -> i128
1474 192..197 'id(y)': i128 1475 189..194 'id(y)': i128
1475 195..196 'y': i128 1476 192..193 'y': i128
1476 210..211 'z': i128 1477 206..207 'z': i128
1477 214..216 'id': fn id<i128>(i128) -> i128 1478 210..212 'id': fn id<i128>(i128) -> i128
1478 214..221 'id(a.x)': i128 1479 210..217 'id(a.x)': i128
1479 217..218 'a': A<i128> 1480 213..214 'a': A<i128>
1480 217..220 'a.x': i128 1481 213..216 'a.x': i128
1481 232..233 'b': A<i128> 1482 227..228 'b': A<i128>
1482 236..246 'A { x: z }': A<i128> 1483 231..241 'A { x: z }': A<i128>
1483 243..244 'z': i128 1484 238..239 'z': i128
1484 253..254 'b': A<i128> 1485 247..248 'b': A<i128>
1485 253..258 'b.x()': i128 1486 247..252 'b.x()': i128
1486 "### 1487 "#]],
1487 ); 1488 );
1488} 1489}
1489 1490
1490#[test] 1491#[test]
1491fn infer_associated_const() { 1492fn infer_associated_const() {
1492 assert_snapshot!( 1493 check_infer(
1493 infer(r#" 1494 r#"
1494struct Struct; 1495 struct Struct;
1495 1496
1496impl Struct { 1497 impl Struct {
1497 const FOO: u32 = 1; 1498 const FOO: u32 = 1;
1498} 1499 }
1499 1500
1500enum Enum {} 1501 enum Enum {}
1501 1502
1502impl Enum { 1503 impl Enum {
1503 const BAR: u32 = 2; 1504 const BAR: u32 = 2;
1504} 1505 }
1505 1506
1506trait Trait { 1507 trait Trait {
1507 const ID: u32; 1508 const ID: u32;
1508} 1509 }
1509 1510
1510struct TraitTest; 1511 struct TraitTest;
1511 1512
1512impl Trait for TraitTest { 1513 impl Trait for TraitTest {
1513 const ID: u32 = 5; 1514 const ID: u32 = 5;
1514} 1515 }
1515 1516
1516fn test() { 1517 fn test() {
1517 let x = Struct::FOO; 1518 let x = Struct::FOO;
1518 let y = Enum::BAR; 1519 let y = Enum::BAR;
1519 let z = TraitTest::ID; 1520 let z = TraitTest::ID;
1520} 1521 }
1521"#), 1522 "#,
1522 @r###" 1523 expect![[r#"
1523 51..52 '1': u32 1524 51..52 '1': u32
1524 104..105 '2': u32 1525 104..105 '2': u32
1525 212..213 '5': u32 1526 212..213 '5': u32
1526 228..306 '{ ...:ID; }': () 1527 228..306 '{ ...:ID; }': ()
1527 238..239 'x': u32 1528 238..239 'x': u32
1528 242..253 'Struct::FOO': u32 1529 242..253 'Struct::FOO': u32
1529 263..264 'y': u32 1530 263..264 'y': u32
1530 267..276 'Enum::BAR': u32 1531 267..276 'Enum::BAR': u32
1531 286..287 'z': u32 1532 286..287 'z': u32
1532 290..303 'TraitTest::ID': u32 1533 290..303 'TraitTest::ID': u32
1533 "### 1534 "#]],
1534 ); 1535 );
1535} 1536}
1536 1537
1537#[test] 1538#[test]
1538fn infer_type_alias() { 1539fn infer_type_alias() {
1539 assert_snapshot!( 1540 check_infer(
1540 infer(r#" 1541 r#"
1541struct A<X, Y> { x: X, y: Y } 1542 struct A<X, Y> { x: X, y: Y }
1542type Foo = A<u32, i128>; 1543 type Foo = A<u32, i128>;
1543type Bar<T> = A<T, u128>; 1544 type Bar<T> = A<T, u128>;
1544type Baz<U, V> = A<V, U>; 1545 type Baz<U, V> = A<V, U>;
1545fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) { 1546 fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
1546 x.x; 1547 x.x;
1547 x.y; 1548 x.y;
1548 y.x; 1549 y.x;
1549 y.y; 1550 y.y;
1550 z.x; 1551 z.x;
1551 z.y; 1552 z.y;
1552} 1553 }
1553"#), 1554 "#,
1554 @r###" 1555 expect![[r#"
1555 115..116 'x': A<u32, i128> 1556 115..116 'x': A<u32, i128>
1556 123..124 'y': A<&str, u128> 1557 123..124 'y': A<&str, u128>
1557 137..138 'z': A<u8, i8> 1558 137..138 'z': A<u8, i8>
1558 153..210 '{ ...z.y; }': () 1559 153..210 '{ ...z.y; }': ()
1559 159..160 'x': A<u32, i128> 1560 159..160 'x': A<u32, i128>
1560 159..162 'x.x': u32 1561 159..162 'x.x': u32
1561 168..169 'x': A<u32, i128> 1562 168..169 'x': A<u32, i128>
1562 168..171 'x.y': i128 1563 168..171 'x.y': i128
1563 177..178 'y': A<&str, u128> 1564 177..178 'y': A<&str, u128>
1564 177..180 'y.x': &str 1565 177..180 'y.x': &str
1565 186..187 'y': A<&str, u128> 1566 186..187 'y': A<&str, u128>
1566 186..189 'y.y': u128 1567 186..189 'y.y': u128
1567 195..196 'z': A<u8, i8> 1568 195..196 'z': A<u8, i8>
1568 195..198 'z.x': u8 1569 195..198 'z.x': u8
1569 204..205 'z': A<u8, i8> 1570 204..205 'z': A<u8, i8>
1570 204..207 'z.y': i8 1571 204..207 'z.y': i8
1571 "### 1572 "#]],
1572 ) 1573 )
1573} 1574}
1574 1575
1575#[test] 1576#[test]
1576fn recursive_type_alias() { 1577fn recursive_type_alias() {
1577 assert_snapshot!( 1578 check_infer(
1578 infer(r#" 1579 r#"
1579struct A<X> {} 1580 struct A<X> {}
1580type Foo = Foo; 1581 type Foo = Foo;
1581type Bar = A<Bar>; 1582 type Bar = A<Bar>;
1582fn test(x: Foo) {} 1583 fn test(x: Foo) {}
1583"#), 1584 "#,
1584 @r###" 1585 expect![[r#"
1585 58..59 'x': {unknown} 1586 58..59 'x': {unknown}
1586 66..68 '{}': () 1587 66..68 '{}': ()
1587 "### 1588 "#]],
1588 ) 1589 )
1589} 1590}
1590 1591
1591#[test] 1592#[test]
1592fn infer_type_param() { 1593fn infer_type_param() {
1593 assert_snapshot!( 1594 check_infer(
1594 infer(r#" 1595 r#"
1595fn id<T>(x: T) -> T { 1596 fn id<T>(x: T) -> T {
1596 x 1597 x
1597} 1598 }
1598 1599
1599fn clone<T>(x: &T) -> T { 1600 fn clone<T>(x: &T) -> T {
1600 *x 1601 *x
1601} 1602 }
1602 1603
1603fn test() { 1604 fn test() {
1604 let y = 10u32; 1605 let y = 10u32;
1605 id(y); 1606 id(y);
1606 let x: bool = clone(z); 1607 let x: bool = clone(z);
1607 id::<i128>(1); 1608 id::<i128>(1);
1608} 1609 }
1609"#), 1610 "#,
1610 @r###" 1611 expect![[r#"
1611 9..10 'x': T 1612 9..10 'x': T
1612 20..29 '{ x }': T 1613 20..29 '{ x }': T
1613 26..27 'x': T 1614 26..27 'x': T
1614 43..44 'x': &T 1615 43..44 'x': &T
1615 55..65 '{ *x }': T 1616 55..65 '{ *x }': T
1616 61..63 '*x': T 1617 61..63 '*x': T
1617 62..63 'x': &T 1618 62..63 'x': &T
1618 77..157 '{ ...(1); }': () 1619 77..157 '{ ...(1); }': ()
1619 87..88 'y': u32 1620 87..88 'y': u32
1620 91..96 '10u32': u32 1621 91..96 '10u32': u32
1621 102..104 'id': fn id<u32>(u32) -> u32 1622 102..104 'id': fn id<u32>(u32) -> u32
1622 102..107 'id(y)': u32 1623 102..107 'id(y)': u32
1623 105..106 'y': u32 1624 105..106 'y': u32
1624 117..118 'x': bool 1625 117..118 'x': bool
1625 127..132 'clone': fn clone<bool>(&bool) -> bool 1626 127..132 'clone': fn clone<bool>(&bool) -> bool
1626 127..135 'clone(z)': bool 1627 127..135 'clone(z)': bool
1627 133..134 'z': &bool 1628 133..134 'z': &bool
1628 141..151 'id::<i128>': fn id<i128>(i128) -> i128 1629 141..151 'id::<i128>': fn id<i128>(i128) -> i128
1629 141..154 'id::<i128>(1)': i128 1630 141..154 'id::<i128>(1)': i128
1630 152..153 '1': i128 1631 152..153 '1': i128
1631 "### 1632 "#]],
1632 ); 1633 );
1633} 1634}
1634 1635
1635#[test] 1636#[test]
1636fn infer_const() { 1637fn infer_const() {
1637 assert_snapshot!( 1638 check_infer(
1638 infer(r#" 1639 r#"
1639struct Foo; 1640 struct Foo;
1640impl Foo { const ASSOC_CONST: u32 = 0; } 1641 impl Foo { const ASSOC_CONST: u32 = 0; }
1641const GLOBAL_CONST: u32 = 101; 1642 const GLOBAL_CONST: u32 = 101;
1642fn test() { 1643 fn test() {
1643 const LOCAL_CONST: u32 = 99; 1644 const LOCAL_CONST: u32 = 99;
1644 let x = LOCAL_CONST; 1645 let x = LOCAL_CONST;
1645 let z = GLOBAL_CONST; 1646 let z = GLOBAL_CONST;
1646 let id = Foo::ASSOC_CONST; 1647 let id = Foo::ASSOC_CONST;
1647} 1648 }
1648"#), 1649 "#,
1649 @r###" 1650 expect![[r#"
1650 48..49 '0': u32 1651 48..49 '0': u32
1651 79..82 '101': u32 1652 79..82 '101': u32
1652 94..212 '{ ...NST; }': () 1653 94..212 '{ ...NST; }': ()
1653 137..138 'x': u32 1654 137..138 'x': u32
1654 141..152 'LOCAL_CONST': u32 1655 141..152 'LOCAL_CONST': u32
1655 162..163 'z': u32 1656 162..163 'z': u32
1656 166..178 'GLOBAL_CONST': u32 1657 166..178 'GLOBAL_CONST': u32
1657 188..190 'id': u32 1658 188..190 'id': u32
1658 193..209 'Foo::A..._CONST': u32 1659 193..209 'Foo::A..._CONST': u32
1659 125..127 '99': u32 1660 125..127 '99': u32
1660 "### 1661 "#]],
1661 ); 1662 );
1662} 1663}
1663 1664
1664#[test] 1665#[test]
1665fn infer_static() { 1666fn infer_static() {
1666 assert_snapshot!( 1667 check_infer(
1667 infer(r#" 1668 r#"
1668static GLOBAL_STATIC: u32 = 101; 1669 static GLOBAL_STATIC: u32 = 101;
1669static mut GLOBAL_STATIC_MUT: u32 = 101; 1670 static mut GLOBAL_STATIC_MUT: u32 = 101;
1670fn test() { 1671 fn test() {
1671 static LOCAL_STATIC: u32 = 99; 1672 static LOCAL_STATIC: u32 = 99;
1672 static mut LOCAL_STATIC_MUT: u32 = 99; 1673 static mut LOCAL_STATIC_MUT: u32 = 99;
1673 let x = LOCAL_STATIC; 1674 let x = LOCAL_STATIC;
1674 let y = LOCAL_STATIC_MUT; 1675 let y = LOCAL_STATIC_MUT;
1675 let z = GLOBAL_STATIC; 1676 let z = GLOBAL_STATIC;
1676 let w = GLOBAL_STATIC_MUT; 1677 let w = GLOBAL_STATIC_MUT;
1677} 1678 }
1678"#), 1679 "#,
1679 @r###" 1680 expect![[r#"
1680 28..31 '101': u32 1681 28..31 '101': u32
1681 69..72 '101': u32 1682 69..72 '101': u32
1682 84..279 '{ ...MUT; }': () 1683 84..279 '{ ...MUT; }': ()
1683 172..173 'x': u32 1684 172..173 'x': u32
1684 176..188 'LOCAL_STATIC': u32 1685 176..188 'LOCAL_STATIC': u32
1685 198..199 'y': u32 1686 198..199 'y': u32
1686 202..218 'LOCAL_...IC_MUT': u32 1687 202..218 'LOCAL_...IC_MUT': u32
1687 228..229 'z': u32 1688 228..229 'z': u32
1688 232..245 'GLOBAL_STATIC': u32 1689 232..245 'GLOBAL_STATIC': u32
1689 255..256 'w': u32 1690 255..256 'w': u32
1690 259..276 'GLOBAL...IC_MUT': u32 1691 259..276 'GLOBAL...IC_MUT': u32
1691 117..119 '99': u32 1692 117..119 '99': u32
1692 160..162 '99': u32 1693 160..162 '99': u32
1693 "### 1694 "#]],
1694 ); 1695 );
1695} 1696}
1696 1697
@@ -1777,413 +1778,413 @@ fn main() {
1777 1778
1778#[test] 1779#[test]
1779fn closure_return() { 1780fn closure_return() {
1780 assert_snapshot!( 1781 check_infer(
1781 infer(r#" 1782 r#"
1782fn foo() -> u32 { 1783 fn foo() -> u32 {
1783 let x = || -> usize { return 1; }; 1784 let x = || -> usize { return 1; };
1784} 1785 }
1785"#), 1786 "#,
1786 @r###" 1787 expect![[r#"
1787 16..58 '{ ...; }; }': () 1788 16..58 '{ ...; }; }': ()
1788 26..27 'x': || -> usize 1789 26..27 'x': || -> usize
1789 30..55 '|| -> ...n 1; }': || -> usize 1790 30..55 '|| -> ...n 1; }': || -> usize
1790 42..55 '{ return 1; }': usize 1791 42..55 '{ return 1; }': usize
1791 44..52 'return 1': ! 1792 44..52 'return 1': !
1792 51..52 '1': usize 1793 51..52 '1': usize
1793 "### 1794 "#]],
1794 ); 1795 );
1795} 1796}
1796 1797
1797#[test] 1798#[test]
1798fn closure_return_unit() { 1799fn closure_return_unit() {
1799 assert_snapshot!( 1800 check_infer(
1800 infer(r#" 1801 r#"
1801fn foo() -> u32 { 1802 fn foo() -> u32 {
1802 let x = || { return; }; 1803 let x = || { return; };
1803} 1804 }
1804"#), 1805 "#,
1805 @r###" 1806 expect![[r#"
1806 16..47 '{ ...; }; }': () 1807 16..47 '{ ...; }; }': ()
1807 26..27 'x': || -> () 1808 26..27 'x': || -> ()
1808 30..44 '|| { return; }': || -> () 1809 30..44 '|| { return; }': || -> ()
1809 33..44 '{ return; }': () 1810 33..44 '{ return; }': ()
1810 35..41 'return': ! 1811 35..41 'return': !
1811 "### 1812 "#]],
1812 ); 1813 );
1813} 1814}
1814 1815
1815#[test] 1816#[test]
1816fn closure_return_inferred() { 1817fn closure_return_inferred() {
1817 assert_snapshot!( 1818 check_infer(
1818 infer(r#" 1819 r#"
1819fn foo() -> u32 { 1820 fn foo() -> u32 {
1820 let x = || { "test" }; 1821 let x = || { "test" };
1821} 1822 }
1822"#), 1823 "#,
1823 @r###" 1824 expect![[r#"
1824 16..46 '{ ..." }; }': () 1825 16..46 '{ ..." }; }': ()
1825 26..27 'x': || -> &str 1826 26..27 'x': || -> &str
1826 30..43 '|| { "test" }': || -> &str 1827 30..43 '|| { "test" }': || -> &str
1827 33..43 '{ "test" }': &str 1828 33..43 '{ "test" }': &str
1828 35..41 '"test"': &str 1829 35..41 '"test"': &str
1829 "### 1830 "#]],
1830 ); 1831 );
1831} 1832}
1832 1833
1833#[test] 1834#[test]
1834fn fn_pointer_return() { 1835fn fn_pointer_return() {
1835 assert_snapshot!( 1836 check_infer(
1836 infer(r#" 1837 r#"
1837struct Vtable { 1838 struct Vtable {
1838 method: fn(), 1839 method: fn(),
1839} 1840 }
1840 1841
1841fn main() { 1842 fn main() {
1842 let vtable = Vtable { method: || {} }; 1843 let vtable = Vtable { method: || {} };
1843 let m = vtable.method; 1844 let m = vtable.method;
1844} 1845 }
1845"#), 1846 "#,
1846 @r###" 1847 expect![[r#"
1847 47..120 '{ ...hod; }': () 1848 47..120 '{ ...hod; }': ()
1848 57..63 'vtable': Vtable 1849 57..63 'vtable': Vtable
1849 66..90 'Vtable...| {} }': Vtable 1850 66..90 'Vtable...| {} }': Vtable
1850 83..88 '|| {}': || -> () 1851 83..88 '|| {}': || -> ()
1851 86..88 '{}': () 1852 86..88 '{}': ()
1852 100..101 'm': fn() 1853 100..101 'm': fn()
1853 104..110 'vtable': Vtable 1854 104..110 'vtable': Vtable
1854 104..117 'vtable.method': fn() 1855 104..117 'vtable.method': fn()
1855 "### 1856 "#]],
1856 ); 1857 );
1857} 1858}
1858 1859
1859#[test] 1860#[test]
1860fn effects_smoke_test() { 1861fn effects_smoke_test() {
1861 assert_snapshot!( 1862 check_infer(
1862 infer(r#" 1863 r#"
1863fn main() { 1864 fn main() {
1864 let x = unsafe { 92 }; 1865 let x = unsafe { 92 };
1865 let y = async { async { () }.await }; 1866 let y = async { async { () }.await };
1866 let z = try { () }; 1867 let z = try { () };
1867 let t = 'a: { 92 }; 1868 let t = 'a: { 92 };
1868} 1869 }
1869"#), 1870 "#,
1870 @r###" 1871 expect![[r#"
1871 10..130 '{ ...2 }; }': () 1872 10..130 '{ ...2 }; }': ()
1872 20..21 'x': i32 1873 20..21 'x': i32
1873 24..37 'unsafe { 92 }': i32 1874 24..37 'unsafe { 92 }': i32
1874 31..37 '{ 92 }': i32 1875 31..37 '{ 92 }': i32
1875 33..35 '92': i32 1876 33..35 '92': i32
1876 47..48 'y': {unknown} 1877 47..48 'y': {unknown}
1877 57..79 '{ asyn...wait }': {unknown} 1878 57..79 '{ asyn...wait }': {unknown}
1878 59..77 'async ....await': {unknown} 1879 59..77 'async ....await': {unknown}
1879 65..71 '{ () }': () 1880 65..71 '{ () }': ()
1880 67..69 '()': () 1881 67..69 '()': ()
1881 89..90 'z': {unknown} 1882 89..90 'z': {unknown}
1882 93..103 'try { () }': {unknown} 1883 93..103 'try { () }': {unknown}
1883 97..103 '{ () }': () 1884 97..103 '{ () }': ()
1884 99..101 '()': () 1885 99..101 '()': ()
1885 113..114 't': i32 1886 113..114 't': i32
1886 121..127 '{ 92 }': i32 1887 121..127 '{ 92 }': i32
1887 123..125 '92': i32 1888 123..125 '92': i32
1888 "### 1889 "#]],
1889 ) 1890 )
1890} 1891}
1891 1892
1892#[test] 1893#[test]
1893fn infer_generic_from_later_assignment() { 1894fn infer_generic_from_later_assignment() {
1894 assert_snapshot!( 1895 check_infer(
1895 infer(r#" 1896 r#"
1896enum Option<T> { Some(T), None } 1897 enum Option<T> { Some(T), None }
1897use Option::*; 1898 use Option::*;
1898 1899
1899fn test() { 1900 fn test() {
1900 let mut end = None; 1901 let mut end = None;
1901 loop { 1902 loop {
1902 end = Some(true); 1903 end = Some(true);
1903 } 1904 }
1904} 1905 }
1905"#), 1906 "#,
1906 @r###" 1907 expect![[r#"
1907 59..129 '{ ... } }': () 1908 59..129 '{ ... } }': ()
1908 69..76 'mut end': Option<bool> 1909 69..76 'mut end': Option<bool>
1909 79..83 'None': Option<bool> 1910 79..83 'None': Option<bool>
1910 89..127 'loop {... }': ! 1911 89..127 'loop {... }': !
1911 94..127 '{ ... }': () 1912 94..127 '{ ... }': ()
1912 104..107 'end': Option<bool> 1913 104..107 'end': Option<bool>
1913 104..120 'end = ...(true)': () 1914 104..120 'end = ...(true)': ()
1914 110..114 'Some': Some<bool>(bool) -> Option<bool> 1915 110..114 'Some': Some<bool>(bool) -> Option<bool>
1915 110..120 'Some(true)': Option<bool> 1916 110..120 'Some(true)': Option<bool>
1916 115..119 'true': bool 1917 115..119 'true': bool
1917 "### 1918 "#]],
1918 ); 1919 );
1919} 1920}
1920 1921
1921#[test] 1922#[test]
1922fn infer_loop_break_with_val() { 1923fn infer_loop_break_with_val() {
1923 assert_snapshot!( 1924 check_infer(
1924 infer(r#" 1925 r#"
1925enum Option<T> { Some(T), None } 1926 enum Option<T> { Some(T), None }
1926use Option::*; 1927 use Option::*;
1927 1928
1928fn test() { 1929 fn test() {
1929 let x = loop { 1930 let x = loop {
1930 if false { 1931 if false {
1931 break None; 1932 break None;
1932 } 1933 }
1933 1934
1934 break Some(true); 1935 break Some(true);
1935 }; 1936 };
1936} 1937 }
1937"#), 1938 "#,
1938 @r###" 1939 expect![[r#"
1939 59..168 '{ ... }; }': () 1940 59..168 '{ ... }; }': ()
1940 69..70 'x': Option<bool> 1941 69..70 'x': Option<bool>
1941 73..165 'loop {... }': Option<bool> 1942 73..165 'loop {... }': Option<bool>
1942 78..165 '{ ... }': () 1943 78..165 '{ ... }': ()
1943 88..132 'if fal... }': () 1944 88..132 'if fal... }': ()
1944 91..96 'false': bool 1945 91..96 'false': bool
1945 97..132 '{ ... }': () 1946 97..132 '{ ... }': ()
1946 111..121 'break None': ! 1947 111..121 'break None': !
1947 117..121 'None': Option<bool> 1948 117..121 'None': Option<bool>
1948 142..158 'break ...(true)': ! 1949 142..158 'break ...(true)': !
1949 148..152 'Some': Some<bool>(bool) -> Option<bool> 1950 148..152 'Some': Some<bool>(bool) -> Option<bool>
1950 148..158 'Some(true)': Option<bool> 1951 148..158 'Some(true)': Option<bool>
1951 153..157 'true': bool 1952 153..157 'true': bool
1952 "### 1953 "#]],
1953 ); 1954 );
1954} 1955}
1955 1956
1956#[test] 1957#[test]
1957fn infer_loop_break_without_val() { 1958fn infer_loop_break_without_val() {
1958 assert_snapshot!( 1959 check_infer(
1959 infer(r#" 1960 r#"
1960enum Option<T> { Some(T), None } 1961 enum Option<T> { Some(T), None }
1961use Option::*; 1962 use Option::*;
1962 1963
1963fn test() { 1964 fn test() {
1964 let x = loop { 1965 let x = loop {
1965 if false { 1966 if false {
1966 break; 1967 break;
1967 } 1968 }
1968 }; 1969 };
1969} 1970 }
1970"#), 1971 "#,
1971 @r###" 1972 expect![[r#"
1972 59..136 '{ ... }; }': () 1973 59..136 '{ ... }; }': ()
1973 69..70 'x': () 1974 69..70 'x': ()
1974 73..133 'loop {... }': () 1975 73..133 'loop {... }': ()
1975 78..133 '{ ... }': () 1976 78..133 '{ ... }': ()
1976 88..127 'if fal... }': () 1977 88..127 'if fal... }': ()
1977 91..96 'false': bool 1978 91..96 'false': bool
1978 97..127 '{ ... }': () 1979 97..127 '{ ... }': ()
1979 111..116 'break': ! 1980 111..116 'break': !
1980 "### 1981 "#]],
1981 ); 1982 );
1982} 1983}
1983 1984
1984#[test] 1985#[test]
1985fn infer_labelled_break_with_val() { 1986fn infer_labelled_break_with_val() {
1986 assert_snapshot!( 1987 check_infer(
1987 infer(r#" 1988 r#"
1988fn foo() { 1989 fn foo() {
1989 let _x = || 'outer: loop { 1990 let _x = || 'outer: loop {
1990 let inner = 'inner: loop { 1991 let inner = 'inner: loop {
1991 let i = Default::default(); 1992 let i = Default::default();
1992 if (break 'outer i) { 1993 if (break 'outer i) {
1993 loop { break 'inner 5i8; }; 1994 loop { break 'inner 5i8; };
1994 } else if true { 1995 } else if true {
1995 break 'inner 6; 1996 break 'inner 6;
1996 } 1997 }
1997 break 7; 1998 break 7;
1998 }; 1999 };
1999 break inner < 8; 2000 break inner < 8;
2000 }; 2001 };
2001} 2002 }
2002"#), 2003 "#,
2003 @r###" 2004 expect![[r#"
2004 9..335 '{ ... }; }': () 2005 9..335 '{ ... }; }': ()
2005 19..21 '_x': || -> bool 2006 19..21 '_x': || -> bool
2006 24..332 '|| 'ou... }': || -> bool 2007 24..332 '|| 'ou... }': || -> bool
2007 27..332 ''outer... }': bool 2008 27..332 ''outer... }': bool
2008 40..332 '{ ... }': () 2009 40..332 '{ ... }': ()
2009 54..59 'inner': i8 2010 54..59 'inner': i8
2010 62..300 ''inner... }': i8 2011 62..300 ''inner... }': i8
2011 75..300 '{ ... }': () 2012 75..300 '{ ... }': ()
2012 93..94 'i': bool 2013 93..94 'i': bool
2013 97..113 'Defaul...efault': {unknown} 2014 97..113 'Defaul...efault': {unknown}
2014 97..115 'Defaul...ault()': bool 2015 97..115 'Defaul...ault()': bool
2015 129..269 'if (br... }': () 2016 129..269 'if (br... }': ()
2016 133..147 'break 'outer i': ! 2017 133..147 'break 'outer i': !
2017 146..147 'i': bool 2018 146..147 'i': bool
2018 149..208 '{ ... }': () 2019 149..208 '{ ... }': ()
2019 167..193 'loop {...5i8; }': ! 2020 167..193 'loop {...5i8; }': !
2020 172..193 '{ brea...5i8; }': () 2021 172..193 '{ brea...5i8; }': ()
2021 174..190 'break ...er 5i8': ! 2022 174..190 'break ...er 5i8': !
2022 187..190 '5i8': i8 2023 187..190 '5i8': i8
2023 214..269 'if tru... }': () 2024 214..269 'if tru... }': ()
2024 217..221 'true': bool 2025 217..221 'true': bool
2025 222..269 '{ ... }': () 2026 222..269 '{ ... }': ()
2026 240..254 'break 'inner 6': ! 2027 240..254 'break 'inner 6': !
2027 253..254 '6': i8 2028 253..254 '6': i8
2028 282..289 'break 7': ! 2029 282..289 'break 7': !
2029 288..289 '7': i8 2030 288..289 '7': i8
2030 310..325 'break inner < 8': ! 2031 310..325 'break inner < 8': !
2031 316..321 'inner': i8 2032 316..321 'inner': i8
2032 316..325 'inner < 8': bool 2033 316..325 'inner < 8': bool
2033 324..325 '8': i8 2034 324..325 '8': i8
2034 "### 2035 "#]],
2035 ); 2036 );
2036} 2037}
2037 2038
2038#[test] 2039#[test]
2039fn generic_default() { 2040fn generic_default() {
2040 assert_snapshot!( 2041 check_infer(
2041 infer(r#" 2042 r#"
2042struct Thing<T = ()> { t: T } 2043 struct Thing<T = ()> { t: T }
2043enum OtherThing<T = ()> { 2044 enum OtherThing<T = ()> {
2044 One { t: T }, 2045 One { t: T },
2045 Two(T), 2046 Two(T),
2046} 2047 }
2047 2048
2048fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) { 2049 fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
2049 t1.t; 2050 t1.t;
2050 t3.t; 2051 t3.t;
2051 match t2 { 2052 match t2 {
2052 OtherThing::One { t } => { t; }, 2053 OtherThing::One { t } => { t; },
2053 OtherThing::Two(t) => { t; }, 2054 OtherThing::Two(t) => { t; },
2054 } 2055 }
2055 match t4 { 2056 match t4 {
2056 OtherThing::One { t } => { t; }, 2057 OtherThing::One { t } => { t; },
2057 OtherThing::Two(t) => { t; }, 2058 OtherThing::Two(t) => { t; },
2058 } 2059 }
2059} 2060 }
2060"#), 2061 "#,
2061 @r###" 2062 expect![[r#"
2062 97..99 't1': Thing<()> 2063 97..99 't1': Thing<()>
2063 108..110 't2': OtherThing<()> 2064 108..110 't2': OtherThing<()>
2064 124..126 't3': Thing<i32> 2065 124..126 't3': Thing<i32>
2065 140..142 't4': OtherThing<i32> 2066 140..142 't4': OtherThing<i32>
2066 161..384 '{ ... } }': () 2067 161..384 '{ ... } }': ()
2067 167..169 't1': Thing<()> 2068 167..169 't1': Thing<()>
2068 167..171 't1.t': () 2069 167..171 't1.t': ()
2069 177..179 't3': Thing<i32> 2070 177..179 't3': Thing<i32>
2070 177..181 't3.t': i32 2071 177..181 't3.t': i32
2071 187..282 'match ... }': () 2072 187..282 'match ... }': ()
2072 193..195 't2': OtherThing<()> 2073 193..195 't2': OtherThing<()>
2073 206..227 'OtherT... { t }': OtherThing<()> 2074 206..227 'OtherT... { t }': OtherThing<()>
2074 224..225 't': () 2075 224..225 't': ()
2075 231..237 '{ t; }': () 2076 231..237 '{ t; }': ()
2076 233..234 't': () 2077 233..234 't': ()
2077 247..265 'OtherT...Two(t)': OtherThing<()> 2078 247..265 'OtherT...Two(t)': OtherThing<()>
2078 263..264 't': () 2079 263..264 't': ()
2079 269..275 '{ t; }': () 2080 269..275 '{ t; }': ()
2080 271..272 't': () 2081 271..272 't': ()
2081 287..382 'match ... }': () 2082 287..382 'match ... }': ()
2082 293..295 't4': OtherThing<i32> 2083 293..295 't4': OtherThing<i32>
2083 306..327 'OtherT... { t }': OtherThing<i32> 2084 306..327 'OtherT... { t }': OtherThing<i32>
2084 324..325 't': i32 2085 324..325 't': i32
2085 331..337 '{ t; }': () 2086 331..337 '{ t; }': ()
2086 333..334 't': i32 2087 333..334 't': i32
2087 347..365 'OtherT...Two(t)': OtherThing<i32> 2088 347..365 'OtherT...Two(t)': OtherThing<i32>
2088 363..364 't': i32 2089 363..364 't': i32
2089 369..375 '{ t; }': () 2090 369..375 '{ t; }': ()
2090 371..372 't': i32 2091 371..372 't': i32
2091 "### 2092 "#]],
2092 ); 2093 );
2093} 2094}
2094 2095
2095#[test] 2096#[test]
2096fn generic_default_in_struct_literal() { 2097fn generic_default_in_struct_literal() {
2097 assert_snapshot!( 2098 check_infer(
2098 infer(r#" 2099 r#"
2099struct Thing<T = ()> { t: T } 2100 struct Thing<T = ()> { t: T }
2100enum OtherThing<T = ()> { 2101 enum OtherThing<T = ()> {
2101 One { t: T }, 2102 One { t: T },
2102 Two(T), 2103 Two(T),
2103} 2104 }
2104 2105
2105fn test() { 2106 fn test() {
2106 let x = Thing { t: loop {} }; 2107 let x = Thing { t: loop {} };
2107 let y = Thing { t: () }; 2108 let y = Thing { t: () };
2108 let z = Thing { t: 1i32 }; 2109 let z = Thing { t: 1i32 };
2109 if let Thing { t } = z { 2110 if let Thing { t } = z {
2110 t; 2111 t;
2111 } 2112 }
2112 2113
2113 let a = OtherThing::One { t: 1i32 }; 2114 let a = OtherThing::One { t: 1i32 };
2114 let b = OtherThing::Two(1i32); 2115 let b = OtherThing::Two(1i32);
2115} 2116 }
2116"#), 2117 "#,
2117 @r###" 2118 expect![[r#"
2118 99..319 '{ ...32); }': () 2119 99..319 '{ ...32); }': ()
2119 109..110 'x': Thing<!> 2120 109..110 'x': Thing<!>
2120 113..133 'Thing ...p {} }': Thing<!> 2121 113..133 'Thing ...p {} }': Thing<!>
2121 124..131 'loop {}': ! 2122 124..131 'loop {}': !
2122 129..131 '{}': () 2123 129..131 '{}': ()
2123 143..144 'y': Thing<()> 2124 143..144 'y': Thing<()>
2124 147..162 'Thing { t: () }': Thing<()> 2125 147..162 'Thing { t: () }': Thing<()>
2125 158..160 '()': () 2126 158..160 '()': ()
2126 172..173 'z': Thing<i32> 2127 172..173 'z': Thing<i32>
2127 176..193 'Thing ...1i32 }': Thing<i32> 2128 176..193 'Thing ...1i32 }': Thing<i32>
2128 187..191 '1i32': i32 2129 187..191 '1i32': i32
2129 199..240 'if let... }': () 2130 199..240 'if let... }': ()
2130 206..217 'Thing { t }': Thing<i32> 2131 206..217 'Thing { t }': Thing<i32>
2131 214..215 't': i32 2132 214..215 't': i32
2132 220..221 'z': Thing<i32> 2133 220..221 'z': Thing<i32>
2133 222..240 '{ ... }': () 2134 222..240 '{ ... }': ()
2134 232..233 't': i32 2135 232..233 't': i32
2135 250..251 'a': OtherThing<i32> 2136 250..251 'a': OtherThing<i32>
2136 254..281 'OtherT...1i32 }': OtherThing<i32> 2137 254..281 'OtherT...1i32 }': OtherThing<i32>
2137 275..279 '1i32': i32 2138 275..279 '1i32': i32
2138 291..292 'b': OtherThing<i32> 2139 291..292 'b': OtherThing<i32>
2139 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32> 2140 295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2140 295..316 'OtherT...(1i32)': OtherThing<i32> 2141 295..316 'OtherT...(1i32)': OtherThing<i32>
2141 311..315 '1i32': i32 2142 311..315 '1i32': i32
2142 "### 2143 "#]],
2143 ); 2144 );
2144} 2145}
2145 2146
2146#[test] 2147#[test]
2147fn generic_default_depending_on_other_type_arg() { 2148fn generic_default_depending_on_other_type_arg() {
2148 assert_snapshot!( 2149 // FIXME: the {unknown} is a bug
2149 infer(r#" 2150 check_infer(
2150struct Thing<T = u128, F = fn() -> T> { t: T } 2151 r#"
2151 2152 struct Thing<T = u128, F = fn() -> T> { t: T }
2152fn test(t1: Thing<u32>, t2: Thing) { 2153
2153 t1; 2154 fn test(t1: Thing<u32>, t2: Thing) {
2154 t2; 2155 t1;
2155 Thing::<_> { t: 1u32 }; 2156 t2;
2156} 2157 Thing::<_> { t: 1u32 };
2157"#), 2158 }
2158 // FIXME: the {unknown} is a bug 2159 "#,
2159 @r###" 2160 expect![[r#"
2160 56..58 't1': Thing<u32, fn() -> u32> 2161 56..58 't1': Thing<u32, fn() -> u32>
2161 72..74 't2': Thing<u128, fn() -> u128> 2162 72..74 't2': Thing<u128, fn() -> u128>
2162 83..130 '{ ...2 }; }': () 2163 83..130 '{ ...2 }; }': ()
2163 89..91 't1': Thing<u32, fn() -> u32> 2164 89..91 't1': Thing<u32, fn() -> u32>
2164 97..99 't2': Thing<u128, fn() -> u128> 2165 97..99 't2': Thing<u128, fn() -> u128>
2165 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}> 2166 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2166 121..125 '1u32': u32 2167 121..125 '1u32': u32
2167 "### 2168 "#]],
2168 ); 2169 );
2169} 2170}
2170 2171
2171#[test] 2172#[test]
2172fn generic_default_depending_on_other_type_arg_forward() { 2173fn generic_default_depending_on_other_type_arg_forward() {
2173 assert_snapshot!( 2174 // the {unknown} here is intentional, as defaults are not allowed to
2174 infer(r#" 2175 // refer to type parameters coming later
2175struct Thing<F = fn() -> T, T = u128> { t: T } 2176 check_infer(
2176 2177 r#"
2177fn test(t1: Thing) { 2178 struct Thing<F = fn() -> T, T = u128> { t: T }
2178 t1; 2179
2179} 2180 fn test(t1: Thing) {
2180"#), 2181 t1;
2181 // the {unknown} here is intentional, as defaults are not allowed to 2182 }
2182 // refer to type parameters coming later 2183 "#,
2183 @r###" 2184 expect![[r#"
2184 56..58 't1': Thing<fn() -> {unknown}, u128> 2185 56..58 't1': Thing<fn() -> {unknown}, u128>
2185 67..78 '{ t1; }': () 2186 67..78 '{ t1; }': ()
2186 73..75 't1': Thing<fn() -> {unknown}, u128> 2187 73..75 't1': Thing<fn() -> {unknown}, u128>
2187 "### 2188 "#]],
2188 ); 2189 );
2189} 2190}