Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/hir_ty/src/tests/method_resolution.rs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index 9c0c00da3b..4de58cc1d8 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs @@ -1460,3 +1460,85 @@ fn main() { "#, ); } + +#[test] +fn deref_fun_1() { + check_types(r#" +//- minicore: deref + +struct A<T, U>(T, U); +struct B<T>(T); +struct C<T>(T); + +impl<T> core::ops::Deref for A<B<T>, u32> { + type Target = B<T>; + fn deref(&self) -> &B<T> { &self.0 } +} +impl core::ops::Deref for B<isize> { + type Target = C<isize>; + fn deref(&self) -> &C<isize> { loop {} } +} + +impl<T: Copy> C<T> { + fn thing(&self) -> T { self.0 } +} + +fn make<T>() -> T { loop {} } + +fn test() { + let a1 = A(make(), make()); + let _: usize = (*a1).0; + a1; + //^^ A<B<usize>, u32> + + let a2 = A(make(), make()); + a2.thing(); + //^^^^^^^^^^ isize + a2; + //^^ A<B<isize>, u32> +} +"#); +} + +#[test] +fn deref_fun_2() { + check_types(r#" +//- minicore: deref + +struct A<T, U>(T, U); +struct B<T>(T); +struct C<T>(T); + +impl<T> core::ops::Deref for A<B<T>, u32> { + type Target = B<T>; + fn deref(&self) -> &B<T> { &self.0 } +} +impl core::ops::Deref for B<isize> { + type Target = C<isize>; + fn deref(&self) -> &C<isize> { loop {} } +} + +impl<T> core::ops::Deref for A<C<T>, i32> { + type Target = C<T>; + fn deref(&self) -> &C<T> { &self.0 } +} + +impl<T: Copy> C<T> { + fn thing(&self) -> T { self.0 } +} + +fn make<T>() -> T { loop {} } + +fn test() { + let a1 = A(make(), 1u32); + a1.thing(); + a1; + //^^ A<B<isize>, u32> + + let a2 = A(make(), 1i32); + let _: &str = a2.thing(); + a2; + //^^ A<C<&str>, i32> +} +"#); +} |