diff options
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 588f0d1d4..6bcede4c4 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -3740,3 +3740,70 @@ mod future { | |||
3740 | "#, | 3740 | "#, |
3741 | ); | 3741 | ); |
3742 | } | 3742 | } |
3743 | |||
3744 | #[test] | ||
3745 | fn local_impl_1() { | ||
3746 | check_types( | ||
3747 | r#" | ||
3748 | trait Trait<T> { | ||
3749 | fn foo(&self) -> T; | ||
3750 | } | ||
3751 | |||
3752 | fn test() { | ||
3753 | struct S; | ||
3754 | impl Trait<u32> for S { | ||
3755 | fn foo(&self) { 0 } | ||
3756 | } | ||
3757 | |||
3758 | S.foo(); | ||
3759 | // ^^^^^^^ u32 | ||
3760 | } | ||
3761 | "#, | ||
3762 | ); | ||
3763 | } | ||
3764 | |||
3765 | #[test] | ||
3766 | fn local_impl_2() { | ||
3767 | check_types( | ||
3768 | r#" | ||
3769 | struct S; | ||
3770 | |||
3771 | fn test() { | ||
3772 | trait Trait<T> { | ||
3773 | fn foo(&self) -> T; | ||
3774 | } | ||
3775 | impl Trait<u32> for S { | ||
3776 | fn foo(&self) { 0 } | ||
3777 | } | ||
3778 | |||
3779 | S.foo(); | ||
3780 | // ^^^^^^^ u32 | ||
3781 | } | ||
3782 | "#, | ||
3783 | ); | ||
3784 | } | ||
3785 | |||
3786 | #[test] | ||
3787 | fn local_impl_3() { | ||
3788 | check_types( | ||
3789 | r#" | ||
3790 | trait Trait<T> { | ||
3791 | fn foo(&self) -> T; | ||
3792 | } | ||
3793 | |||
3794 | fn test() { | ||
3795 | struct S1; | ||
3796 | { | ||
3797 | struct S2; | ||
3798 | |||
3799 | impl Trait<S1> for S2 { | ||
3800 | fn foo(&self) { S1 } | ||
3801 | } | ||
3802 | |||
3803 | S2.foo(); | ||
3804 | // ^^^^^^^^ S1 | ||
3805 | } | ||
3806 | } | ||
3807 | "#, | ||
3808 | ); | ||
3809 | } | ||