diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-13 12:13:31 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-13 12:13:31 +0100 |
commit | be9742809c80fbb86b1a25479a4cf2a0df24adb7 (patch) | |
tree | c9aeedf0d7167d436befbdc5cea6b06b7a1cfe98 /crates/hir_ty/src/tests | |
parent | e29a4c36c7135820929e741ed40192648556aca6 (diff) | |
parent | 5ca71a19903cea277ed8a347b36cffeca6b99922 (diff) |
Merge #9244
9244: feat: Make block-local trait impls work r=flodiebold a=flodiebold
As long as either the trait or the implementing type are defined in the same block.
CC #8961
Co-authored-by: Florian Diebold <[email protected]>
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 | } | ||