diff options
Diffstat (limited to 'crates/hir_ty/src/tests/method_resolution.rs')
-rw-r--r-- | crates/hir_ty/src/tests/method_resolution.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index a6a54e542..a9901d7b8 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs | |||
@@ -956,6 +956,51 @@ fn test() { foo.call(); } | |||
956 | } | 956 | } |
957 | 957 | ||
958 | #[test] | 958 | #[test] |
959 | fn super_trait_impl_return_trait_method_resolution() { | ||
960 | check_infer( | ||
961 | r#" | ||
962 | trait Base { | ||
963 | fn foo(self) -> usize; | ||
964 | } | ||
965 | |||
966 | trait Super : Base {} | ||
967 | |||
968 | fn base1() -> impl Base { loop {} } | ||
969 | fn super1() -> impl Super { loop {} } | ||
970 | |||
971 | fn test(base2: impl Base, super2: impl Super) { | ||
972 | base1().foo(); | ||
973 | super1().foo(); | ||
974 | base2.foo(); | ||
975 | super2.foo(); | ||
976 | } | ||
977 | "#, | ||
978 | expect![[r#" | ||
979 | 24..28 'self': Self | ||
980 | 90..101 '{ loop {} }': ! | ||
981 | 92..99 'loop {}': ! | ||
982 | 97..99 '{}': () | ||
983 | 128..139 '{ loop {} }': ! | ||
984 | 130..137 'loop {}': ! | ||
985 | 135..137 '{}': () | ||
986 | 149..154 'base2': impl Base | ||
987 | 167..173 'super2': impl Super | ||
988 | 187..264 '{ ...o(); }': () | ||
989 | 193..198 'base1': fn base1() -> impl Base | ||
990 | 193..200 'base1()': impl Base | ||
991 | 193..206 'base1().foo()': usize | ||
992 | 212..218 'super1': fn super1() -> impl Super | ||
993 | 212..220 'super1()': impl Super | ||
994 | 212..226 'super1().foo()': usize | ||
995 | 232..237 'base2': impl Base | ||
996 | 232..243 'base2.foo()': usize | ||
997 | 249..255 'super2': impl Super | ||
998 | 249..261 'super2.foo()': usize | ||
999 | "#]], | ||
1000 | ); | ||
1001 | } | ||
1002 | |||
1003 | #[test] | ||
959 | fn method_resolution_non_parameter_type() { | 1004 | fn method_resolution_non_parameter_type() { |
960 | check_types( | 1005 | check_types( |
961 | r#" | 1006 | r#" |
@@ -1106,3 +1151,25 @@ fn main() { | |||
1106 | "#, | 1151 | "#, |
1107 | ); | 1152 | ); |
1108 | } | 1153 | } |
1154 | |||
1155 | #[test] | ||
1156 | fn method_on_dyn_impl() { | ||
1157 | check_types( | ||
1158 | r#" | ||
1159 | trait Foo {} | ||
1160 | |||
1161 | impl Foo for u32 {} | ||
1162 | impl dyn Foo + '_ { | ||
1163 | pub fn dyn_foo(&self) -> u32 { | ||
1164 | 0 | ||
1165 | } | ||
1166 | } | ||
1167 | |||
1168 | fn main() { | ||
1169 | let f = &42u32 as &dyn Foo; | ||
1170 | f.dyn_foo(); | ||
1171 | // ^u32 | ||
1172 | } | ||
1173 | "#, | ||
1174 | ); | ||
1175 | } | ||