diff options
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r-- | crates/hir_ty/src/tests/macros.rs | 201 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/method_resolution.rs | 37 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/patterns.rs | 28 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/regression.rs | 76 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/simple.rs | 54 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 1467 |
6 files changed, 1157 insertions, 706 deletions
diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index 86e3d8b86..6588aa46c 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs | |||
@@ -1065,12 +1065,211 @@ fn macro_in_arm() { | |||
1065 | } | 1065 | } |
1066 | "#, | 1066 | "#, |
1067 | expect![[r#" | 1067 | expect![[r#" |
1068 | !0..2 '()': () | ||
1068 | 51..110 '{ ... }; }': () | 1069 | 51..110 '{ ... }; }': () |
1069 | 61..62 'x': u32 | 1070 | 61..62 'x': u32 |
1070 | 65..107 'match ... }': u32 | 1071 | 65..107 'match ... }': u32 |
1071 | 71..73 '()': () | 1072 | 71..73 '()': () |
1072 | 84..91 'unit!()': () | ||
1073 | 95..100 '92u32': u32 | 1073 | 95..100 '92u32': u32 |
1074 | "#]], | 1074 | "#]], |
1075 | ); | 1075 | ); |
1076 | } | 1076 | } |
1077 | |||
1078 | #[test] | ||
1079 | fn macro_in_type_alias_position() { | ||
1080 | check_infer( | ||
1081 | r#" | ||
1082 | macro_rules! U32 { | ||
1083 | () => { u32 }; | ||
1084 | } | ||
1085 | |||
1086 | trait Foo { | ||
1087 | type Ty; | ||
1088 | } | ||
1089 | |||
1090 | impl<T> Foo for T { | ||
1091 | type Ty = U32!(); | ||
1092 | } | ||
1093 | |||
1094 | type TayTo = U32!(); | ||
1095 | |||
1096 | fn testy() { | ||
1097 | let a: <() as Foo>::Ty; | ||
1098 | let b: TayTo; | ||
1099 | } | ||
1100 | "#, | ||
1101 | expect![[r#" | ||
1102 | 147..196 '{ ...yTo; }': () | ||
1103 | 157..158 'a': u32 | ||
1104 | 185..186 'b': u32 | ||
1105 | "#]], | ||
1106 | ); | ||
1107 | } | ||
1108 | |||
1109 | #[test] | ||
1110 | fn nested_macro_in_type_alias_position() { | ||
1111 | check_infer( | ||
1112 | r#" | ||
1113 | macro_rules! U32Inner2 { | ||
1114 | () => { u32 }; | ||
1115 | } | ||
1116 | |||
1117 | macro_rules! U32Inner1 { | ||
1118 | () => { U32Inner2!() }; | ||
1119 | } | ||
1120 | |||
1121 | macro_rules! U32 { | ||
1122 | () => { U32Inner1!() }; | ||
1123 | } | ||
1124 | |||
1125 | trait Foo { | ||
1126 | type Ty; | ||
1127 | } | ||
1128 | |||
1129 | impl<T> Foo for T { | ||
1130 | type Ty = U32!(); | ||
1131 | } | ||
1132 | |||
1133 | type TayTo = U32!(); | ||
1134 | |||
1135 | fn testy() { | ||
1136 | let a: <() as Foo>::Ty; | ||
1137 | let b: TayTo; | ||
1138 | } | ||
1139 | "#, | ||
1140 | expect![[r#" | ||
1141 | 259..308 '{ ...yTo; }': () | ||
1142 | 269..270 'a': u32 | ||
1143 | 297..298 'b': u32 | ||
1144 | "#]], | ||
1145 | ); | ||
1146 | } | ||
1147 | |||
1148 | #[test] | ||
1149 | fn macros_in_type_alias_position_generics() { | ||
1150 | check_infer( | ||
1151 | r#" | ||
1152 | struct Foo<A, B>(A, B); | ||
1153 | |||
1154 | macro_rules! U32 { | ||
1155 | () => { u32 }; | ||
1156 | } | ||
1157 | |||
1158 | macro_rules! Bar { | ||
1159 | () => { Foo<U32!(), U32!()> }; | ||
1160 | } | ||
1161 | |||
1162 | trait Moo { | ||
1163 | type Ty; | ||
1164 | } | ||
1165 | |||
1166 | impl<T> Moo for T { | ||
1167 | type Ty = Bar!(); | ||
1168 | } | ||
1169 | |||
1170 | type TayTo = Bar!(); | ||
1171 | |||
1172 | fn main() { | ||
1173 | let a: <() as Moo>::Ty; | ||
1174 | let b: TayTo; | ||
1175 | } | ||
1176 | "#, | ||
1177 | expect![[r#" | ||
1178 | 228..277 '{ ...yTo; }': () | ||
1179 | 238..239 'a': Foo<u32, u32> | ||
1180 | 266..267 'b': Foo<u32, u32> | ||
1181 | "#]], | ||
1182 | ); | ||
1183 | } | ||
1184 | |||
1185 | #[test] | ||
1186 | fn macros_in_type_position() { | ||
1187 | check_infer( | ||
1188 | r#" | ||
1189 | struct Foo<A, B>(A, B); | ||
1190 | |||
1191 | macro_rules! U32 { | ||
1192 | () => { u32 }; | ||
1193 | } | ||
1194 | |||
1195 | macro_rules! Bar { | ||
1196 | () => { Foo<U32!(), U32!()> }; | ||
1197 | } | ||
1198 | |||
1199 | fn main() { | ||
1200 | let a: Bar!(); | ||
1201 | } | ||
1202 | "#, | ||
1203 | expect![[r#" | ||
1204 | 133..155 '{ ...!(); }': () | ||
1205 | 143..144 'a': Foo<u32, u32> | ||
1206 | "#]], | ||
1207 | ); | ||
1208 | } | ||
1209 | |||
1210 | #[test] | ||
1211 | fn macros_in_type_generics() { | ||
1212 | check_infer( | ||
1213 | r#" | ||
1214 | struct Foo<A, B>(A, B); | ||
1215 | |||
1216 | macro_rules! U32 { | ||
1217 | () => { u32 }; | ||
1218 | } | ||
1219 | |||
1220 | macro_rules! Bar { | ||
1221 | () => { Foo<U32!(), U32!()> }; | ||
1222 | } | ||
1223 | |||
1224 | trait Moo { | ||
1225 | type Ty; | ||
1226 | } | ||
1227 | |||
1228 | impl<T> Moo for T { | ||
1229 | type Ty = Foo<Bar!(), Bar!()>; | ||
1230 | } | ||
1231 | |||
1232 | type TayTo = Foo<Bar!(), U32!()>; | ||
1233 | |||
1234 | fn main() { | ||
1235 | let a: <() as Moo>::Ty; | ||
1236 | let b: TayTo; | ||
1237 | } | ||
1238 | "#, | ||
1239 | expect![[r#" | ||
1240 | 254..303 '{ ...yTo; }': () | ||
1241 | 264..265 'a': Foo<Foo<u32, u32>, Foo<u32, u32>> | ||
1242 | 292..293 'b': Foo<Foo<u32, u32>, u32> | ||
1243 | "#]], | ||
1244 | ); | ||
1245 | } | ||
1246 | |||
1247 | #[test] | ||
1248 | fn infinitely_recursive_macro_type() { | ||
1249 | check_infer( | ||
1250 | r#" | ||
1251 | struct Bar<T, X>(T, X); | ||
1252 | |||
1253 | macro_rules! Foo { | ||
1254 | () => { Foo!() } | ||
1255 | } | ||
1256 | |||
1257 | macro_rules! U32 { | ||
1258 | () => { u32 } | ||
1259 | } | ||
1260 | |||
1261 | type A = Foo!(); | ||
1262 | type B = Bar<Foo!(), U32!()>; | ||
1263 | |||
1264 | fn main() { | ||
1265 | let a: A; | ||
1266 | let b: B; | ||
1267 | } | ||
1268 | "#, | ||
1269 | expect![[r#" | ||
1270 | 166..197 '{ ...: B; }': () | ||
1271 | 176..177 'a': {unknown} | ||
1272 | 190..191 'b': Bar<{unknown}, u32> | ||
1273 | "#]], | ||
1274 | ); | ||
1275 | } | ||
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index 4b2c82b41..a4c132bc5 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs | |||
@@ -1294,7 +1294,7 @@ mod b { | |||
1294 | } | 1294 | } |
1295 | 1295 | ||
1296 | #[test] | 1296 | #[test] |
1297 | fn impl_in_unnamed_const() { | 1297 | fn trait_impl_in_unnamed_const() { |
1298 | check_types( | 1298 | check_types( |
1299 | r#" | 1299 | r#" |
1300 | struct S; | 1300 | struct S; |
@@ -1314,3 +1314,38 @@ fn f() { | |||
1314 | "#, | 1314 | "#, |
1315 | ); | 1315 | ); |
1316 | } | 1316 | } |
1317 | |||
1318 | #[test] | ||
1319 | fn inherent_impl_in_unnamed_const() { | ||
1320 | check_types( | ||
1321 | r#" | ||
1322 | struct S; | ||
1323 | |||
1324 | const _: () = { | ||
1325 | impl S { | ||
1326 | fn method(&self) -> u16 { 0 } | ||
1327 | |||
1328 | pub(super) fn super_method(&self) -> u16 { 0 } | ||
1329 | |||
1330 | pub(crate) fn crate_method(&self) -> u16 { 0 } | ||
1331 | |||
1332 | pub fn pub_method(&self) -> u16 { 0 } | ||
1333 | } | ||
1334 | }; | ||
1335 | |||
1336 | fn f() { | ||
1337 | S.method(); | ||
1338 | //^^^^^^^^^^ u16 | ||
1339 | |||
1340 | S.super_method(); | ||
1341 | //^^^^^^^^^^^^^^^^ u16 | ||
1342 | |||
1343 | S.crate_method(); | ||
1344 | //^^^^^^^^^^^^^^^^ u16 | ||
1345 | |||
1346 | S.pub_method(); | ||
1347 | //^^^^^^^^^^^^^^ u16 | ||
1348 | } | ||
1349 | "#, | ||
1350 | ); | ||
1351 | } | ||
diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs index 85a28e76b..f514b3efe 100644 --- a/crates/hir_ty/src/tests/patterns.rs +++ b/crates/hir_ty/src/tests/patterns.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use expect_test::expect; | 1 | use expect_test::expect; |
2 | 2 | ||
3 | use super::{check_infer, check_infer_with_mismatches}; | 3 | use super::{check_infer, check_infer_with_mismatches, check_types}; |
4 | 4 | ||
5 | #[test] | 5 | #[test] |
6 | fn infer_pattern() { | 6 | fn infer_pattern() { |
@@ -825,3 +825,29 @@ fn foo(foo: Foo) { | |||
825 | "#]], | 825 | "#]], |
826 | ); | 826 | ); |
827 | } | 827 | } |
828 | |||
829 | #[test] | ||
830 | fn macro_pat() { | ||
831 | check_types( | ||
832 | r#" | ||
833 | macro_rules! pat { | ||
834 | ($name:ident) => { Enum::Variant1($name) } | ||
835 | } | ||
836 | |||
837 | enum Enum { | ||
838 | Variant1(u8), | ||
839 | Variant2, | ||
840 | } | ||
841 | |||
842 | fn f(e: Enum) { | ||
843 | match e { | ||
844 | pat!(bind) => { | ||
845 | bind; | ||
846 | //^^^^ u8 | ||
847 | } | ||
848 | Enum::Variant2 => {} | ||
849 | } | ||
850 | } | ||
851 | "#, | ||
852 | ) | ||
853 | } | ||
diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index b69f86050..d14f5c9bb 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs | |||
@@ -974,3 +974,79 @@ fn param_overrides_fn() { | |||
974 | "#, | 974 | "#, |
975 | ) | 975 | ) |
976 | } | 976 | } |
977 | |||
978 | #[test] | ||
979 | fn lifetime_from_chalk_during_deref() { | ||
980 | check_types( | ||
981 | r#" | ||
982 | #[lang = "deref"] | ||
983 | pub trait Deref { | ||
984 | type Target; | ||
985 | } | ||
986 | |||
987 | struct Box<T: ?Sized> {} | ||
988 | impl<T> Deref for Box<T> { | ||
989 | type Target = T; | ||
990 | |||
991 | fn deref(&self) -> &Self::Target { | ||
992 | loop {} | ||
993 | } | ||
994 | } | ||
995 | |||
996 | trait Iterator { | ||
997 | type Item; | ||
998 | } | ||
999 | |||
1000 | pub struct Iter<'a, T: 'a> { | ||
1001 | inner: Box<dyn IterTrait<'a, T, Item = &'a T> + 'a>, | ||
1002 | } | ||
1003 | |||
1004 | trait IterTrait<'a, T: 'a>: Iterator<Item = &'a T> { | ||
1005 | fn clone_box(&self); | ||
1006 | } | ||
1007 | |||
1008 | fn clone_iter<T>(s: Iter<T>) { | ||
1009 | s.inner.clone_box(); | ||
1010 | //^^^^^^^^^^^^^^^^^^^ () | ||
1011 | } | ||
1012 | "#, | ||
1013 | ) | ||
1014 | } | ||
1015 | |||
1016 | #[test] | ||
1017 | fn issue_8686() { | ||
1018 | check_infer( | ||
1019 | r#" | ||
1020 | pub trait Try: FromResidual { | ||
1021 | type Output; | ||
1022 | type Residual; | ||
1023 | } | ||
1024 | pub trait FromResidual<R = <Self as Try>::Residual> { | ||
1025 | fn from_residual(residual: R) -> Self; | ||
1026 | } | ||
1027 | |||
1028 | struct ControlFlow<B, C>; | ||
1029 | impl<B, C> Try for ControlFlow<B, C> { | ||
1030 | type Output = C; | ||
1031 | type Residual = ControlFlow<B, !>; | ||
1032 | } | ||
1033 | impl<B, C> FromResidual for ControlFlow<B, C> { | ||
1034 | fn from_residual(r: ControlFlow<B, !>) -> Self { ControlFlow } | ||
1035 | } | ||
1036 | |||
1037 | fn test() { | ||
1038 | ControlFlow::from_residual(ControlFlow::<u32, !>); | ||
1039 | } | ||
1040 | "#, | ||
1041 | expect![[r#" | ||
1042 | 144..152 'residual': R | ||
1043 | 365..366 'r': ControlFlow<B, !> | ||
1044 | 395..410 '{ ControlFlow }': ControlFlow<B, C> | ||
1045 | 397..408 'ControlFlow': ControlFlow<B, C> | ||
1046 | 424..482 '{ ...!>); }': () | ||
1047 | 430..456 'Contro...sidual': fn from_residual<ControlFlow<u32, {unknown}>, ControlFlow<u32, !>>(ControlFlow<u32, !>) -> ControlFlow<u32, {unknown}> | ||
1048 | 430..479 'Contro...2, !>)': ControlFlow<u32, {unknown}> | ||
1049 | 457..478 'Contro...32, !>': ControlFlow<u32, !> | ||
1050 | "#]], | ||
1051 | ); | ||
1052 | } | ||
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index 84c5c05fd..0eefd70f2 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs | |||
@@ -1029,6 +1029,42 @@ fn infer_in_elseif() { | |||
1029 | } | 1029 | } |
1030 | 1030 | ||
1031 | #[test] | 1031 | #[test] |
1032 | fn infer_closure_unify() { | ||
1033 | check_infer( | ||
1034 | r#" | ||
1035 | fn foo(f: bool) { | ||
1036 | let a = |x| x; | ||
1037 | let b = |x| x; | ||
1038 | let id = if f { a } else { b }; | ||
1039 | id(123); | ||
1040 | } | ||
1041 | "#, | ||
1042 | expect![[r#" | ||
1043 | 7..8 'f': bool | ||
1044 | 16..106 '{ ...23); }': () | ||
1045 | 26..27 'a': |i32| -> i32 | ||
1046 | 30..35 '|x| x': |i32| -> i32 | ||
1047 | 31..32 'x': i32 | ||
1048 | 34..35 'x': i32 | ||
1049 | 45..46 'b': |i32| -> i32 | ||
1050 | 49..54 '|x| x': |i32| -> i32 | ||
1051 | 50..51 'x': i32 | ||
1052 | 53..54 'x': i32 | ||
1053 | 64..66 'id': |i32| -> i32 | ||
1054 | 69..90 'if f {... { b }': |i32| -> i32 | ||
1055 | 72..73 'f': bool | ||
1056 | 74..79 '{ a }': |i32| -> i32 | ||
1057 | 76..77 'a': |i32| -> i32 | ||
1058 | 85..90 '{ b }': |i32| -> i32 | ||
1059 | 87..88 'b': |i32| -> i32 | ||
1060 | 96..98 'id': |i32| -> i32 | ||
1061 | 96..103 'id(123)': i32 | ||
1062 | 99..102 '123': i32 | ||
1063 | "#]], | ||
1064 | ) | ||
1065 | } | ||
1066 | |||
1067 | #[test] | ||
1032 | fn infer_if_match_with_return() { | 1068 | fn infer_if_match_with_return() { |
1033 | check_infer( | 1069 | check_infer( |
1034 | r#" | 1070 | r#" |
@@ -1765,6 +1801,24 @@ fn main() { | |||
1765 | } | 1801 | } |
1766 | 1802 | ||
1767 | #[test] | 1803 | #[test] |
1804 | fn shadowing_primitive_with_inner_items() { | ||
1805 | check_types( | ||
1806 | r#" | ||
1807 | struct i32; | ||
1808 | struct Foo; | ||
1809 | |||
1810 | impl i32 { fn foo(&self) -> Foo { Foo } } | ||
1811 | |||
1812 | fn main() { | ||
1813 | fn inner() {} | ||
1814 | let x: i32 = i32; | ||
1815 | x.foo(); | ||
1816 | //^ Foo | ||
1817 | }"#, | ||
1818 | ); | ||
1819 | } | ||
1820 | |||
1821 | #[test] | ||
1768 | fn not_shadowing_primitive_by_module() { | 1822 | fn not_shadowing_primitive_by_module() { |
1769 | check_types( | 1823 | check_types( |
1770 | r#" | 1824 | r#" |
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 65b71fdfa..ffc7c8ef4 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -263,15 +263,14 @@ mod ops { | |||
263 | fn infer_from_bound_1() { | 263 | fn infer_from_bound_1() { |
264 | check_infer( | 264 | check_infer( |
265 | r#" | 265 | r#" |
266 | trait Trait<T> {} | 266 | trait Trait<T> {} |
267 | struct S<T>(T); | 267 | struct S<T>(T); |
268 | impl<U> Trait<U> for S<U> {} | 268 | impl<U> Trait<U> for S<U> {} |
269 | fn foo<T: Trait<u32>>(t: T) {} | 269 | fn foo<T: Trait<u32>>(t: T) {} |
270 | fn test() { | 270 | fn test() { |
271 | let s = S(unknown); | 271 | let s = S(unknown); |
272 | foo(s); | 272 | foo(s); |
273 | } | 273 | }"#, |
274 | "#, | ||
275 | expect![[r#" | 274 | expect![[r#" |
276 | 85..86 't': T | 275 | 85..86 't': T |
277 | 91..93 '{}': () | 276 | 91..93 '{}': () |
@@ -291,15 +290,14 @@ fn infer_from_bound_1() { | |||
291 | fn infer_from_bound_2() { | 290 | fn infer_from_bound_2() { |
292 | check_infer( | 291 | check_infer( |
293 | r#" | 292 | r#" |
294 | trait Trait<T> {} | 293 | trait Trait<T> {} |
295 | struct S<T>(T); | 294 | struct S<T>(T); |
296 | impl<U> Trait<U> for S<U> {} | 295 | impl<U> Trait<U> for S<U> {} |
297 | fn foo<U, T: Trait<U>>(t: T) -> U {} | 296 | fn foo<U, T: Trait<U>>(t: T) -> U {} |
298 | fn test() { | 297 | fn test() { |
299 | let s = S(unknown); | 298 | let s = S(unknown); |
300 | let x: u32 = foo(s); | 299 | let x: u32 = foo(s); |
301 | } | 300 | }"#, |
302 | "#, | ||
303 | expect![[r#" | 301 | expect![[r#" |
304 | 86..87 't': T | 302 | 86..87 't': T |
305 | 97..99 '{}': () | 303 | 97..99 '{}': () |
@@ -321,13 +319,12 @@ fn trait_default_method_self_bound_implements_trait() { | |||
321 | cov_mark::check!(trait_self_implements_self); | 319 | cov_mark::check!(trait_self_implements_self); |
322 | check_infer( | 320 | check_infer( |
323 | r#" | 321 | r#" |
324 | trait Trait { | 322 | trait Trait { |
325 | fn foo(&self) -> i64; | 323 | fn foo(&self) -> i64; |
326 | fn bar(&self) -> { | 324 | fn bar(&self) -> { |
327 | let x = self.foo(); | 325 | let x = self.foo(); |
328 | } | 326 | } |
329 | } | 327 | }"#, |
330 | "#, | ||
331 | expect![[r#" | 328 | expect![[r#" |
332 | 26..30 'self': &Self | 329 | 26..30 'self': &Self |
333 | 52..56 'self': &Self | 330 | 52..56 'self': &Self |
@@ -343,15 +340,14 @@ fn trait_default_method_self_bound_implements_trait() { | |||
343 | fn trait_default_method_self_bound_implements_super_trait() { | 340 | fn trait_default_method_self_bound_implements_super_trait() { |
344 | check_infer( | 341 | check_infer( |
345 | r#" | 342 | r#" |
346 | trait SuperTrait { | 343 | trait SuperTrait { |
347 | fn foo(&self) -> i64; | 344 | fn foo(&self) -> i64; |
348 | } | 345 | } |
349 | trait Trait: SuperTrait { | 346 | trait Trait: SuperTrait { |
350 | fn bar(&self) -> { | 347 | fn bar(&self) -> { |
351 | let x = self.foo(); | 348 | let x = self.foo(); |
352 | } | 349 | } |
353 | } | 350 | }"#, |
354 | "#, | ||
355 | expect![[r#" | 351 | expect![[r#" |
356 | 31..35 'self': &Self | 352 | 31..35 'self': &Self |
357 | 85..89 'self': &Self | 353 | 85..89 'self': &Self |
@@ -367,18 +363,17 @@ fn trait_default_method_self_bound_implements_super_trait() { | |||
367 | fn infer_project_associated_type() { | 363 | fn infer_project_associated_type() { |
368 | check_infer( | 364 | check_infer( |
369 | r#" | 365 | r#" |
370 | trait Iterable { | 366 | trait Iterable { |
371 | type Item; | 367 | type Item; |
372 | } | 368 | } |
373 | struct S; | 369 | struct S; |
374 | impl Iterable for S { type Item = u32; } | 370 | impl Iterable for S { type Item = u32; } |
375 | fn test<T: Iterable>() { | 371 | fn test<T: Iterable>() { |
376 | let x: <S as Iterable>::Item = 1; | 372 | let x: <S as Iterable>::Item = 1; |
377 | let y: <T as Iterable>::Item = no_matter; | 373 | let y: <T as Iterable>::Item = no_matter; |
378 | let z: T::Item = no_matter; | 374 | let z: T::Item = no_matter; |
379 | let a: <T>::Item = no_matter; | 375 | let a: <T>::Item = no_matter; |
380 | } | 376 | }"#, |
381 | "#, | ||
382 | expect![[r#" | 377 | expect![[r#" |
383 | 108..261 '{ ...ter; }': () | 378 | 108..261 '{ ...ter; }': () |
384 | 118..119 'x': u32 | 379 | 118..119 'x': u32 |
@@ -397,20 +392,19 @@ fn infer_project_associated_type() { | |||
397 | fn infer_return_associated_type() { | 392 | fn infer_return_associated_type() { |
398 | check_infer( | 393 | check_infer( |
399 | r#" | 394 | r#" |
400 | trait Iterable { | 395 | trait Iterable { |
401 | type Item; | 396 | type Item; |
402 | } | 397 | } |
403 | struct S; | 398 | struct S; |
404 | impl Iterable for S { type Item = u32; } | 399 | impl Iterable for S { type Item = u32; } |
405 | fn foo1<T: Iterable>(t: T) -> T::Item {} | 400 | fn foo1<T: Iterable>(t: T) -> T::Item {} |
406 | fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {} | 401 | fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {} |
407 | fn foo3<T: Iterable>(t: T) -> <T>::Item {} | 402 | fn foo3<T: Iterable>(t: T) -> <T>::Item {} |
408 | fn test() { | 403 | fn test() { |
409 | let x = foo1(S); | 404 | let x = foo1(S); |
410 | let y = foo2(S); | 405 | let y = foo2(S); |
411 | let z = foo3(S); | 406 | let z = foo3(S); |
412 | } | 407 | }"#, |
413 | "#, | ||
414 | expect![[r#" | 408 | expect![[r#" |
415 | 106..107 't': T | 409 | 106..107 't': T |
416 | 123..125 '{}': () | 410 | 123..125 '{}': () |
@@ -439,13 +433,12 @@ fn infer_return_associated_type() { | |||
439 | fn infer_associated_type_bound() { | 433 | fn infer_associated_type_bound() { |
440 | check_infer( | 434 | check_infer( |
441 | r#" | 435 | r#" |
442 | trait Iterable { | 436 | trait Iterable { |
443 | type Item; | 437 | type Item; |
444 | } | 438 | } |
445 | fn test<T: Iterable<Item=u32>>() { | 439 | fn test<T: Iterable<Item=u32>>() { |
446 | let y: T::Item = unknown; | 440 | let y: T::Item = unknown; |
447 | } | 441 | }"#, |
448 | "#, | ||
449 | expect![[r#" | 442 | expect![[r#" |
450 | 67..100 '{ ...own; }': () | 443 | 67..100 '{ ...own; }': () |
451 | 77..78 'y': u32 | 444 | 77..78 'y': u32 |
@@ -458,9 +451,8 @@ fn infer_associated_type_bound() { | |||
458 | fn infer_const_body() { | 451 | fn infer_const_body() { |
459 | check_infer( | 452 | check_infer( |
460 | r#" | 453 | r#" |
461 | const A: u32 = 1 + 1; | 454 | const A: u32 = 1 + 1; |
462 | static B: u64 = { let x = 1; x }; | 455 | static B: u64 = { let x = 1; x };"#, |
463 | "#, | ||
464 | expect![[r#" | 456 | expect![[r#" |
465 | 15..16 '1': u32 | 457 | 15..16 '1': u32 |
466 | 15..20 '1 + 1': u32 | 458 | 15..20 '1 + 1': u32 |
@@ -477,13 +469,12 @@ fn infer_const_body() { | |||
477 | fn tuple_struct_fields() { | 469 | fn tuple_struct_fields() { |
478 | check_infer( | 470 | check_infer( |
479 | r#" | 471 | r#" |
480 | struct S(i32, u64); | 472 | struct S(i32, u64); |
481 | fn test() -> u64 { | 473 | fn test() -> u64 { |
482 | let a = S(4, 6); | 474 | let a = S(4, 6); |
483 | let b = a.0; | 475 | let b = a.0; |
484 | a.1 | 476 | a.1 |
485 | } | 477 | }"#, |
486 | "#, | ||
487 | expect![[r#" | 478 | expect![[r#" |
488 | 37..86 '{ ... a.1 }': u64 | 479 | 37..86 '{ ... a.1 }': u64 |
489 | 47..48 'a': S | 480 | 47..48 'a': S |
@@ -504,13 +495,12 @@ fn tuple_struct_fields() { | |||
504 | fn tuple_struct_with_fn() { | 495 | fn tuple_struct_with_fn() { |
505 | check_infer( | 496 | check_infer( |
506 | r#" | 497 | r#" |
507 | struct S(fn(u32) -> u64); | 498 | struct S(fn(u32) -> u64); |
508 | fn test() -> u64 { | 499 | fn test() -> u64 { |
509 | let a = S(|i| 2*i); | 500 | let a = S(|i| 2*i); |
510 | let b = a.0(4); | 501 | let b = a.0(4); |
511 | a.0(2) | 502 | a.0(2) |
512 | } | 503 | }"#, |
513 | "#, | ||
514 | expect![[r#" | 504 | expect![[r#" |
515 | 43..101 '{ ...0(2) }': u64 | 505 | 43..101 '{ ...0(2) }': u64 |
516 | 53..54 'a': S | 506 | 53..54 'a': S |
@@ -949,27 +939,26 @@ fn test<T: ApplyL>(t: T) { | |||
949 | fn argument_impl_trait() { | 939 | fn argument_impl_trait() { |
950 | check_infer_with_mismatches( | 940 | check_infer_with_mismatches( |
951 | r#" | 941 | r#" |
952 | trait Trait<T> { | 942 | trait Trait<T> { |
953 | fn foo(&self) -> T; | 943 | fn foo(&self) -> T; |
954 | fn foo2(&self) -> i64; | 944 | fn foo2(&self) -> i64; |
955 | } | 945 | } |
956 | fn bar(x: impl Trait<u16>) {} | 946 | fn bar(x: impl Trait<u16>) {} |
957 | struct S<T>(T); | 947 | struct S<T>(T); |
958 | impl<T> Trait<T> for S<T> {} | 948 | impl<T> Trait<T> for S<T> {} |
959 | 949 | ||
960 | fn test(x: impl Trait<u64>, y: &impl Trait<u32>) { | 950 | fn test(x: impl Trait<u64>, y: &impl Trait<u32>) { |
961 | x; | 951 | x; |
962 | y; | 952 | y; |
963 | let z = S(1); | 953 | let z = S(1); |
964 | bar(z); | 954 | bar(z); |
965 | x.foo(); | 955 | x.foo(); |
966 | y.foo(); | 956 | y.foo(); |
967 | z.foo(); | 957 | z.foo(); |
968 | x.foo2(); | 958 | x.foo2(); |
969 | y.foo2(); | 959 | y.foo2(); |
970 | z.foo2(); | 960 | z.foo2(); |
971 | } | 961 | }"#, |
972 | "#, | ||
973 | expect![[r#" | 962 | expect![[r#" |
974 | 29..33 'self': &Self | 963 | 29..33 'self': &Self |
975 | 54..58 'self': &Self | 964 | 54..58 'self': &Self |
@@ -1007,30 +996,29 @@ fn argument_impl_trait() { | |||
1007 | fn argument_impl_trait_type_args_1() { | 996 | fn argument_impl_trait_type_args_1() { |
1008 | check_infer_with_mismatches( | 997 | check_infer_with_mismatches( |
1009 | r#" | 998 | r#" |
1010 | trait Trait {} | 999 | trait Trait {} |
1011 | trait Foo { | 1000 | trait Foo { |
1012 | // this function has an implicit Self param, an explicit type param, | 1001 | // this function has an implicit Self param, an explicit type param, |
1013 | // and an implicit impl Trait param! | 1002 | // and an implicit impl Trait param! |
1014 | fn bar<T>(x: impl Trait) -> T { loop {} } | 1003 | fn bar<T>(x: impl Trait) -> T { loop {} } |
1015 | } | 1004 | } |
1016 | fn foo<T>(x: impl Trait) -> T { loop {} } | 1005 | fn foo<T>(x: impl Trait) -> T { loop {} } |
1017 | struct S; | 1006 | struct S; |
1018 | impl Trait for S {} | 1007 | impl Trait for S {} |
1019 | struct F; | 1008 | struct F; |
1020 | impl Foo for F {} | 1009 | impl Foo for F {} |
1021 | 1010 | ||
1022 | fn test() { | 1011 | fn test() { |
1023 | Foo::bar(S); | 1012 | Foo::bar(S); |
1024 | <F as Foo>::bar(S); | 1013 | <F as Foo>::bar(S); |
1025 | F::bar(S); | 1014 | F::bar(S); |
1026 | Foo::bar::<u32>(S); | 1015 | Foo::bar::<u32>(S); |
1027 | <F as Foo>::bar::<u32>(S); | 1016 | <F as Foo>::bar::<u32>(S); |
1028 | 1017 | ||
1029 | foo(S); | 1018 | foo(S); |
1030 | foo::<u32>(S); | 1019 | foo::<u32>(S); |
1031 | foo::<u32, i32>(S); // we should ignore the extraneous i32 | 1020 | foo::<u32, i32>(S); // we should ignore the extraneous i32 |
1032 | } | 1021 | }"#, |
1033 | "#, | ||
1034 | expect![[r#" | 1022 | expect![[r#" |
1035 | 155..156 'x': impl Trait | 1023 | 155..156 'x': impl Trait |
1036 | 175..186 '{ loop {} }': T | 1024 | 175..186 '{ loop {} }': T |
@@ -1073,21 +1061,20 @@ fn argument_impl_trait_type_args_1() { | |||
1073 | fn argument_impl_trait_type_args_2() { | 1061 | fn argument_impl_trait_type_args_2() { |
1074 | check_infer_with_mismatches( | 1062 | check_infer_with_mismatches( |
1075 | r#" | 1063 | r#" |
1076 | trait Trait {} | 1064 | trait Trait {} |
1077 | struct S; | 1065 | struct S; |
1078 | impl Trait for S {} | 1066 | impl Trait for S {} |
1079 | struct F<T>; | 1067 | struct F<T>; |
1080 | impl<T> F<T> { | 1068 | impl<T> F<T> { |
1081 | fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} } | 1069 | fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} } |
1082 | } | 1070 | } |
1083 | 1071 | ||
1084 | fn test() { | 1072 | fn test() { |
1085 | F.foo(S); | 1073 | F.foo(S); |
1086 | F::<u32>.foo(S); | 1074 | F::<u32>.foo(S); |
1087 | F::<u32>.foo::<i32>(S); | 1075 | F::<u32>.foo::<i32>(S); |
1088 | F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored | 1076 | F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored |
1089 | } | 1077 | }"#, |
1090 | "#, | ||
1091 | expect![[r#" | 1078 | expect![[r#" |
1092 | 87..91 'self': F<T> | 1079 | 87..91 'self': F<T> |
1093 | 93..94 'x': impl Trait | 1080 | 93..94 'x': impl Trait |
@@ -1115,15 +1102,14 @@ fn argument_impl_trait_type_args_2() { | |||
1115 | fn argument_impl_trait_to_fn_pointer() { | 1102 | fn argument_impl_trait_to_fn_pointer() { |
1116 | check_infer_with_mismatches( | 1103 | check_infer_with_mismatches( |
1117 | r#" | 1104 | r#" |
1118 | trait Trait {} | 1105 | trait Trait {} |
1119 | fn foo(x: impl Trait) { loop {} } | 1106 | fn foo(x: impl Trait) { loop {} } |
1120 | struct S; | 1107 | struct S; |
1121 | impl Trait for S {} | 1108 | impl Trait for S {} |
1122 | 1109 | ||
1123 | fn test() { | 1110 | fn test() { |
1124 | let f: fn(S) -> () = foo; | 1111 | let f: fn(S) -> () = foo; |
1125 | } | 1112 | }"#, |
1126 | "#, | ||
1127 | expect![[r#" | 1113 | expect![[r#" |
1128 | 22..23 'x': impl Trait | 1114 | 22..23 'x': impl Trait |
1129 | 37..48 '{ loop {} }': () | 1115 | 37..48 '{ loop {} }': () |
@@ -1140,24 +1126,23 @@ fn argument_impl_trait_to_fn_pointer() { | |||
1140 | fn impl_trait() { | 1126 | fn impl_trait() { |
1141 | check_infer( | 1127 | check_infer( |
1142 | r#" | 1128 | r#" |
1143 | trait Trait<T> { | 1129 | trait Trait<T> { |
1144 | fn foo(&self) -> T; | 1130 | fn foo(&self) -> T; |
1145 | fn foo2(&self) -> i64; | 1131 | fn foo2(&self) -> i64; |
1146 | } | 1132 | } |
1147 | fn bar() -> impl Trait<u64> {} | 1133 | fn bar() -> impl Trait<u64> {} |
1148 | 1134 | ||
1149 | fn test(x: impl Trait<u64>, y: &impl Trait<u64>) { | 1135 | fn test(x: impl Trait<u64>, y: &impl Trait<u64>) { |
1150 | x; | 1136 | x; |
1151 | y; | 1137 | y; |
1152 | let z = bar(); | 1138 | let z = bar(); |
1153 | x.foo(); | 1139 | x.foo(); |
1154 | y.foo(); | 1140 | y.foo(); |
1155 | z.foo(); | 1141 | z.foo(); |
1156 | x.foo2(); | 1142 | x.foo2(); |
1157 | y.foo2(); | 1143 | y.foo2(); |
1158 | z.foo2(); | 1144 | z.foo2(); |
1159 | } | 1145 | }"#, |
1160 | "#, | ||
1161 | expect![[r#" | 1146 | expect![[r#" |
1162 | 29..33 'self': &Self | 1147 | 29..33 'self': &Self |
1163 | 54..58 'self': &Self | 1148 | 54..58 'self': &Self |
@@ -1191,16 +1176,15 @@ fn simple_return_pos_impl_trait() { | |||
1191 | cov_mark::check!(lower_rpit); | 1176 | cov_mark::check!(lower_rpit); |
1192 | check_infer( | 1177 | check_infer( |
1193 | r#" | 1178 | r#" |
1194 | trait Trait<T> { | 1179 | trait Trait<T> { |
1195 | fn foo(&self) -> T; | 1180 | fn foo(&self) -> T; |
1196 | } | 1181 | } |
1197 | fn bar() -> impl Trait<u64> { loop {} } | 1182 | fn bar() -> impl Trait<u64> { loop {} } |
1198 | 1183 | ||
1199 | fn test() { | 1184 | fn test() { |
1200 | let a = bar(); | 1185 | let a = bar(); |
1201 | a.foo(); | 1186 | a.foo(); |
1202 | } | 1187 | }"#, |
1203 | "#, | ||
1204 | expect![[r#" | 1188 | expect![[r#" |
1205 | 29..33 'self': &Self | 1189 | 29..33 'self': &Self |
1206 | 71..82 '{ loop {} }': ! | 1190 | 71..82 '{ loop {} }': ! |
@@ -1220,25 +1204,24 @@ fn simple_return_pos_impl_trait() { | |||
1220 | fn more_return_pos_impl_trait() { | 1204 | fn more_return_pos_impl_trait() { |
1221 | check_infer( | 1205 | check_infer( |
1222 | r#" | 1206 | r#" |
1223 | trait Iterator { | 1207 | trait Iterator { |
1224 | type Item; | 1208 | type Item; |
1225 | fn next(&mut self) -> Self::Item; | 1209 | fn next(&mut self) -> Self::Item; |
1226 | } | 1210 | } |
1227 | trait Trait<T> { | 1211 | trait Trait<T> { |
1228 | fn foo(&self) -> T; | 1212 | fn foo(&self) -> T; |
1229 | } | 1213 | } |
1230 | fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} } | 1214 | fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} } |
1231 | fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} } | 1215 | fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} } |
1232 | 1216 | ||
1233 | fn test() { | 1217 | fn test() { |
1234 | let (a, b) = bar(); | 1218 | let (a, b) = bar(); |
1235 | a.next().foo(); | 1219 | a.next().foo(); |
1236 | b.foo(); | 1220 | b.foo(); |
1237 | let (c, d) = baz(1u128); | 1221 | let (c, d) = baz(1u128); |
1238 | c.next().foo(); | 1222 | c.next().foo(); |
1239 | d.foo(); | 1223 | d.foo(); |
1240 | } | 1224 | }"#, |
1241 | "#, | ||
1242 | expect![[r#" | 1225 | expect![[r#" |
1243 | 49..53 'self': &mut Self | 1226 | 49..53 'self': &mut Self |
1244 | 101..105 'self': &Self | 1227 | 101..105 'self': &Self |
@@ -1279,24 +1262,23 @@ fn more_return_pos_impl_trait() { | |||
1279 | fn dyn_trait() { | 1262 | fn dyn_trait() { |
1280 | check_infer( | 1263 | check_infer( |
1281 | r#" | 1264 | r#" |
1282 | trait Trait<T> { | 1265 | trait Trait<T> { |
1283 | fn foo(&self) -> T; | 1266 | fn foo(&self) -> T; |
1284 | fn foo2(&self) -> i64; | 1267 | fn foo2(&self) -> i64; |
1285 | } | 1268 | } |
1286 | fn bar() -> dyn Trait<u64> {} | 1269 | fn bar() -> dyn Trait<u64> {} |
1287 | 1270 | ||
1288 | fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) { | 1271 | fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) { |
1289 | x; | 1272 | x; |
1290 | y; | 1273 | y; |
1291 | let z = bar(); | 1274 | let z = bar(); |
1292 | x.foo(); | 1275 | x.foo(); |
1293 | y.foo(); | 1276 | y.foo(); |
1294 | z.foo(); | 1277 | z.foo(); |
1295 | x.foo2(); | 1278 | x.foo2(); |
1296 | y.foo2(); | 1279 | y.foo2(); |
1297 | z.foo2(); | 1280 | z.foo2(); |
1298 | } | 1281 | }"#, |
1299 | "#, | ||
1300 | expect![[r#" | 1282 | expect![[r#" |
1301 | 29..33 'self': &Self | 1283 | 29..33 'self': &Self |
1302 | 54..58 'self': &Self | 1284 | 54..58 'self': &Self |
@@ -1329,22 +1311,21 @@ fn dyn_trait() { | |||
1329 | fn dyn_trait_in_impl() { | 1311 | fn dyn_trait_in_impl() { |
1330 | check_infer( | 1312 | check_infer( |
1331 | r#" | 1313 | r#" |
1332 | trait Trait<T, U> { | 1314 | trait Trait<T, U> { |
1333 | fn foo(&self) -> (T, U); | 1315 | fn foo(&self) -> (T, U); |
1334 | } | 1316 | } |
1335 | struct S<T, U> {} | 1317 | struct S<T, U> {} |
1336 | impl<T, U> S<T, U> { | 1318 | impl<T, U> S<T, U> { |
1337 | fn bar(&self) -> &dyn Trait<T, U> { loop {} } | 1319 | fn bar(&self) -> &dyn Trait<T, U> { loop {} } |
1338 | } | 1320 | } |
1339 | trait Trait2<T, U> { | 1321 | trait Trait2<T, U> { |
1340 | fn baz(&self) -> (T, U); | 1322 | fn baz(&self) -> (T, U); |
1341 | } | 1323 | } |
1342 | impl<T, U> Trait2<T, U> for dyn Trait<T, U> { } | 1324 | impl<T, U> Trait2<T, U> for dyn Trait<T, U> { } |
1343 | 1325 | ||
1344 | fn test(s: S<u32, i32>) { | 1326 | fn test(s: S<u32, i32>) { |
1345 | s.bar().baz(); | 1327 | s.bar().baz(); |
1346 | } | 1328 | }"#, |
1347 | "#, | ||
1348 | expect![[r#" | 1329 | expect![[r#" |
1349 | 32..36 'self': &Self | 1330 | 32..36 'self': &Self |
1350 | 102..106 'self': &S<T, U> | 1331 | 102..106 'self': &S<T, U> |
@@ -1365,20 +1346,19 @@ fn dyn_trait_in_impl() { | |||
1365 | fn dyn_trait_bare() { | 1346 | fn dyn_trait_bare() { |
1366 | check_infer( | 1347 | check_infer( |
1367 | r#" | 1348 | r#" |
1368 | trait Trait { | 1349 | trait Trait { |
1369 | fn foo(&self) -> u64; | 1350 | fn foo(&self) -> u64; |
1370 | } | 1351 | } |
1371 | fn bar() -> Trait {} | 1352 | fn bar() -> Trait {} |
1372 | 1353 | ||
1373 | fn test(x: Trait, y: &Trait) -> u64 { | 1354 | fn test(x: Trait, y: &Trait) -> u64 { |
1374 | x; | 1355 | x; |
1375 | y; | 1356 | y; |
1376 | let z = bar(); | 1357 | let z = bar(); |
1377 | x.foo(); | 1358 | x.foo(); |
1378 | y.foo(); | 1359 | y.foo(); |
1379 | z.foo(); | 1360 | z.foo(); |
1380 | } | 1361 | }"#, |
1381 | "#, | ||
1382 | expect![[r#" | 1362 | expect![[r#" |
1383 | 26..30 'self': &Self | 1363 | 26..30 'self': &Self |
1384 | 60..62 '{}': () | 1364 | 60..62 '{}': () |
@@ -1404,17 +1384,24 @@ fn dyn_trait_bare() { | |||
1404 | fn weird_bounds() { | 1384 | fn weird_bounds() { |
1405 | check_infer( | 1385 | check_infer( |
1406 | r#" | 1386 | r#" |
1407 | trait Trait {} | 1387 | trait Trait {} |
1408 | fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) {} | 1388 | fn test( |
1409 | "#, | 1389 | a: impl Trait + 'lifetime, |
1390 | b: impl 'lifetime, | ||
1391 | c: impl (Trait), | ||
1392 | d: impl ('lifetime), | ||
1393 | e: impl ?Sized, | ||
1394 | f: impl Trait + ?Sized | ||
1395 | ) {} | ||
1396 | "#, | ||
1410 | expect![[r#" | 1397 | expect![[r#" |
1411 | 23..24 'a': impl Trait | 1398 | 28..29 'a': impl Trait |
1412 | 50..51 'b': impl | 1399 | 59..60 'b': impl |
1413 | 69..70 'c': impl Trait | 1400 | 82..83 'c': impl Trait |
1414 | 86..87 'd': impl | 1401 | 103..104 'd': impl |
1415 | 107..108 'e': impl | 1402 | 128..129 'e': impl |
1416 | 123..124 'f': impl Trait | 1403 | 148..149 'f': impl Trait |
1417 | 147..149 '{}': () | 1404 | 173..175 '{}': () |
1418 | "#]], | 1405 | "#]], |
1419 | ); | 1406 | ); |
1420 | } | 1407 | } |
@@ -1439,27 +1426,26 @@ fn test(x: (impl Trait + UnknownTrait)) { | |||
1439 | fn assoc_type_bindings() { | 1426 | fn assoc_type_bindings() { |
1440 | check_infer( | 1427 | check_infer( |
1441 | r#" | 1428 | r#" |
1442 | trait Trait { | 1429 | trait Trait { |
1443 | type Type; | 1430 | type Type; |
1444 | } | 1431 | } |
1445 | 1432 | ||
1446 | fn get<T: Trait>(t: T) -> <T as Trait>::Type {} | 1433 | fn get<T: Trait>(t: T) -> <T as Trait>::Type {} |
1447 | fn get2<U, T: Trait<Type = U>>(t: T) -> U {} | 1434 | fn get2<U, T: Trait<Type = U>>(t: T) -> U {} |
1448 | fn set<T: Trait<Type = u64>>(t: T) -> T {t} | 1435 | fn set<T: Trait<Type = u64>>(t: T) -> T {t} |
1449 | 1436 | ||
1450 | struct S<T>; | 1437 | struct S<T>; |
1451 | impl<T> Trait for S<T> { type Type = T; } | 1438 | impl<T> Trait for S<T> { type Type = T; } |
1452 | 1439 | ||
1453 | fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) { | 1440 | fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) { |
1454 | get(x); | 1441 | get(x); |
1455 | get2(x); | 1442 | get2(x); |
1456 | get(y); | 1443 | get(y); |
1457 | get2(y); | 1444 | get2(y); |
1458 | get(set(S)); | 1445 | get(set(S)); |
1459 | get2(set(S)); | 1446 | get2(set(S)); |
1460 | get2(S::<str>); | 1447 | get2(S::<str>); |
1461 | } | 1448 | }"#, |
1462 | "#, | ||
1463 | expect![[r#" | 1449 | expect![[r#" |
1464 | 49..50 't': T | 1450 | 49..50 't': T |
1465 | 77..79 '{}': () | 1451 | 77..79 '{}': () |
@@ -1546,18 +1532,17 @@ mod iter { | |||
1546 | fn projection_eq_within_chalk() { | 1532 | fn projection_eq_within_chalk() { |
1547 | check_infer( | 1533 | check_infer( |
1548 | r#" | 1534 | r#" |
1549 | trait Trait1 { | 1535 | trait Trait1 { |
1550 | type Type; | 1536 | type Type; |
1551 | } | 1537 | } |
1552 | trait Trait2<T> { | 1538 | trait Trait2<T> { |
1553 | fn foo(self) -> T; | 1539 | fn foo(self) -> T; |
1554 | } | 1540 | } |
1555 | impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {} | 1541 | impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {} |
1556 | 1542 | ||
1557 | fn test<T: Trait1<Type = u32>>(x: T) { | 1543 | fn test<T: Trait1<Type = u32>>(x: T) { |
1558 | x.foo(); | 1544 | x.foo(); |
1559 | } | 1545 | }"#, |
1560 | "#, | ||
1561 | expect![[r#" | 1546 | expect![[r#" |
1562 | 61..65 'self': Self | 1547 | 61..65 'self': Self |
1563 | 163..164 'x': T | 1548 | 163..164 'x': T |
@@ -1589,19 +1574,18 @@ fn test<T: foo::Trait>(x: T) { | |||
1589 | fn super_trait_method_resolution() { | 1574 | fn super_trait_method_resolution() { |
1590 | check_infer( | 1575 | check_infer( |
1591 | r#" | 1576 | r#" |
1592 | mod foo { | 1577 | mod foo { |
1593 | trait SuperTrait { | 1578 | trait SuperTrait { |
1594 | fn foo(&self) -> u32 {} | 1579 | fn foo(&self) -> u32 {} |
1595 | } | 1580 | } |
1596 | } | 1581 | } |
1597 | trait Trait1: foo::SuperTrait {} | 1582 | trait Trait1: foo::SuperTrait {} |
1598 | trait Trait2 where Self: foo::SuperTrait {} | 1583 | trait Trait2 where Self: foo::SuperTrait {} |
1599 | 1584 | ||
1600 | fn test<T: Trait1, U: Trait2>(x: T, y: U) { | 1585 | fn test<T: Trait1, U: Trait2>(x: T, y: U) { |
1601 | x.foo(); | 1586 | x.foo(); |
1602 | y.foo(); | 1587 | y.foo(); |
1603 | } | 1588 | }"#, |
1604 | "#, | ||
1605 | expect![[r#" | 1589 | expect![[r#" |
1606 | 49..53 'self': &Self | 1590 | 49..53 'self': &Self |
1607 | 62..64 '{}': () | 1591 | 62..64 '{}': () |
@@ -1620,17 +1604,16 @@ fn super_trait_method_resolution() { | |||
1620 | fn super_trait_impl_trait_method_resolution() { | 1604 | fn super_trait_impl_trait_method_resolution() { |
1621 | check_infer( | 1605 | check_infer( |
1622 | r#" | 1606 | r#" |
1623 | mod foo { | 1607 | mod foo { |
1624 | trait SuperTrait { | 1608 | trait SuperTrait { |
1625 | fn foo(&self) -> u32 {} | 1609 | fn foo(&self) -> u32 {} |
1626 | } | 1610 | } |
1627 | } | 1611 | } |
1628 | trait Trait1: foo::SuperTrait {} | 1612 | trait Trait1: foo::SuperTrait {} |
1629 | 1613 | ||
1630 | fn test(x: &impl Trait1) { | 1614 | fn test(x: &impl Trait1) { |
1631 | x.foo(); | 1615 | x.foo(); |
1632 | } | 1616 | }"#, |
1633 | "#, | ||
1634 | expect![[r#" | 1617 | expect![[r#" |
1635 | 49..53 'self': &Self | 1618 | 49..53 'self': &Self |
1636 | 62..64 '{}': () | 1619 | 62..64 '{}': () |
@@ -1667,20 +1650,19 @@ fn super_trait_cycle() { | |||
1667 | fn super_trait_assoc_type_bounds() { | 1650 | fn super_trait_assoc_type_bounds() { |
1668 | check_infer( | 1651 | check_infer( |
1669 | r#" | 1652 | r#" |
1670 | trait SuperTrait { type Type; } | 1653 | trait SuperTrait { type Type; } |
1671 | trait Trait where Self: SuperTrait {} | 1654 | trait Trait where Self: SuperTrait {} |
1672 | 1655 | ||
1673 | fn get2<U, T: Trait<Type = U>>(t: T) -> U {} | 1656 | fn get2<U, T: Trait<Type = U>>(t: T) -> U {} |
1674 | fn set<T: Trait<Type = u64>>(t: T) -> T {t} | 1657 | fn set<T: Trait<Type = u64>>(t: T) -> T {t} |
1675 | 1658 | ||
1676 | struct S<T>; | 1659 | struct S<T>; |
1677 | impl<T> SuperTrait for S<T> { type Type = T; } | 1660 | impl<T> SuperTrait for S<T> { type Type = T; } |
1678 | impl<T> Trait for S<T> {} | 1661 | impl<T> Trait for S<T> {} |
1679 | 1662 | ||
1680 | fn test() { | 1663 | fn test() { |
1681 | get2(set(S)); | 1664 | get2(set(S)); |
1682 | } | 1665 | }"#, |
1683 | "#, | ||
1684 | expect![[r#" | 1666 | expect![[r#" |
1685 | 102..103 't': T | 1667 | 102..103 't': T |
1686 | 113..115 '{}': () | 1668 | 113..115 '{}': () |
@@ -1701,16 +1683,15 @@ fn super_trait_assoc_type_bounds() { | |||
1701 | fn fn_trait() { | 1683 | fn fn_trait() { |
1702 | check_infer_with_mismatches( | 1684 | check_infer_with_mismatches( |
1703 | r#" | 1685 | r#" |
1704 | trait FnOnce<Args> { | 1686 | trait FnOnce<Args> { |
1705 | type Output; | 1687 | type Output; |
1706 | 1688 | ||
1707 | fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output; | 1689 | fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output; |
1708 | } | 1690 | } |
1709 | 1691 | ||
1710 | fn test<F: FnOnce(u32, u64) -> u128>(f: F) { | 1692 | fn test<F: FnOnce(u32, u64) -> u128>(f: F) { |
1711 | f.call_once((1, 2)); | 1693 | f.call_once((1, 2)); |
1712 | } | 1694 | }"#, |
1713 | "#, | ||
1714 | expect![[r#" | 1695 | expect![[r#" |
1715 | 56..60 'self': Self | 1696 | 56..60 'self': Self |
1716 | 62..66 'args': Args | 1697 | 62..66 'args': Args |
@@ -1729,37 +1710,36 @@ fn fn_trait() { | |||
1729 | fn fn_ptr_and_item() { | 1710 | fn fn_ptr_and_item() { |
1730 | check_infer_with_mismatches( | 1711 | check_infer_with_mismatches( |
1731 | r#" | 1712 | r#" |
1732 | #[lang="fn_once"] | 1713 | #[lang="fn_once"] |
1733 | trait FnOnce<Args> { | 1714 | trait FnOnce<Args> { |
1734 | type Output; | 1715 | type Output; |
1735 | 1716 | ||
1736 | fn call_once(self, args: Args) -> Self::Output; | 1717 | fn call_once(self, args: Args) -> Self::Output; |
1737 | } | 1718 | } |
1738 | 1719 | ||
1739 | trait Foo<T> { | 1720 | trait Foo<T> { |
1740 | fn foo(&self) -> T; | 1721 | fn foo(&self) -> T; |
1741 | } | 1722 | } |
1742 | 1723 | ||
1743 | struct Bar<T>(T); | 1724 | struct Bar<T>(T); |
1744 | 1725 | ||
1745 | impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> { | 1726 | impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> { |
1746 | fn foo(&self) -> (A1, R) { loop {} } | 1727 | fn foo(&self) -> (A1, R) { loop {} } |
1747 | } | 1728 | } |
1748 | 1729 | ||
1749 | enum Opt<T> { None, Some(T) } | 1730 | enum Opt<T> { None, Some(T) } |
1750 | impl<T> Opt<T> { | 1731 | impl<T> Opt<T> { |
1751 | fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} } | 1732 | fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} } |
1752 | } | 1733 | } |
1753 | 1734 | ||
1754 | fn test() { | 1735 | fn test() { |
1755 | let bar: Bar<fn(u8) -> u32>; | 1736 | let bar: Bar<fn(u8) -> u32>; |
1756 | bar.foo(); | 1737 | bar.foo(); |
1757 | 1738 | ||
1758 | let opt: Opt<u8>; | 1739 | let opt: Opt<u8>; |
1759 | let f: fn(u8) -> u32; | 1740 | let f: fn(u8) -> u32; |
1760 | opt.map(f); | 1741 | opt.map(f); |
1761 | } | 1742 | }"#, |
1762 | "#, | ||
1763 | expect![[r#" | 1743 | expect![[r#" |
1764 | 74..78 'self': Self | 1744 | 74..78 'self': Self |
1765 | 80..84 'args': Args | 1745 | 80..84 'args': Args |
@@ -1790,46 +1770,45 @@ fn fn_ptr_and_item() { | |||
1790 | fn fn_trait_deref_with_ty_default() { | 1770 | fn fn_trait_deref_with_ty_default() { |
1791 | check_infer( | 1771 | check_infer( |
1792 | r#" | 1772 | r#" |
1793 | #[lang = "deref"] | 1773 | #[lang = "deref"] |
1794 | trait Deref { | 1774 | trait Deref { |
1795 | type Target; | 1775 | type Target; |
1796 | 1776 | ||
1797 | fn deref(&self) -> &Self::Target; | 1777 | fn deref(&self) -> &Self::Target; |
1798 | } | 1778 | } |
1799 | 1779 | ||
1800 | #[lang="fn_once"] | 1780 | #[lang="fn_once"] |
1801 | trait FnOnce<Args> { | 1781 | trait FnOnce<Args> { |
1802 | type Output; | 1782 | type Output; |
1803 | 1783 | ||
1804 | fn call_once(self, args: Args) -> Self::Output; | 1784 | fn call_once(self, args: Args) -> Self::Output; |
1805 | } | 1785 | } |
1806 | 1786 | ||
1807 | struct Foo; | 1787 | struct Foo; |
1808 | 1788 | ||
1809 | impl Foo { | 1789 | impl Foo { |
1810 | fn foo(&self) -> usize {} | 1790 | fn foo(&self) -> usize {} |
1811 | } | 1791 | } |
1812 | 1792 | ||
1813 | struct Lazy<T, F = fn() -> T>(F); | 1793 | struct Lazy<T, F = fn() -> T>(F); |
1814 | 1794 | ||
1815 | impl<T, F> Lazy<T, F> { | 1795 | impl<T, F> Lazy<T, F> { |
1816 | pub fn new(f: F) -> Lazy<T, F> {} | 1796 | pub fn new(f: F) -> Lazy<T, F> {} |
1817 | } | 1797 | } |
1818 | 1798 | ||
1819 | impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { | 1799 | impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { |
1820 | type Target = T; | 1800 | type Target = T; |
1821 | } | 1801 | } |
1822 | 1802 | ||
1823 | fn test() { | 1803 | fn test() { |
1824 | let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo); | 1804 | let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo); |
1825 | let r1 = lazy1.foo(); | 1805 | let r1 = lazy1.foo(); |
1826 | 1806 | ||
1827 | fn make_foo_fn() -> Foo {} | 1807 | fn make_foo_fn() -> Foo {} |
1828 | let make_foo_fn_ptr: fn() -> Foo = make_foo_fn; | 1808 | let make_foo_fn_ptr: fn() -> Foo = make_foo_fn; |
1829 | let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr); | 1809 | let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr); |
1830 | let r2 = lazy2.foo(); | 1810 | let r2 = lazy2.foo(); |
1831 | } | 1811 | }"#, |
1832 | "#, | ||
1833 | expect![[r#" | 1812 | expect![[r#" |
1834 | 64..68 'self': &Self | 1813 | 64..68 'self': &Self |
1835 | 165..169 'self': Self | 1814 | 165..169 'self': Self |
@@ -1865,23 +1844,22 @@ fn fn_trait_deref_with_ty_default() { | |||
1865 | fn closure_1() { | 1844 | fn closure_1() { |
1866 | check_infer_with_mismatches( | 1845 | check_infer_with_mismatches( |
1867 | r#" | 1846 | r#" |
1868 | #[lang = "fn_once"] | 1847 | #[lang = "fn_once"] |
1869 | trait FnOnce<Args> { | 1848 | trait FnOnce<Args> { |
1870 | type Output; | 1849 | type Output; |
1871 | } | 1850 | } |
1872 | 1851 | ||
1873 | enum Option<T> { Some(T), None } | 1852 | enum Option<T> { Some(T), None } |
1874 | impl<T> Option<T> { | 1853 | impl<T> Option<T> { |
1875 | fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} } | 1854 | fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} } |
1876 | } | 1855 | } |
1877 | 1856 | ||
1878 | fn test() { | 1857 | fn test() { |
1879 | let x = Option::Some(1u32); | 1858 | let x = Option::Some(1u32); |
1880 | x.map(|v| v + 1); | 1859 | x.map(|v| v + 1); |
1881 | x.map(|_v| 1u64); | 1860 | x.map(|_v| 1u64); |
1882 | let y: Option<i64> = x.map(|_v| 1); | 1861 | let y: Option<i64> = x.map(|_v| 1); |
1883 | } | 1862 | }"#, |
1884 | "#, | ||
1885 | expect![[r#" | 1863 | expect![[r#" |
1886 | 147..151 'self': Option<T> | 1864 | 147..151 'self': Option<T> |
1887 | 153..154 'f': F | 1865 | 153..154 'f': F |
@@ -1919,38 +1897,63 @@ fn closure_1() { | |||
1919 | fn closure_2() { | 1897 | fn closure_2() { |
1920 | check_infer_with_mismatches( | 1898 | check_infer_with_mismatches( |
1921 | r#" | 1899 | r#" |
1922 | trait FnOnce<Args> { | 1900 | #[lang = "add"] |
1923 | type Output; | 1901 | pub trait Add<Rhs = Self> { |
1924 | } | 1902 | type Output; |
1903 | fn add(self, rhs: Rhs) -> Self::Output; | ||
1904 | } | ||
1925 | 1905 | ||
1926 | fn test<F: FnOnce(u32) -> u64>(f: F) { | 1906 | trait FnOnce<Args> { |
1927 | f(1); | 1907 | type Output; |
1928 | let g = |v| v + 1; | 1908 | } |
1929 | g(1u64); | 1909 | |
1930 | let h = |v| 1u128 + v; | 1910 | impl Add for u64 { |
1931 | } | 1911 | type Output = Self; |
1932 | "#, | 1912 | fn add(self, rhs: u64) -> Self::Output {0} |
1913 | } | ||
1914 | |||
1915 | impl Add for u128 { | ||
1916 | type Output = Self; | ||
1917 | fn add(self, rhs: u128) -> Self::Output {0} | ||
1918 | } | ||
1919 | |||
1920 | fn test<F: FnOnce(u32) -> u64>(f: F) { | ||
1921 | f(1); | ||
1922 | let g = |v| v + 1; | ||
1923 | g(1u64); | ||
1924 | let h = |v| 1u128 + v; | ||
1925 | }"#, | ||
1933 | expect![[r#" | 1926 | expect![[r#" |
1934 | 72..73 'f': F | 1927 | 72..76 'self': Self |
1935 | 78..154 '{ ...+ v; }': () | 1928 | 78..81 'rhs': Rhs |
1936 | 84..85 'f': F | 1929 | 203..207 'self': u64 |
1937 | 84..88 'f(1)': {unknown} | 1930 | 209..212 'rhs': u64 |
1938 | 86..87 '1': i32 | 1931 | 235..238 '{0}': u64 |
1939 | 98..99 'g': |u64| -> i32 | 1932 | 236..237 '0': u64 |
1940 | 102..111 '|v| v + 1': |u64| -> i32 | 1933 | 297..301 'self': u128 |
1941 | 103..104 'v': u64 | 1934 | 303..306 'rhs': u128 |
1942 | 106..107 'v': u64 | 1935 | 330..333 '{0}': u128 |
1943 | 106..111 'v + 1': i32 | 1936 | 331..332 '0': u128 |
1944 | 110..111 '1': i32 | 1937 | 368..369 'f': F |
1945 | 117..118 'g': |u64| -> i32 | 1938 | 374..450 '{ ...+ v; }': () |
1946 | 117..124 'g(1u64)': i32 | 1939 | 380..381 'f': F |
1947 | 119..123 '1u64': u64 | 1940 | 380..384 'f(1)': {unknown} |
1948 | 134..135 'h': |u128| -> u128 | 1941 | 382..383 '1': i32 |
1949 | 138..151 '|v| 1u128 + v': |u128| -> u128 | 1942 | 394..395 'g': |u64| -> u64 |
1950 | 139..140 'v': u128 | 1943 | 398..407 '|v| v + 1': |u64| -> u64 |
1951 | 142..147 '1u128': u128 | 1944 | 399..400 'v': u64 |
1952 | 142..151 '1u128 + v': u128 | 1945 | 402..403 'v': u64 |
1953 | 150..151 'v': u128 | 1946 | 402..407 'v + 1': u64 |
1947 | 406..407 '1': u64 | ||
1948 | 413..414 'g': |u64| -> u64 | ||
1949 | 413..420 'g(1u64)': u64 | ||
1950 | 415..419 '1u64': u64 | ||
1951 | 430..431 'h': |u128| -> u128 | ||
1952 | 434..447 '|v| 1u128 + v': |u128| -> u128 | ||
1953 | 435..436 'v': u128 | ||
1954 | 438..443 '1u128': u128 | ||
1955 | 438..447 '1u128 + v': u128 | ||
1956 | 446..447 'v': u128 | ||
1954 | "#]], | 1957 | "#]], |
1955 | ); | 1958 | ); |
1956 | } | 1959 | } |
@@ -1959,29 +1962,28 @@ fn closure_2() { | |||
1959 | fn closure_as_argument_inference_order() { | 1962 | fn closure_as_argument_inference_order() { |
1960 | check_infer_with_mismatches( | 1963 | check_infer_with_mismatches( |
1961 | r#" | 1964 | r#" |
1962 | #[lang = "fn_once"] | 1965 | #[lang = "fn_once"] |
1963 | trait FnOnce<Args> { | 1966 | trait FnOnce<Args> { |
1964 | type Output; | 1967 | type Output; |
1965 | } | 1968 | } |
1966 | 1969 | ||
1967 | fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} } | 1970 | fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} } |
1968 | fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} } | 1971 | fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} } |
1969 | 1972 | ||
1970 | struct S; | 1973 | struct S; |
1971 | impl S { | 1974 | impl S { |
1972 | fn method(self) -> u64; | 1975 | fn method(self) -> u64; |
1973 | 1976 | ||
1974 | fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} } | 1977 | fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} } |
1975 | fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} } | 1978 | fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} } |
1976 | } | 1979 | } |
1977 | 1980 | ||
1978 | fn test() { | 1981 | fn test() { |
1979 | let x1 = foo1(S, |s| s.method()); | 1982 | let x1 = foo1(S, |s| s.method()); |
1980 | let x2 = foo2(|s| s.method(), S); | 1983 | let x2 = foo2(|s| s.method(), S); |
1981 | let x3 = S.foo1(S, |s| s.method()); | 1984 | let x3 = S.foo1(S, |s| s.method()); |
1982 | let x4 = S.foo2(|s| s.method(), S); | 1985 | let x4 = S.foo2(|s| s.method(), S); |
1983 | } | 1986 | }"#, |
1984 | "#, | ||
1985 | expect![[r#" | 1987 | expect![[r#" |
1986 | 94..95 'x': T | 1988 | 94..95 'x': T |
1987 | 100..101 'f': F | 1989 | 100..101 'f': F |
@@ -2110,27 +2112,26 @@ fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { | |||
2110 | fn unselected_projection_on_impl_self() { | 2112 | fn unselected_projection_on_impl_self() { |
2111 | check_infer( | 2113 | check_infer( |
2112 | r#" | 2114 | r#" |
2113 | //- /main.rs | 2115 | //- /main.rs |
2114 | trait Trait { | 2116 | trait Trait { |
2115 | type Item; | 2117 | type Item; |
2116 | 2118 | ||
2117 | fn f(&self, x: Self::Item); | 2119 | fn f(&self, x: Self::Item); |
2118 | } | 2120 | } |
2119 | 2121 | ||
2120 | struct S; | 2122 | struct S; |
2121 | 2123 | ||
2122 | impl Trait for S { | 2124 | impl Trait for S { |
2123 | type Item = u32; | 2125 | type Item = u32; |
2124 | fn f(&self, x: Self::Item) { let y = x; } | 2126 | fn f(&self, x: Self::Item) { let y = x; } |
2125 | } | 2127 | } |
2126 | 2128 | ||
2127 | struct S2; | 2129 | struct S2; |
2128 | 2130 | ||
2129 | impl Trait for S2 { | 2131 | impl Trait for S2 { |
2130 | type Item = i32; | 2132 | type Item = i32; |
2131 | fn f(&self, x: <Self>::Item) { let y = x; } | 2133 | fn f(&self, x: <Self>::Item) { let y = x; } |
2132 | } | 2134 | }"#, |
2133 | "#, | ||
2134 | expect![[r#" | 2135 | expect![[r#" |
2135 | 40..44 'self': &Self | 2136 | 40..44 'self': &Self |
2136 | 46..47 'x': Trait::Item<Self> | 2137 | 46..47 'x': Trait::Item<Self> |
@@ -2366,58 +2367,57 @@ fn test<I: Iterator<Item: Iterator<Item = u32>>>() { | |||
2366 | fn proc_macro_server_types() { | 2367 | fn proc_macro_server_types() { |
2367 | check_infer( | 2368 | check_infer( |
2368 | r#" | 2369 | r#" |
2369 | macro_rules! with_api { | 2370 | macro_rules! with_api { |
2370 | ($S:ident, $self:ident, $m:ident) => { | 2371 | ($S:ident, $self:ident, $m:ident) => { |
2371 | $m! { | 2372 | $m! { |
2372 | TokenStream { | 2373 | TokenStream { |
2373 | fn new() -> $S::TokenStream; | 2374 | fn new() -> $S::TokenStream; |
2374 | }, | 2375 | }, |
2375 | Group { | 2376 | Group { |
2376 | }, | 2377 | }, |
2377 | } | ||
2378 | }; | ||
2379 | } | 2378 | } |
2380 | macro_rules! associated_item { | 2379 | }; |
2381 | (type TokenStream) => | 2380 | } |
2382 | (type TokenStream: 'static;); | 2381 | macro_rules! associated_item { |
2383 | (type Group) => | 2382 | (type TokenStream) => |
2384 | (type Group: 'static;); | 2383 | (type TokenStream: 'static;); |
2385 | ($($item:tt)*) => ($($item)*;) | 2384 | (type Group) => |
2386 | } | 2385 | (type Group: 'static;); |
2387 | macro_rules! declare_server_traits { | 2386 | ($($item:tt)*) => ($($item)*;) |
2388 | ($($name:ident { | 2387 | } |
2389 | $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)* | 2388 | macro_rules! declare_server_traits { |
2390 | }),* $(,)?) => { | 2389 | ($($name:ident { |
2391 | pub trait Types { | 2390 | $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)* |
2392 | $(associated_item!(type $name);)* | 2391 | }),* $(,)?) => { |
2393 | } | 2392 | pub trait Types { |
2394 | 2393 | $(associated_item!(type $name);)* | |
2395 | $(pub trait $name: Types { | ||
2396 | $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)* | ||
2397 | })* | ||
2398 | |||
2399 | pub trait Server: Types $(+ $name)* {} | ||
2400 | impl<S: Types $(+ $name)*> Server for S {} | ||
2401 | } | ||
2402 | } | 2394 | } |
2403 | 2395 | ||
2404 | with_api!(Self, self_, declare_server_traits); | 2396 | $(pub trait $name: Types { |
2405 | struct G {} | 2397 | $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)* |
2406 | struct T {} | 2398 | })* |
2407 | struct Rustc; | ||
2408 | impl Types for Rustc { | ||
2409 | type TokenStream = T; | ||
2410 | type Group = G; | ||
2411 | } | ||
2412 | 2399 | ||
2413 | fn make<T>() -> T { loop {} } | 2400 | pub trait Server: Types $(+ $name)* {} |
2414 | impl TokenStream for Rustc { | 2401 | impl<S: Types $(+ $name)*> Server for S {} |
2415 | fn new() -> Self::TokenStream { | 2402 | } |
2416 | let group: Self::Group = make(); | 2403 | } |
2417 | make() | 2404 | |
2418 | } | 2405 | with_api!(Self, self_, declare_server_traits); |
2419 | } | 2406 | struct G {} |
2420 | "#, | 2407 | struct T {} |
2408 | struct Rustc; | ||
2409 | impl Types for Rustc { | ||
2410 | type TokenStream = T; | ||
2411 | type Group = G; | ||
2412 | } | ||
2413 | |||
2414 | fn make<T>() -> T { loop {} } | ||
2415 | impl TokenStream for Rustc { | ||
2416 | fn new() -> Self::TokenStream { | ||
2417 | let group: Self::Group = make(); | ||
2418 | make() | ||
2419 | } | ||
2420 | }"#, | ||
2421 | expect![[r#" | 2421 | expect![[r#" |
2422 | 1061..1072 '{ loop {} }': T | 2422 | 1061..1072 '{ loop {} }': T |
2423 | 1063..1070 'loop {}': ! | 2423 | 1063..1070 'loop {}': ! |
@@ -2436,23 +2436,22 @@ fn proc_macro_server_types() { | |||
2436 | fn unify_impl_trait() { | 2436 | fn unify_impl_trait() { |
2437 | check_infer_with_mismatches( | 2437 | check_infer_with_mismatches( |
2438 | r#" | 2438 | r#" |
2439 | trait Trait<T> {} | 2439 | trait Trait<T> {} |
2440 | 2440 | ||
2441 | fn foo(x: impl Trait<u32>) { loop {} } | 2441 | fn foo(x: impl Trait<u32>) { loop {} } |
2442 | fn bar<T>(x: impl Trait<T>) -> T { loop {} } | 2442 | fn bar<T>(x: impl Trait<T>) -> T { loop {} } |
2443 | 2443 | ||
2444 | struct S<T>(T); | 2444 | struct S<T>(T); |
2445 | impl<T> Trait<T> for S<T> {} | 2445 | impl<T> Trait<T> for S<T> {} |
2446 | 2446 | ||
2447 | fn default<T>() -> T { loop {} } | 2447 | fn default<T>() -> T { loop {} } |
2448 | 2448 | ||
2449 | fn test() -> impl Trait<i32> { | 2449 | fn test() -> impl Trait<i32> { |
2450 | let s1 = S(default()); | 2450 | let s1 = S(default()); |
2451 | foo(s1); | 2451 | foo(s1); |
2452 | let x: i32 = bar(S(default())); | 2452 | let x: i32 = bar(S(default())); |
2453 | S(default()) | 2453 | S(default()) |
2454 | } | 2454 | }"#, |
2455 | "#, | ||
2456 | expect![[r#" | 2455 | expect![[r#" |
2457 | 26..27 'x': impl Trait<u32> | 2456 | 26..27 'x': impl Trait<u32> |
2458 | 46..57 '{ loop {} }': () | 2457 | 46..57 '{ loop {} }': () |
@@ -2493,30 +2492,29 @@ fn unify_impl_trait() { | |||
2493 | fn assoc_types_from_bounds() { | 2492 | fn assoc_types_from_bounds() { |
2494 | check_infer( | 2493 | check_infer( |
2495 | r#" | 2494 | r#" |
2496 | //- /main.rs | 2495 | //- /main.rs |
2497 | #[lang = "fn_once"] | 2496 | #[lang = "fn_once"] |
2498 | trait FnOnce<Args> { | 2497 | trait FnOnce<Args> { |
2499 | type Output; | 2498 | type Output; |
2500 | } | 2499 | } |
2501 | 2500 | ||
2502 | trait T { | 2501 | trait T { |
2503 | type O; | 2502 | type O; |
2504 | } | 2503 | } |
2505 | 2504 | ||
2506 | impl T for () { | 2505 | impl T for () { |
2507 | type O = (); | 2506 | type O = (); |
2508 | } | 2507 | } |
2509 | 2508 | ||
2510 | fn f<X, F>(_v: F) | 2509 | fn f<X, F>(_v: F) |
2511 | where | 2510 | where |
2512 | X: T, | 2511 | X: T, |
2513 | F: FnOnce(&X::O), | 2512 | F: FnOnce(&X::O), |
2514 | { } | 2513 | { } |
2515 | 2514 | ||
2516 | fn main() { | 2515 | fn main() { |
2517 | f::<(), _>(|z| { z; }); | 2516 | f::<(), _>(|z| { z; }); |
2518 | } | 2517 | }"#, |
2519 | "#, | ||
2520 | expect![[r#" | 2518 | expect![[r#" |
2521 | 133..135 '_v': F | 2519 | 133..135 '_v': F |
2522 | 178..181 '{ }': () | 2520 | 178..181 '{ }': () |
@@ -2602,76 +2600,75 @@ fn test() { | |||
2602 | fn iterator_chain() { | 2600 | fn iterator_chain() { |
2603 | check_infer_with_mismatches( | 2601 | check_infer_with_mismatches( |
2604 | r#" | 2602 | r#" |
2605 | //- /main.rs | 2603 | //- /main.rs |
2606 | #[lang = "fn_once"] | 2604 | #[lang = "fn_once"] |
2607 | trait FnOnce<Args> { | 2605 | trait FnOnce<Args> { |
2608 | type Output; | 2606 | type Output; |
2609 | } | 2607 | } |
2610 | #[lang = "fn_mut"] | 2608 | #[lang = "fn_mut"] |
2611 | trait FnMut<Args>: FnOnce<Args> { } | 2609 | trait FnMut<Args>: FnOnce<Args> { } |
2612 | 2610 | ||
2613 | enum Option<T> { Some(T), None } | 2611 | enum Option<T> { Some(T), None } |
2614 | use Option::*; | 2612 | use Option::*; |
2615 | 2613 | ||
2616 | pub trait Iterator { | 2614 | pub trait Iterator { |
2617 | type Item; | 2615 | type Item; |
2618 | 2616 | ||
2619 | fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> | 2617 | fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> |
2620 | where | 2618 | where |
2621 | F: FnMut(Self::Item) -> Option<B>, | 2619 | F: FnMut(Self::Item) -> Option<B>, |
2622 | { loop {} } | 2620 | { loop {} } |
2623 | 2621 | ||
2624 | fn for_each<F>(self, f: F) | 2622 | fn for_each<F>(self, f: F) |
2625 | where | 2623 | where |
2626 | F: FnMut(Self::Item), | 2624 | F: FnMut(Self::Item), |
2627 | { loop {} } | 2625 | { loop {} } |
2628 | } | 2626 | } |
2629 | 2627 | ||
2630 | pub trait IntoIterator { | 2628 | pub trait IntoIterator { |
2631 | type Item; | 2629 | type Item; |
2632 | type IntoIter: Iterator<Item = Self::Item>; | 2630 | type IntoIter: Iterator<Item = Self::Item>; |
2633 | fn into_iter(self) -> Self::IntoIter; | 2631 | fn into_iter(self) -> Self::IntoIter; |
2634 | } | 2632 | } |
2635 | 2633 | ||
2636 | pub struct FilterMap<I, F> { } | 2634 | pub struct FilterMap<I, F> { } |
2637 | impl<B, I: Iterator, F> Iterator for FilterMap<I, F> | 2635 | impl<B, I: Iterator, F> Iterator for FilterMap<I, F> |
2638 | where | 2636 | where |
2639 | F: FnMut(I::Item) -> Option<B>, | 2637 | F: FnMut(I::Item) -> Option<B>, |
2640 | { | 2638 | { |
2641 | type Item = B; | 2639 | type Item = B; |
2642 | } | 2640 | } |
2643 | 2641 | ||
2644 | #[stable(feature = "rust1", since = "1.0.0")] | 2642 | #[stable(feature = "rust1", since = "1.0.0")] |
2645 | impl<I: Iterator> IntoIterator for I { | 2643 | impl<I: Iterator> IntoIterator for I { |
2646 | type Item = I::Item; | 2644 | type Item = I::Item; |
2647 | type IntoIter = I; | 2645 | type IntoIter = I; |
2648 | 2646 | ||
2649 | fn into_iter(self) -> I { | 2647 | fn into_iter(self) -> I { |
2650 | self | 2648 | self |
2651 | } | 2649 | } |
2652 | } | 2650 | } |
2653 | 2651 | ||
2654 | struct Vec<T> {} | 2652 | struct Vec<T> {} |
2655 | impl<T> Vec<T> { | 2653 | impl<T> Vec<T> { |
2656 | fn new() -> Self { loop {} } | 2654 | fn new() -> Self { loop {} } |
2657 | } | 2655 | } |
2658 | 2656 | ||
2659 | impl<T> IntoIterator for Vec<T> { | 2657 | impl<T> IntoIterator for Vec<T> { |
2660 | type Item = T; | 2658 | type Item = T; |
2661 | type IntoIter = IntoIter<T>; | 2659 | type IntoIter = IntoIter<T>; |
2662 | } | 2660 | } |
2663 | 2661 | ||
2664 | pub struct IntoIter<T> { } | 2662 | pub struct IntoIter<T> { } |
2665 | impl<T> Iterator for IntoIter<T> { | 2663 | impl<T> Iterator for IntoIter<T> { |
2666 | type Item = T; | 2664 | type Item = T; |
2667 | } | 2665 | } |
2668 | 2666 | ||
2669 | fn main() { | 2667 | fn main() { |
2670 | Vec::<i32>::new().into_iter() | 2668 | Vec::<i32>::new().into_iter() |
2671 | .filter_map(|x| if x > 0 { Some(x as u32) } else { None }) | 2669 | .filter_map(|x| if x > 0 { Some(x as u32) } else { None }) |
2672 | .for_each(|y| { y; }); | 2670 | .for_each(|y| { y; }); |
2673 | } | 2671 | }"#, |
2674 | "#, | ||
2675 | expect![[r#" | 2672 | expect![[r#" |
2676 | 226..230 'self': Self | 2673 | 226..230 'self': Self |
2677 | 232..233 'f': F | 2674 | 232..233 'f': F |
@@ -2753,14 +2750,13 @@ fn main() { | |||
2753 | fn trait_object_no_coercion() { | 2750 | fn trait_object_no_coercion() { |
2754 | check_infer_with_mismatches( | 2751 | check_infer_with_mismatches( |
2755 | r#" | 2752 | r#" |
2756 | trait Foo {} | 2753 | trait Foo {} |
2757 | 2754 | ||
2758 | fn foo(x: &dyn Foo) {} | 2755 | fn foo(x: &dyn Foo) {} |
2759 | 2756 | ||
2760 | fn test(x: &dyn Foo) { | 2757 | fn test(x: &dyn Foo) { |
2761 | foo(x); | 2758 | foo(x); |
2762 | } | 2759 | }"#, |
2763 | "#, | ||
2764 | expect![[r#" | 2760 | expect![[r#" |
2765 | 21..22 'x': &dyn Foo | 2761 | 21..22 'x': &dyn Foo |
2766 | 34..36 '{}': () | 2762 | 34..36 '{}': () |
@@ -2777,23 +2773,22 @@ fn trait_object_no_coercion() { | |||
2777 | fn builtin_copy() { | 2773 | fn builtin_copy() { |
2778 | check_infer_with_mismatches( | 2774 | check_infer_with_mismatches( |
2779 | r#" | 2775 | r#" |
2780 | #[lang = "copy"] | 2776 | #[lang = "copy"] |
2781 | trait Copy {} | 2777 | trait Copy {} |
2782 | 2778 | ||
2783 | struct IsCopy; | 2779 | struct IsCopy; |
2784 | impl Copy for IsCopy {} | 2780 | impl Copy for IsCopy {} |
2785 | struct NotCopy; | 2781 | struct NotCopy; |
2786 | 2782 | ||
2787 | trait Test { fn test(&self) -> bool; } | 2783 | trait Test { fn test(&self) -> bool; } |
2788 | impl<T: Copy> Test for T {} | 2784 | impl<T: Copy> Test for T {} |
2789 | 2785 | ||
2790 | fn test() { | 2786 | fn test() { |
2791 | IsCopy.test(); | 2787 | IsCopy.test(); |
2792 | NotCopy.test(); | 2788 | NotCopy.test(); |
2793 | (IsCopy, IsCopy).test(); | 2789 | (IsCopy, IsCopy).test(); |
2794 | (IsCopy, NotCopy).test(); | 2790 | (IsCopy, NotCopy).test(); |
2795 | } | 2791 | }"#, |
2796 | "#, | ||
2797 | expect![[r#" | 2792 | expect![[r#" |
2798 | 110..114 'self': &Self | 2793 | 110..114 'self': &Self |
2799 | 166..267 '{ ...t(); }': () | 2794 | 166..267 '{ ...t(); }': () |
@@ -2817,24 +2812,23 @@ fn builtin_copy() { | |||
2817 | fn builtin_fn_def_copy() { | 2812 | fn builtin_fn_def_copy() { |
2818 | check_infer_with_mismatches( | 2813 | check_infer_with_mismatches( |
2819 | r#" | 2814 | r#" |
2820 | #[lang = "copy"] | 2815 | #[lang = "copy"] |
2821 | trait Copy {} | 2816 | trait Copy {} |
2822 | 2817 | ||
2823 | fn foo() {} | 2818 | fn foo() {} |
2824 | fn bar<T: Copy>(T) -> T {} | 2819 | fn bar<T: Copy>(T) -> T {} |
2825 | struct Struct(usize); | 2820 | struct Struct(usize); |
2826 | enum Enum { Variant(usize) } | 2821 | enum Enum { Variant(usize) } |
2827 | 2822 | ||
2828 | trait Test { fn test(&self) -> bool; } | 2823 | trait Test { fn test(&self) -> bool; } |
2829 | impl<T: Copy> Test for T {} | 2824 | impl<T: Copy> Test for T {} |
2830 | 2825 | ||
2831 | fn test() { | 2826 | fn test() { |
2832 | foo.test(); | 2827 | foo.test(); |
2833 | bar.test(); | 2828 | bar.test(); |
2834 | Struct.test(); | 2829 | Struct.test(); |
2835 | Enum::Variant.test(); | 2830 | Enum::Variant.test(); |
2836 | } | 2831 | }"#, |
2837 | "#, | ||
2838 | expect![[r#" | 2832 | expect![[r#" |
2839 | 41..43 '{}': () | 2833 | 41..43 '{}': () |
2840 | 60..61 'T': {unknown} | 2834 | 60..61 'T': {unknown} |
@@ -2858,18 +2852,17 @@ fn builtin_fn_def_copy() { | |||
2858 | fn builtin_fn_ptr_copy() { | 2852 | fn builtin_fn_ptr_copy() { |
2859 | check_infer_with_mismatches( | 2853 | check_infer_with_mismatches( |
2860 | r#" | 2854 | r#" |
2861 | #[lang = "copy"] | 2855 | #[lang = "copy"] |
2862 | trait Copy {} | 2856 | trait Copy {} |
2863 | 2857 | ||
2864 | trait Test { fn test(&self) -> bool; } | 2858 | trait Test { fn test(&self) -> bool; } |
2865 | impl<T: Copy> Test for T {} | 2859 | impl<T: Copy> Test for T {} |
2866 | 2860 | ||
2867 | fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) { | 2861 | fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) { |
2868 | f1.test(); | 2862 | f1.test(); |
2869 | f2.test(); | 2863 | f2.test(); |
2870 | f3.test(); | 2864 | f3.test(); |
2871 | } | 2865 | }"#, |
2872 | "#, | ||
2873 | expect![[r#" | 2866 | expect![[r#" |
2874 | 54..58 'self': &Self | 2867 | 54..58 'self': &Self |
2875 | 108..110 'f1': fn() | 2868 | 108..110 'f1': fn() |
@@ -2890,19 +2883,18 @@ fn builtin_fn_ptr_copy() { | |||
2890 | fn builtin_sized() { | 2883 | fn builtin_sized() { |
2891 | check_infer_with_mismatches( | 2884 | check_infer_with_mismatches( |
2892 | r#" | 2885 | r#" |
2893 | #[lang = "sized"] | 2886 | #[lang = "sized"] |
2894 | trait Sized {} | 2887 | trait Sized {} |
2895 | 2888 | ||
2896 | trait Test { fn test(&self) -> bool; } | 2889 | trait Test { fn test(&self) -> bool; } |
2897 | impl<T: Sized> Test for T {} | 2890 | impl<T: Sized> Test for T {} |
2898 | 2891 | ||
2899 | fn test() { | 2892 | fn test() { |
2900 | 1u8.test(); | 2893 | 1u8.test(); |
2901 | (*"foo").test(); // not Sized | 2894 | (*"foo").test(); // not Sized |
2902 | (1u8, 1u8).test(); | 2895 | (1u8, 1u8).test(); |
2903 | (1u8, *"foo").test(); // not Sized | 2896 | (1u8, *"foo").test(); // not Sized |
2904 | } | 2897 | }"#, |
2905 | "#, | ||
2906 | expect![[r#" | 2898 | expect![[r#" |
2907 | 56..60 'self': &Self | 2899 | 56..60 'self': &Self |
2908 | 113..228 '{ ...ized }': () | 2900 | 113..228 '{ ...ized }': () |
@@ -2972,19 +2964,18 @@ impl<A: Step> iter::Iterator for ops::Range<A> { | |||
2972 | fn infer_closure_arg() { | 2964 | fn infer_closure_arg() { |
2973 | check_infer( | 2965 | check_infer( |
2974 | r#" | 2966 | r#" |
2975 | //- /lib.rs | 2967 | //- /lib.rs |
2976 | 2968 | ||
2977 | enum Option<T> { | 2969 | enum Option<T> { |
2978 | None, | 2970 | None, |
2979 | Some(T) | 2971 | Some(T) |
2980 | } | 2972 | } |
2981 | 2973 | ||
2982 | fn foo() { | 2974 | fn foo() { |
2983 | let s = Option::None; | 2975 | let s = Option::None; |
2984 | let f = |x: Option<i32>| {}; | 2976 | let f = |x: Option<i32>| {}; |
2985 | (&f)(s) | 2977 | (&f)(s) |
2986 | } | 2978 | }"#, |
2987 | "#, | ||
2988 | expect![[r#" | 2979 | expect![[r#" |
2989 | 52..126 '{ ...)(s) }': () | 2980 | 52..126 '{ ...)(s) }': () |
2990 | 62..63 's': Option<i32> | 2981 | 62..63 's': Option<i32> |
@@ -3053,46 +3044,45 @@ fn infer_box_fn_arg() { | |||
3053 | // The type mismatch is a bug | 3044 | // The type mismatch is a bug |
3054 | check_infer_with_mismatches( | 3045 | check_infer_with_mismatches( |
3055 | r#" | 3046 | r#" |
3056 | //- /lib.rs deps:std | 3047 | //- /lib.rs deps:std |
3057 | 3048 | ||
3058 | #[lang = "fn_once"] | 3049 | #[lang = "fn_once"] |
3059 | pub trait FnOnce<Args> { | 3050 | pub trait FnOnce<Args> { |
3060 | type Output; | 3051 | type Output; |
3061 | 3052 | ||
3062 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | 3053 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; |
3063 | } | 3054 | } |
3064 | 3055 | ||
3065 | #[lang = "deref"] | 3056 | #[lang = "deref"] |
3066 | pub trait Deref { | 3057 | pub trait Deref { |
3067 | type Target: ?Sized; | 3058 | type Target: ?Sized; |
3068 | 3059 | ||
3069 | fn deref(&self) -> &Self::Target; | 3060 | fn deref(&self) -> &Self::Target; |
3070 | } | 3061 | } |
3071 | 3062 | ||
3072 | #[lang = "owned_box"] | 3063 | #[lang = "owned_box"] |
3073 | pub struct Box<T: ?Sized> { | 3064 | pub struct Box<T: ?Sized> { |
3074 | inner: *mut T, | 3065 | inner: *mut T, |
3075 | } | 3066 | } |
3076 | 3067 | ||
3077 | impl<T: ?Sized> Deref for Box<T> { | 3068 | impl<T: ?Sized> Deref for Box<T> { |
3078 | type Target = T; | 3069 | type Target = T; |
3079 | 3070 | ||
3080 | fn deref(&self) -> &T { | 3071 | fn deref(&self) -> &T { |
3081 | &self.inner | 3072 | &self.inner |
3082 | } | 3073 | } |
3083 | } | 3074 | } |
3084 | 3075 | ||
3085 | enum Option<T> { | 3076 | enum Option<T> { |
3086 | None, | 3077 | None, |
3087 | Some(T) | 3078 | Some(T) |
3088 | } | 3079 | } |
3089 | 3080 | ||
3090 | fn foo() { | 3081 | fn foo() { |
3091 | let s = Option::None; | 3082 | let s = Option::None; |
3092 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); | 3083 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); |
3093 | f(&s); | 3084 | f(&s); |
3094 | } | 3085 | }"#, |
3095 | "#, | ||
3096 | expect![[r#" | 3086 | expect![[r#" |
3097 | 100..104 'self': Self | 3087 | 100..104 'self': Self |
3098 | 106..110 'args': Args | 3088 | 106..110 'args': Args |
@@ -3258,8 +3248,7 @@ fn f() { | |||
3258 | ().method(); | 3248 | ().method(); |
3259 | //^^^^^^^^^^^ u8 | 3249 | //^^^^^^^^^^^ u8 |
3260 | } | 3250 | } |
3261 | } | 3251 | }"#, |
3262 | "#, | ||
3263 | expect![[r#" | 3252 | expect![[r#" |
3264 | 46..50 'self': &Self | 3253 | 46..50 'self': &Self |
3265 | 58..63 '{ 0 }': u8 | 3254 | 58..63 '{ 0 }': u8 |
@@ -3313,8 +3302,7 @@ fn f() { | |||
3313 | fn inner() -> S { | 3302 | fn inner() -> S { |
3314 | let s = inner(); | 3303 | let s = inner(); |
3315 | } | 3304 | } |
3316 | } | 3305 | }"#, |
3317 | "#, | ||
3318 | expect![[r#" | 3306 | expect![[r#" |
3319 | 17..73 '{ ... } }': () | 3307 | 17..73 '{ ... } }': () |
3320 | 39..71 '{ ... }': () | 3308 | 39..71 '{ ... }': () |
@@ -3349,8 +3337,7 @@ fn test() { | |||
3349 | let x = A; | 3337 | let x = A; |
3350 | let y = A; | 3338 | let y = A; |
3351 | let r = x.do_op(y); | 3339 | let r = x.do_op(y); |
3352 | } | 3340 | }"#, |
3353 | "#, | ||
3354 | expect![[r#" | 3341 | expect![[r#" |
3355 | 63..67 'self': Self | 3342 | 63..67 'self': Self |
3356 | 69..72 'rhs': RHS | 3343 | 69..72 'rhs': RHS |
@@ -3399,9 +3386,7 @@ impl foo::Bar for F { | |||
3399 | fn foo() { | 3386 | fn foo() { |
3400 | use foo::Bar; | 3387 | use foo::Bar; |
3401 | let x = <F as Bar>::boo(); | 3388 | let x = <F as Bar>::boo(); |
3402 | } | 3389 | }"#, |
3403 | |||
3404 | "#, | ||
3405 | expect![[r#" | 3390 | expect![[r#" |
3406 | 132..163 '{ ... }': Bar::Output<Self> | 3391 | 132..163 '{ ... }': Bar::Output<Self> |
3407 | 146..153 'loop {}': ! | 3392 | 146..153 'loop {}': ! |
@@ -3413,3 +3398,79 @@ fn foo() { | |||
3413 | "#]], | 3398 | "#]], |
3414 | ); | 3399 | ); |
3415 | } | 3400 | } |
3401 | |||
3402 | #[test] | ||
3403 | fn renamed_extern_crate_in_block() { | ||
3404 | check_types( | ||
3405 | r#" | ||
3406 | //- /lib.rs crate:lib deps:serde | ||
3407 | use serde::Deserialize; | ||
3408 | |||
3409 | struct Foo {} | ||
3410 | |||
3411 | const _ : () = { | ||
3412 | extern crate serde as _serde; | ||
3413 | impl _serde::Deserialize for Foo { | ||
3414 | fn deserialize() -> u8 { 0 } | ||
3415 | } | ||
3416 | }; | ||
3417 | |||
3418 | fn foo() { | ||
3419 | Foo::deserialize(); | ||
3420 | //^^^^^^^^^^^^^^^^^^ u8 | ||
3421 | } | ||
3422 | |||
3423 | //- /serde.rs crate:serde | ||
3424 | |||
3425 | pub trait Deserialize { | ||
3426 | fn deserialize() -> u8; | ||
3427 | }"#, | ||
3428 | ); | ||
3429 | } | ||
3430 | |||
3431 | #[test] | ||
3432 | fn bin_op_adt_with_rhs_primitive() { | ||
3433 | check_infer_with_mismatches( | ||
3434 | r#" | ||
3435 | #[lang = "add"] | ||
3436 | pub trait Add<Rhs = Self> { | ||
3437 | type Output; | ||
3438 | fn add(self, rhs: Rhs) -> Self::Output; | ||
3439 | } | ||
3440 | |||
3441 | struct Wrapper(u32); | ||
3442 | impl Add<u32> for Wrapper { | ||
3443 | type Output = Self; | ||
3444 | fn add(self, rhs: u32) -> Wrapper { | ||
3445 | Wrapper(rhs) | ||
3446 | } | ||
3447 | } | ||
3448 | fn main(){ | ||
3449 | let wrapped = Wrapper(10); | ||
3450 | let num: u32 = 2; | ||
3451 | let res = wrapped + num; | ||
3452 | |||
3453 | }"#, | ||
3454 | expect![[r#" | ||
3455 | 72..76 'self': Self | ||
3456 | 78..81 'rhs': Rhs | ||
3457 | 192..196 'self': Wrapper | ||
3458 | 198..201 'rhs': u32 | ||
3459 | 219..247 '{ ... }': Wrapper | ||
3460 | 229..236 'Wrapper': Wrapper(u32) -> Wrapper | ||
3461 | 229..241 'Wrapper(rhs)': Wrapper | ||
3462 | 237..240 'rhs': u32 | ||
3463 | 259..345 '{ ...um; }': () | ||
3464 | 269..276 'wrapped': Wrapper | ||
3465 | 279..286 'Wrapper': Wrapper(u32) -> Wrapper | ||
3466 | 279..290 'Wrapper(10)': Wrapper | ||
3467 | 287..289 '10': u32 | ||
3468 | 300..303 'num': u32 | ||
3469 | 311..312 '2': u32 | ||
3470 | 322..325 'res': Wrapper | ||
3471 | 328..335 'wrapped': Wrapper | ||
3472 | 328..341 'wrapped + num': Wrapper | ||
3473 | 338..341 'num': u32 | ||
3474 | "#]], | ||
3475 | ) | ||
3476 | } | ||