diff options
Diffstat (limited to 'crates/hir_ty/src/tests/traits.rs')
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 244 |
1 files changed, 91 insertions, 153 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 279a1354a..a0ddad570 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | use cov_mark::check; | ||
1 | use expect_test::expect; | 2 | use expect_test::expect; |
2 | 3 | ||
3 | use super::{check_infer, check_infer_with_mismatches, check_types}; | 4 | use super::{check, check_infer, check_infer_with_mismatches, check_types}; |
4 | 5 | ||
5 | #[test] | 6 | #[test] |
6 | fn infer_await() { | 7 | fn infer_await() { |
@@ -285,7 +286,7 @@ mod ops { | |||
285 | 286 | ||
286 | #[test] | 287 | #[test] |
287 | fn infer_from_bound_1() { | 288 | fn infer_from_bound_1() { |
288 | check_infer( | 289 | check_types( |
289 | r#" | 290 | r#" |
290 | trait Trait<T> {} | 291 | trait Trait<T> {} |
291 | struct S<T>(T); | 292 | struct S<T>(T); |
@@ -293,99 +294,62 @@ impl<U> Trait<U> for S<U> {} | |||
293 | fn foo<T: Trait<u32>>(t: T) {} | 294 | fn foo<T: Trait<u32>>(t: T) {} |
294 | fn test() { | 295 | fn test() { |
295 | let s = S(unknown); | 296 | let s = S(unknown); |
297 | // ^^^^^^^ u32 | ||
296 | foo(s); | 298 | foo(s); |
297 | }"#, | 299 | }"#, |
298 | expect![[r#" | ||
299 | 85..86 't': T | ||
300 | 91..93 '{}': () | ||
301 | 104..143 '{ ...(s); }': () | ||
302 | 114..115 's': S<u32> | ||
303 | 118..119 'S': S<u32>(u32) -> S<u32> | ||
304 | 118..128 'S(unknown)': S<u32> | ||
305 | 120..127 'unknown': u32 | ||
306 | 134..137 'foo': fn foo<S<u32>>(S<u32>) | ||
307 | 134..140 'foo(s)': () | ||
308 | 138..139 's': S<u32> | ||
309 | "#]], | ||
310 | ); | 300 | ); |
311 | } | 301 | } |
312 | 302 | ||
313 | #[test] | 303 | #[test] |
314 | fn infer_from_bound_2() { | 304 | fn infer_from_bound_2() { |
315 | check_infer( | 305 | check_types( |
316 | r#" | 306 | r#" |
317 | trait Trait<T> {} | 307 | trait Trait<T> {} |
318 | struct S<T>(T); | 308 | struct S<T>(T); |
319 | impl<U> Trait<U> for S<U> {} | 309 | impl<U> Trait<U> for S<U> {} |
320 | fn foo<U, T: Trait<U>>(t: T) -> U {} | 310 | fn foo<U, T: Trait<U>>(t: T) -> U { loop {} } |
321 | fn test() { | 311 | fn test() { |
322 | let s = S(unknown); | 312 | let s = S(unknown); |
313 | // ^^^^^^^ u32 | ||
323 | let x: u32 = foo(s); | 314 | let x: u32 = foo(s); |
324 | }"#, | 315 | }"#, |
325 | expect![[r#" | ||
326 | 86..87 't': T | ||
327 | 97..99 '{}': () | ||
328 | 110..162 '{ ...(s); }': () | ||
329 | 120..121 's': S<u32> | ||
330 | 124..125 'S': S<u32>(u32) -> S<u32> | ||
331 | 124..134 'S(unknown)': S<u32> | ||
332 | 126..133 'unknown': u32 | ||
333 | 144..145 'x': u32 | ||
334 | 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32 | ||
335 | 153..159 'foo(s)': u32 | ||
336 | 157..158 's': S<u32> | ||
337 | "#]], | ||
338 | ); | 316 | ); |
339 | } | 317 | } |
340 | 318 | ||
341 | #[test] | 319 | #[test] |
342 | fn trait_default_method_self_bound_implements_trait() { | 320 | fn trait_default_method_self_bound_implements_trait() { |
343 | cov_mark::check!(trait_self_implements_self); | 321 | cov_mark::check!(trait_self_implements_self); |
344 | check_infer( | 322 | check( |
345 | r#" | 323 | r#" |
346 | trait Trait { | 324 | trait Trait { |
347 | fn foo(&self) -> i64; | 325 | fn foo(&self) -> i64; |
348 | fn bar(&self) -> { | 326 | fn bar(&self) -> () { |
349 | let x = self.foo(); | 327 | self.foo(); |
328 | // ^^^^^^^^^^ type: i64 | ||
350 | } | 329 | } |
351 | }"#, | 330 | }"#, |
352 | expect![[r#" | ||
353 | 26..30 'self': &Self | ||
354 | 52..56 'self': &Self | ||
355 | 61..96 '{ ... }': () | ||
356 | 75..76 'x': i64 | ||
357 | 79..83 'self': &Self | ||
358 | 79..89 'self.foo()': i64 | ||
359 | "#]], | ||
360 | ); | 331 | ); |
361 | } | 332 | } |
362 | 333 | ||
363 | #[test] | 334 | #[test] |
364 | fn trait_default_method_self_bound_implements_super_trait() { | 335 | fn trait_default_method_self_bound_implements_super_trait() { |
365 | check_infer( | 336 | check( |
366 | r#" | 337 | r#" |
367 | trait SuperTrait { | 338 | trait SuperTrait { |
368 | fn foo(&self) -> i64; | 339 | fn foo(&self) -> i64; |
369 | } | 340 | } |
370 | trait Trait: SuperTrait { | 341 | trait Trait: SuperTrait { |
371 | fn bar(&self) -> { | 342 | fn bar(&self) -> () { |
372 | let x = self.foo(); | 343 | self.foo(); |
344 | // ^^^^^^^^^^ type: i64 | ||
373 | } | 345 | } |
374 | }"#, | 346 | }"#, |
375 | expect![[r#" | ||
376 | 31..35 'self': &Self | ||
377 | 85..89 'self': &Self | ||
378 | 94..129 '{ ... }': () | ||
379 | 108..109 'x': i64 | ||
380 | 112..116 'self': &Self | ||
381 | 112..122 'self.foo()': i64 | ||
382 | "#]], | ||
383 | ); | 347 | ); |
384 | } | 348 | } |
385 | 349 | ||
386 | #[test] | 350 | #[test] |
387 | fn infer_project_associated_type() { | 351 | fn infer_project_associated_type() { |
388 | check_infer( | 352 | check_types( |
389 | r#" | 353 | r#" |
390 | trait Iterable { | 354 | trait Iterable { |
391 | type Item; | 355 | type Item; |
@@ -394,89 +358,62 @@ struct S; | |||
394 | impl Iterable for S { type Item = u32; } | 358 | impl Iterable for S { type Item = u32; } |
395 | fn test<T: Iterable>() { | 359 | fn test<T: Iterable>() { |
396 | let x: <S as Iterable>::Item = 1; | 360 | let x: <S as Iterable>::Item = 1; |
397 | let y: <T as Iterable>::Item = no_matter; | 361 | // ^ u32 |
398 | let z: T::Item = no_matter; | 362 | let y: <T as Iterable>::Item = u; |
399 | let a: <T>::Item = no_matter; | 363 | // ^ Iterable::Item<T> |
364 | let z: T::Item = u; | ||
365 | // ^ Iterable::Item<T> | ||
366 | let a: <T>::Item = u; | ||
367 | // ^ Iterable::Item<T> | ||
400 | }"#, | 368 | }"#, |
401 | expect![[r#" | ||
402 | 108..261 '{ ...ter; }': () | ||
403 | 118..119 'x': u32 | ||
404 | 145..146 '1': u32 | ||
405 | 156..157 'y': Iterable::Item<T> | ||
406 | 183..192 'no_matter': Iterable::Item<T> | ||
407 | 202..203 'z': Iterable::Item<T> | ||
408 | 215..224 'no_matter': Iterable::Item<T> | ||
409 | 234..235 'a': Iterable::Item<T> | ||
410 | 249..258 'no_matter': Iterable::Item<T> | ||
411 | "#]], | ||
412 | ); | 369 | ); |
413 | } | 370 | } |
414 | 371 | ||
415 | #[test] | 372 | #[test] |
416 | fn infer_return_associated_type() { | 373 | fn infer_return_associated_type() { |
417 | check_infer( | 374 | check_types( |
418 | r#" | 375 | r#" |
419 | trait Iterable { | 376 | trait Iterable { |
420 | type Item; | 377 | type Item; |
421 | } | 378 | } |
422 | struct S; | 379 | struct S; |
423 | impl Iterable for S { type Item = u32; } | 380 | impl Iterable for S { type Item = u32; } |
424 | fn foo1<T: Iterable>(t: T) -> T::Item {} | 381 | fn foo1<T: Iterable>(t: T) -> T::Item { loop {} } |
425 | fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {} | 382 | fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item { loop {} } |
426 | fn foo3<T: Iterable>(t: T) -> <T>::Item {} | 383 | fn foo3<T: Iterable>(t: T) -> <T>::Item { loop {} } |
427 | fn test() { | 384 | fn test() { |
428 | let x = foo1(S); | 385 | foo1(S); |
429 | let y = foo2(S); | 386 | // ^^^^^^^ u32 |
430 | let z = foo3(S); | 387 | foo2(S); |
388 | // ^^^^^^^ u32 | ||
389 | foo3(S); | ||
390 | // ^^^^^^^ u32 | ||
431 | }"#, | 391 | }"#, |
432 | expect![[r#" | ||
433 | 106..107 't': T | ||
434 | 123..125 '{}': () | ||
435 | 147..148 't': T | ||
436 | 178..180 '{}': () | ||
437 | 202..203 't': T | ||
438 | 221..223 '{}': () | ||
439 | 234..300 '{ ...(S); }': () | ||
440 | 244..245 'x': u32 | ||
441 | 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item | ||
442 | 248..255 'foo1(S)': u32 | ||
443 | 253..254 'S': S | ||
444 | 265..266 'y': u32 | ||
445 | 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item | ||
446 | 269..276 'foo2(S)': u32 | ||
447 | 274..275 'S': S | ||
448 | 286..287 'z': u32 | ||
449 | 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item | ||
450 | 290..297 'foo3(S)': u32 | ||
451 | 295..296 'S': S | ||
452 | "#]], | ||
453 | ); | 392 | ); |
454 | } | 393 | } |
455 | 394 | ||
456 | #[test] | 395 | #[test] |
457 | fn infer_associated_type_bound() { | 396 | fn infer_associated_type_bound() { |
458 | check_infer( | 397 | check_types( |
459 | r#" | 398 | r#" |
460 | trait Iterable { | 399 | trait Iterable { |
461 | type Item; | 400 | type Item; |
462 | } | 401 | } |
463 | fn test<T: Iterable<Item=u32>>() { | 402 | fn test<T: Iterable<Item=u32>>() { |
464 | let y: T::Item = unknown; | 403 | let y: T::Item = unknown; |
404 | // ^^^^^^^ u32 | ||
465 | }"#, | 405 | }"#, |
466 | expect![[r#" | ||
467 | 67..100 '{ ...own; }': () | ||
468 | 77..78 'y': u32 | ||
469 | 90..97 'unknown': u32 | ||
470 | "#]], | ||
471 | ); | 406 | ); |
472 | } | 407 | } |
473 | 408 | ||
474 | #[test] | 409 | #[test] |
475 | fn infer_const_body() { | 410 | fn infer_const_body() { |
411 | // FIXME make check_types work with other bodies | ||
476 | check_infer( | 412 | check_infer( |
477 | r#" | 413 | r#" |
478 | const A: u32 = 1 + 1; | 414 | const A: u32 = 1 + 1; |
479 | static B: u64 = { let x = 1; x };"#, | 415 | static B: u64 = { let x = 1; x }; |
416 | "#, | ||
480 | expect![[r#" | 417 | expect![[r#" |
481 | 15..16 '1': u32 | 418 | 15..16 '1': u32 |
482 | 15..20 '1 + 1': u32 | 419 | 15..20 '1 + 1': u32 |
@@ -637,12 +574,12 @@ impl<T> core::ops::Deref for Arc<T> { | |||
637 | 574 | ||
638 | struct S; | 575 | struct S; |
639 | impl S { | 576 | impl S { |
640 | fn foo(&self) -> u128 {} | 577 | fn foo(&self) -> u128 { 0 } |
641 | } | 578 | } |
642 | 579 | ||
643 | fn test(s: Arc<S>) { | 580 | fn test(s: Arc<S>) { |
644 | (*s, s.foo()); | 581 | (*s, s.foo()); |
645 | } //^ (S, u128) | 582 | } //^^^^^^^^^^^^^ (S, u128) |
646 | "#, | 583 | "#, |
647 | ); | 584 | ); |
648 | } | 585 | } |
@@ -653,7 +590,7 @@ fn deref_trait_with_inference_var() { | |||
653 | r#" | 590 | r#" |
654 | //- minicore: deref | 591 | //- minicore: deref |
655 | struct Arc<T>; | 592 | struct Arc<T>; |
656 | fn new_arc<T>() -> Arc<T> {} | 593 | fn new_arc<T>() -> Arc<T> { Arc } |
657 | impl<T> core::ops::Deref for Arc<T> { | 594 | impl<T> core::ops::Deref for Arc<T> { |
658 | type Target = T; | 595 | type Target = T; |
659 | } | 596 | } |
@@ -663,8 +600,8 @@ fn foo(a: Arc<S>) {} | |||
663 | 600 | ||
664 | fn test() { | 601 | fn test() { |
665 | let a = new_arc(); | 602 | let a = new_arc(); |
666 | let b = (*a); | 603 | let b = *a; |
667 | //^ S | 604 | //^^ S |
668 | foo(a); | 605 | foo(a); |
669 | } | 606 | } |
670 | "#, | 607 | "#, |
@@ -684,7 +621,7 @@ impl core::ops::Deref for S { | |||
684 | 621 | ||
685 | fn test(s: S) { | 622 | fn test(s: S) { |
686 | s.foo(); | 623 | s.foo(); |
687 | } //^ {unknown} | 624 | } //^^^^^^^ {unknown} |
688 | "#, | 625 | "#, |
689 | ); | 626 | ); |
690 | } | 627 | } |
@@ -701,12 +638,12 @@ impl<T: ?Sized> core::ops::Deref for Arc<T> { | |||
701 | 638 | ||
702 | struct S; | 639 | struct S; |
703 | impl S { | 640 | impl S { |
704 | fn foo(&self) -> u128 {} | 641 | fn foo(&self) -> u128 { 0 } |
705 | } | 642 | } |
706 | 643 | ||
707 | fn test(s: Arc<S>) { | 644 | fn test(s: Arc<S>) { |
708 | (*s, s.foo()); | 645 | (*s, s.foo()); |
709 | } //^ (S, u128) | 646 | } //^^^^^^^^^^^^^ (S, u128) |
710 | "#, | 647 | "#, |
711 | ); | 648 | ); |
712 | } | 649 | } |
@@ -720,11 +657,11 @@ struct S; | |||
720 | trait Trait<T> {} | 657 | trait Trait<T> {} |
721 | impl Trait<u32> for S {} | 658 | impl Trait<u32> for S {} |
722 | 659 | ||
723 | fn foo<T: Trait<U>, U>(t: T) -> U {} | 660 | fn foo<T: Trait<U>, U>(t: T) -> U { loop {} } |
724 | 661 | ||
725 | fn test(s: S) { | 662 | fn test(s: S) { |
726 | (foo(s)); | 663 | foo(s); |
727 | } //^ u32 | 664 | } //^^^^^^ u32 |
728 | "#, | 665 | "#, |
729 | ); | 666 | ); |
730 | } | 667 | } |
@@ -741,12 +678,12 @@ impl Trait<isize> for S {} | |||
741 | 678 | ||
742 | struct O; | 679 | struct O; |
743 | impl O { | 680 | impl O { |
744 | fn foo<T: Trait<U>, U>(&self, t: T) -> U {} | 681 | fn foo<T: Trait<U>, U>(&self, t: T) -> U { loop {} } |
745 | } | 682 | } |
746 | 683 | ||
747 | fn test() { | 684 | fn test() { |
748 | O.foo(S); | 685 | O.foo(S); |
749 | } //^ isize | 686 | } //^^^^^^^^ isize |
750 | "#, | 687 | "#, |
751 | ); | 688 | ); |
752 | } | 689 | } |
@@ -761,12 +698,12 @@ trait Trait<T> {} | |||
761 | impl Trait<i64> for S {} | 698 | impl Trait<i64> for S {} |
762 | 699 | ||
763 | impl S { | 700 | impl S { |
764 | fn foo<U>(&self) -> U where Self: Trait<U> {} | 701 | fn foo<U>(&self) -> U where Self: Trait<U> { loop {} } |
765 | } | 702 | } |
766 | 703 | ||
767 | fn test() { | 704 | fn test() { |
768 | S.foo(); | 705 | S.foo(); |
769 | } //^ i64 | 706 | } //^^^^^^^ i64 |
770 | "#, | 707 | "#, |
771 | ); | 708 | ); |
772 | } | 709 | } |
@@ -782,12 +719,12 @@ impl Trait<&str> for S {} | |||
782 | 719 | ||
783 | struct O<T>; | 720 | struct O<T>; |
784 | impl<U, T: Trait<U>> O<T> { | 721 | impl<U, T: Trait<U>> O<T> { |
785 | fn foo(&self) -> U {} | 722 | fn foo(&self) -> U { loop {} } |
786 | } | 723 | } |
787 | 724 | ||
788 | fn test(o: O<S>) { | 725 | fn test(o: O<S>) { |
789 | o.foo(); | 726 | o.foo(); |
790 | } //^ &str | 727 | } //^^^^^^^ &str |
791 | "#, | 728 | "#, |
792 | ); | 729 | ); |
793 | } | 730 | } |
@@ -802,7 +739,7 @@ struct S; | |||
802 | impl Clone for S {} | 739 | impl Clone for S {} |
803 | impl<T> Trait for T where T: Clone {} | 740 | impl<T> Trait for T where T: Clone {} |
804 | fn test<T: Clone>(t: T) { t.foo(); } | 741 | fn test<T: Clone>(t: T) { t.foo(); } |
805 | //^ u128 | 742 | //^^^^^^^ u128 |
806 | "#, | 743 | "#, |
807 | ); | 744 | ); |
808 | } | 745 | } |
@@ -818,7 +755,7 @@ struct S; | |||
818 | impl Clone for S {} | 755 | impl Clone for S {} |
819 | impl<T> Trait for T where T: Clone {} | 756 | impl<T> Trait for T where T: Clone {} |
820 | fn test<T>(t: T) { t.foo(); } | 757 | fn test<T>(t: T) { t.foo(); } |
821 | //^ {unknown} | 758 | //^^^^^^^ {unknown} |
822 | "#, | 759 | "#, |
823 | ); | 760 | ); |
824 | } | 761 | } |
@@ -831,7 +768,7 @@ trait Trait { fn foo(self) -> u128; } | |||
831 | struct S; | 768 | struct S; |
832 | impl Trait for S {} | 769 | impl Trait for S {} |
833 | fn test<T: Trait>(t: T) { t.foo(); } | 770 | fn test<T: Trait>(t: T) { t.foo(); } |
834 | //^ u128 | 771 | //^^^^^^^ u128 |
835 | "#, | 772 | "#, |
836 | ); | 773 | ); |
837 | } | 774 | } |
@@ -844,7 +781,7 @@ trait Trait { fn foo(self) -> u128; } | |||
844 | struct S; | 781 | struct S; |
845 | impl Trait for S {} | 782 | impl Trait for S {} |
846 | fn test<T>(t: T) { t.foo(); } | 783 | fn test<T>(t: T) { t.foo(); } |
847 | //^ {unknown} | 784 | //^^^^^^^ {unknown} |
848 | "#, | 785 | "#, |
849 | ); | 786 | ); |
850 | } | 787 | } |
@@ -858,8 +795,8 @@ trait Trait {} | |||
858 | impl<T> core::ops::Deref for T where T: Trait { | 795 | impl<T> core::ops::Deref for T where T: Trait { |
859 | type Target = i128; | 796 | type Target = i128; |
860 | } | 797 | } |
861 | fn test<T: Trait>(t: T) { (*t); } | 798 | fn test<T: Trait>(t: T) { *t; } |
862 | //^ i128 | 799 | //^^ i128 |
863 | "#, | 800 | "#, |
864 | ); | 801 | ); |
865 | } | 802 | } |
@@ -1380,12 +1317,12 @@ fn error_bound_chalk() { | |||
1380 | check_types( | 1317 | check_types( |
1381 | r#" | 1318 | r#" |
1382 | trait Trait { | 1319 | trait Trait { |
1383 | fn foo(&self) -> u32 {} | 1320 | fn foo(&self) -> u32 { 0 } |
1384 | } | 1321 | } |
1385 | 1322 | ||
1386 | fn test(x: (impl Trait + UnknownTrait)) { | 1323 | fn test(x: (impl Trait + UnknownTrait)) { |
1387 | x.foo(); | 1324 | x.foo(); |
1388 | } //^ u32 | 1325 | } //^^^^^^^ u32 |
1389 | "#, | 1326 | "#, |
1390 | ); | 1327 | ); |
1391 | } | 1328 | } |
@@ -1476,7 +1413,7 @@ trait Clone { | |||
1476 | fn api_walkthrough() { | 1413 | fn api_walkthrough() { |
1477 | for node in foo() { | 1414 | for node in foo() { |
1478 | node.clone(); | 1415 | node.clone(); |
1479 | } //^ {unknown} | 1416 | } //^^^^^^^^^^^^ {unknown} |
1480 | } | 1417 | } |
1481 | "#, | 1418 | "#, |
1482 | ); | 1419 | ); |
@@ -1513,13 +1450,13 @@ fn where_clause_trait_in_scope_for_method_resolution() { | |||
1513 | r#" | 1450 | r#" |
1514 | mod foo { | 1451 | mod foo { |
1515 | trait Trait { | 1452 | trait Trait { |
1516 | fn foo(&self) -> u32 {} | 1453 | fn foo(&self) -> u32 { 0 } |
1517 | } | 1454 | } |
1518 | } | 1455 | } |
1519 | 1456 | ||
1520 | fn test<T: foo::Trait>(x: T) { | 1457 | fn test<T: foo::Trait>(x: T) { |
1521 | x.foo(); | 1458 | x.foo(); |
1522 | } //^ u32 | 1459 | } //^^^^^^^ u32 |
1523 | "#, | 1460 | "#, |
1524 | ); | 1461 | ); |
1525 | } | 1462 | } |
@@ -1982,7 +1919,7 @@ fn fn_item_fn_trait() { | |||
1982 | //- minicore: fn | 1919 | //- minicore: fn |
1983 | struct S; | 1920 | struct S; |
1984 | 1921 | ||
1985 | fn foo() -> S {} | 1922 | fn foo() -> S { S } |
1986 | 1923 | ||
1987 | fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() } | 1924 | fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() } |
1988 | 1925 | ||
@@ -2009,7 +1946,7 @@ trait Trait2 { | |||
2009 | fn test<T: Trait>() where T::Item: Trait2 { | 1946 | fn test<T: Trait>() where T::Item: Trait2 { |
2010 | let x: T::Item = no_matter; | 1947 | let x: T::Item = no_matter; |
2011 | x.foo(); | 1948 | x.foo(); |
2012 | } //^ u32 | 1949 | } //^^^^^^^ u32 |
2013 | "#, | 1950 | "#, |
2014 | ); | 1951 | ); |
2015 | } | 1952 | } |
@@ -2029,7 +1966,7 @@ trait Trait2 { | |||
2029 | fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { | 1966 | fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { |
2030 | let x: T::Item = no_matter; | 1967 | let x: T::Item = no_matter; |
2031 | x.foo(); | 1968 | x.foo(); |
2032 | } //^ u32 | 1969 | } //^^^^^^^ u32 |
2033 | "#, | 1970 | "#, |
2034 | ); | 1971 | ); |
2035 | } | 1972 | } |
@@ -2092,7 +2029,7 @@ impl Trait for S { | |||
2092 | 2029 | ||
2093 | fn test() { | 2030 | fn test() { |
2094 | S.f(); | 2031 | S.f(); |
2095 | } //^ u32 | 2032 | } //^^^^^ u32 |
2096 | "#, | 2033 | "#, |
2097 | ); | 2034 | ); |
2098 | } | 2035 | } |
@@ -2120,7 +2057,7 @@ where | |||
2120 | 2057 | ||
2121 | fn foo<I: Interner>(interner: &I, t: Ty<I>) { | 2058 | fn foo<I: Interner>(interner: &I, t: Ty<I>) { |
2122 | fold(interner, t); | 2059 | fold(interner, t); |
2123 | } //^ Ty<I> | 2060 | } //^^^^^^^^^^^^^^^^^ Ty<I> |
2124 | "#, | 2061 | "#, |
2125 | ); | 2062 | ); |
2126 | } | 2063 | } |
@@ -2139,7 +2076,7 @@ impl Trait<Self> for S {} | |||
2139 | 2076 | ||
2140 | fn test() { | 2077 | fn test() { |
2141 | S.foo(); | 2078 | S.foo(); |
2142 | } //^ () | 2079 | } //^^^^^^^ () |
2143 | "#, | 2080 | "#, |
2144 | ); | 2081 | ); |
2145 | } | 2082 | } |
@@ -2158,7 +2095,7 @@ impl Trait for S<Self> {} | |||
2158 | 2095 | ||
2159 | fn test() { | 2096 | fn test() { |
2160 | S.foo(); | 2097 | S.foo(); |
2161 | } //^ {unknown} | 2098 | } //^^^^^^^ {unknown} |
2162 | "#, | 2099 | "#, |
2163 | ); | 2100 | ); |
2164 | } | 2101 | } |
@@ -2176,7 +2113,7 @@ trait Trait2<T> {} | |||
2176 | 2113 | ||
2177 | fn test<T: Trait>() where T: Trait2<T::Item> { | 2114 | fn test<T: Trait>() where T: Trait2<T::Item> { |
2178 | let x: T::Item = no_matter; | 2115 | let x: T::Item = no_matter; |
2179 | } //^ {unknown} | 2116 | } //^^^^^^^^^ {unknown} |
2180 | "#, | 2117 | "#, |
2181 | ); | 2118 | ); |
2182 | } | 2119 | } |
@@ -2193,7 +2130,7 @@ trait Trait<T> { | |||
2193 | 2130 | ||
2194 | fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> { | 2131 | fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> { |
2195 | let x: T::Item = no_matter; | 2132 | let x: T::Item = no_matter; |
2196 | } //^ {unknown} | 2133 | } //^^^^^^^^^ {unknown} |
2197 | "#, | 2134 | "#, |
2198 | ); | 2135 | ); |
2199 | } | 2136 | } |
@@ -2211,7 +2148,7 @@ trait Trait { | |||
2211 | 2148 | ||
2212 | fn test<T>() where T: Trait<OtherItem = T::Item> { | 2149 | fn test<T>() where T: Trait<OtherItem = T::Item> { |
2213 | let x: T::Item = no_matter; | 2150 | let x: T::Item = no_matter; |
2214 | } //^ Trait::Item<T> | 2151 | } //^^^^^^^^^ Trait::Item<T> |
2215 | "#, | 2152 | "#, |
2216 | ); | 2153 | ); |
2217 | } | 2154 | } |
@@ -2243,7 +2180,7 @@ fn test<T>(t: T) where T: UnificationStoreMut { | |||
2243 | t.push(x); | 2180 | t.push(x); |
2244 | let y: Key<T>; | 2181 | let y: Key<T>; |
2245 | (x, y); | 2182 | (x, y); |
2246 | } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>) | 2183 | } //^^^^^^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>) |
2247 | "#, | 2184 | "#, |
2248 | ); | 2185 | ); |
2249 | } | 2186 | } |
@@ -2268,7 +2205,7 @@ impl<T: Iterator> Iterator for S<T> { | |||
2268 | fn test<I: Iterator<Item: OtherTrait<u32>>>() { | 2205 | fn test<I: Iterator<Item: OtherTrait<u32>>>() { |
2269 | let x: <S<I> as Iterator>::Item; | 2206 | let x: <S<I> as Iterator>::Item; |
2270 | x.foo(); | 2207 | x.foo(); |
2271 | } //^ u32 | 2208 | } //^^^^^^^ u32 |
2272 | "#, | 2209 | "#, |
2273 | ); | 2210 | ); |
2274 | } | 2211 | } |
@@ -2470,7 +2407,7 @@ impl<T: Trait> Trait for S<T> { | |||
2470 | fn test<T: Trait>() { | 2407 | fn test<T: Trait>() { |
2471 | let y: <S<T> as Trait>::Item = no_matter; | 2408 | let y: <S<T> as Trait>::Item = no_matter; |
2472 | y.foo(); | 2409 | y.foo(); |
2473 | } //^ u32 | 2410 | } //^^^^^^^ u32 |
2474 | "#, | 2411 | "#, |
2475 | ); | 2412 | ); |
2476 | } | 2413 | } |
@@ -2490,7 +2427,7 @@ trait Trait { | |||
2490 | 2427 | ||
2491 | fn test(x: Box<dyn Trait>) { | 2428 | fn test(x: Box<dyn Trait>) { |
2492 | x.foo(); | 2429 | x.foo(); |
2493 | } //^ () | 2430 | } //^^^^^^^ () |
2494 | "#, | 2431 | "#, |
2495 | ); | 2432 | ); |
2496 | } | 2433 | } |
@@ -2509,7 +2446,7 @@ impl ToOwned for str { | |||
2509 | } | 2446 | } |
2510 | fn test() { | 2447 | fn test() { |
2511 | "foo".to_owned(); | 2448 | "foo".to_owned(); |
2512 | } //^ String | 2449 | } //^^^^^^^^^^^^^^^^ String |
2513 | "#, | 2450 | "#, |
2514 | ); | 2451 | ); |
2515 | } | 2452 | } |
@@ -2649,7 +2586,7 @@ impl<T:A> B for T { | |||
2649 | 2586 | ||
2650 | fn main() { | 2587 | fn main() { |
2651 | Bar::foo(); | 2588 | Bar::foo(); |
2652 | } //^ Foo | 2589 | } //^^^^^^^^^^ Foo |
2653 | "#, | 2590 | "#, |
2654 | ); | 2591 | ); |
2655 | } | 2592 | } |
@@ -3002,7 +2939,7 @@ fn test() { | |||
3002 | S.get(1); | 2939 | S.get(1); |
3003 | //^^^^^^^^ u128 | 2940 | //^^^^^^^^ u128 |
3004 | S.get(1.); | 2941 | S.get(1.); |
3005 | //^^^^^^^^ f32 | 2942 | //^^^^^^^^^ f32 |
3006 | } | 2943 | } |
3007 | "#, | 2944 | "#, |
3008 | ); | 2945 | ); |
@@ -3477,14 +3414,12 @@ trait Convert { | |||
3477 | fn new() -> Self; | 3414 | fn new() -> Self; |
3478 | } | 3415 | } |
3479 | impl Convert for u32 { | 3416 | impl Convert for u32 { |
3480 | fn new() -> Self { | 3417 | fn new() -> Self { 0 } |
3481 | 0 | ||
3482 | } | ||
3483 | } | 3418 | } |
3484 | 3419 | ||
3485 | async fn get_accounts() -> Result<u32, ()> { | 3420 | async fn get_accounts() -> Result<u32, ()> { |
3486 | let ret = Fooey.collect(); | 3421 | let ret = Fooey.collect(); |
3487 | // ^ u32 | 3422 | // ^^^^^^^^^^^^^^^ u32 |
3488 | Ok(ret) | 3423 | Ok(ret) |
3489 | } | 3424 | } |
3490 | "#, | 3425 | "#, |
@@ -3493,6 +3428,7 @@ async fn get_accounts() -> Result<u32, ()> { | |||
3493 | 3428 | ||
3494 | #[test] | 3429 | #[test] |
3495 | fn local_impl_1() { | 3430 | fn local_impl_1() { |
3431 | check!(block_local_impls); | ||
3496 | check_types( | 3432 | check_types( |
3497 | r#" | 3433 | r#" |
3498 | trait Trait<T> { | 3434 | trait Trait<T> { |
@@ -3502,7 +3438,7 @@ trait Trait<T> { | |||
3502 | fn test() { | 3438 | fn test() { |
3503 | struct S; | 3439 | struct S; |
3504 | impl Trait<u32> for S { | 3440 | impl Trait<u32> for S { |
3505 | fn foo(&self) { 0 } | 3441 | fn foo(&self) -> u32 { 0 } |
3506 | } | 3442 | } |
3507 | 3443 | ||
3508 | S.foo(); | 3444 | S.foo(); |
@@ -3514,6 +3450,7 @@ fn test() { | |||
3514 | 3450 | ||
3515 | #[test] | 3451 | #[test] |
3516 | fn local_impl_2() { | 3452 | fn local_impl_2() { |
3453 | check!(block_local_impls); | ||
3517 | check_types( | 3454 | check_types( |
3518 | r#" | 3455 | r#" |
3519 | struct S; | 3456 | struct S; |
@@ -3523,7 +3460,7 @@ fn test() { | |||
3523 | fn foo(&self) -> T; | 3460 | fn foo(&self) -> T; |
3524 | } | 3461 | } |
3525 | impl Trait<u32> for S { | 3462 | impl Trait<u32> for S { |
3526 | fn foo(&self) { 0 } | 3463 | fn foo(&self) -> u32 { 0 } |
3527 | } | 3464 | } |
3528 | 3465 | ||
3529 | S.foo(); | 3466 | S.foo(); |
@@ -3535,6 +3472,7 @@ fn test() { | |||
3535 | 3472 | ||
3536 | #[test] | 3473 | #[test] |
3537 | fn local_impl_3() { | 3474 | fn local_impl_3() { |
3475 | check!(block_local_impls); | ||
3538 | check_types( | 3476 | check_types( |
3539 | r#" | 3477 | r#" |
3540 | trait Trait<T> { | 3478 | trait Trait<T> { |
@@ -3547,7 +3485,7 @@ fn test() { | |||
3547 | struct S2; | 3485 | struct S2; |
3548 | 3486 | ||
3549 | impl Trait<S1> for S2 { | 3487 | impl Trait<S1> for S2 { |
3550 | fn foo(&self) { S1 } | 3488 | fn foo(&self) -> S1 { S1 } |
3551 | } | 3489 | } |
3552 | 3490 | ||
3553 | S2.foo(); | 3491 | S2.foo(); |