diff options
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 1354 |
1 files changed, 656 insertions, 698 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 1879dbc78..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,33 +1897,32 @@ 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 | #[lang = "add"] | 1900 | #[lang = "add"] |
1923 | pub trait Add<Rhs = Self> { | 1901 | pub trait Add<Rhs = Self> { |
1924 | type Output; | 1902 | type Output; |
1925 | fn add(self, rhs: Rhs) -> Self::Output; | 1903 | fn add(self, rhs: Rhs) -> Self::Output; |
1926 | } | 1904 | } |
1927 | 1905 | ||
1928 | trait FnOnce<Args> { | 1906 | trait FnOnce<Args> { |
1929 | type Output; | 1907 | type Output; |
1930 | } | 1908 | } |
1931 | 1909 | ||
1932 | impl Add for u64 { | 1910 | impl Add for u64 { |
1933 | type Output = Self; | 1911 | type Output = Self; |
1934 | fn add(self, rhs: u64) -> Self::Output {0} | 1912 | fn add(self, rhs: u64) -> Self::Output {0} |
1935 | } | 1913 | } |
1936 | 1914 | ||
1937 | impl Add for u128 { | 1915 | impl Add for u128 { |
1938 | type Output = Self; | 1916 | type Output = Self; |
1939 | fn add(self, rhs: u128) -> Self::Output {0} | 1917 | fn add(self, rhs: u128) -> Self::Output {0} |
1940 | } | 1918 | } |
1941 | 1919 | ||
1942 | fn test<F: FnOnce(u32) -> u64>(f: F) { | 1920 | fn test<F: FnOnce(u32) -> u64>(f: F) { |
1943 | f(1); | 1921 | f(1); |
1944 | let g = |v| v + 1; | 1922 | let g = |v| v + 1; |
1945 | g(1u64); | 1923 | g(1u64); |
1946 | let h = |v| 1u128 + v; | 1924 | let h = |v| 1u128 + v; |
1947 | } | 1925 | }"#, |
1948 | "#, | ||
1949 | expect![[r#" | 1926 | expect![[r#" |
1950 | 72..76 'self': Self | 1927 | 72..76 'self': Self |
1951 | 78..81 'rhs': Rhs | 1928 | 78..81 'rhs': Rhs |
@@ -1985,29 +1962,28 @@ fn closure_2() { | |||
1985 | fn closure_as_argument_inference_order() { | 1962 | fn closure_as_argument_inference_order() { |
1986 | check_infer_with_mismatches( | 1963 | check_infer_with_mismatches( |
1987 | r#" | 1964 | r#" |
1988 | #[lang = "fn_once"] | 1965 | #[lang = "fn_once"] |
1989 | trait FnOnce<Args> { | 1966 | trait FnOnce<Args> { |
1990 | type Output; | 1967 | type Output; |
1991 | } | 1968 | } |
1992 | 1969 | ||
1993 | 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 {} } |
1994 | 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 {} } |
1995 | 1972 | ||
1996 | struct S; | 1973 | struct S; |
1997 | impl S { | 1974 | impl S { |
1998 | fn method(self) -> u64; | 1975 | fn method(self) -> u64; |
1999 | 1976 | ||
2000 | 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 {} } |
2001 | 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 {} } |
2002 | } | 1979 | } |
2003 | 1980 | ||
2004 | fn test() { | 1981 | fn test() { |
2005 | let x1 = foo1(S, |s| s.method()); | 1982 | let x1 = foo1(S, |s| s.method()); |
2006 | let x2 = foo2(|s| s.method(), S); | 1983 | let x2 = foo2(|s| s.method(), S); |
2007 | let x3 = S.foo1(S, |s| s.method()); | 1984 | let x3 = S.foo1(S, |s| s.method()); |
2008 | let x4 = S.foo2(|s| s.method(), S); | 1985 | let x4 = S.foo2(|s| s.method(), S); |
2009 | } | 1986 | }"#, |
2010 | "#, | ||
2011 | expect![[r#" | 1987 | expect![[r#" |
2012 | 94..95 'x': T | 1988 | 94..95 'x': T |
2013 | 100..101 'f': F | 1989 | 100..101 'f': F |
@@ -2136,27 +2112,26 @@ fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { | |||
2136 | fn unselected_projection_on_impl_self() { | 2112 | fn unselected_projection_on_impl_self() { |
2137 | check_infer( | 2113 | check_infer( |
2138 | r#" | 2114 | r#" |
2139 | //- /main.rs | 2115 | //- /main.rs |
2140 | trait Trait { | 2116 | trait Trait { |
2141 | type Item; | 2117 | type Item; |
2142 | 2118 | ||
2143 | fn f(&self, x: Self::Item); | 2119 | fn f(&self, x: Self::Item); |
2144 | } | 2120 | } |
2145 | 2121 | ||
2146 | struct S; | 2122 | struct S; |
2147 | 2123 | ||
2148 | impl Trait for S { | 2124 | impl Trait for S { |
2149 | type Item = u32; | 2125 | type Item = u32; |
2150 | fn f(&self, x: Self::Item) { let y = x; } | 2126 | fn f(&self, x: Self::Item) { let y = x; } |
2151 | } | 2127 | } |
2152 | 2128 | ||
2153 | struct S2; | 2129 | struct S2; |
2154 | 2130 | ||
2155 | impl Trait for S2 { | 2131 | impl Trait for S2 { |
2156 | type Item = i32; | 2132 | type Item = i32; |
2157 | fn f(&self, x: <Self>::Item) { let y = x; } | 2133 | fn f(&self, x: <Self>::Item) { let y = x; } |
2158 | } | 2134 | }"#, |
2159 | "#, | ||
2160 | expect![[r#" | 2135 | expect![[r#" |
2161 | 40..44 'self': &Self | 2136 | 40..44 'self': &Self |
2162 | 46..47 'x': Trait::Item<Self> | 2137 | 46..47 'x': Trait::Item<Self> |
@@ -2392,58 +2367,57 @@ fn test<I: Iterator<Item: Iterator<Item = u32>>>() { | |||
2392 | fn proc_macro_server_types() { | 2367 | fn proc_macro_server_types() { |
2393 | check_infer( | 2368 | check_infer( |
2394 | r#" | 2369 | r#" |
2395 | macro_rules! with_api { | 2370 | macro_rules! with_api { |
2396 | ($S:ident, $self:ident, $m:ident) => { | 2371 | ($S:ident, $self:ident, $m:ident) => { |
2397 | $m! { | 2372 | $m! { |
2398 | TokenStream { | 2373 | TokenStream { |
2399 | fn new() -> $S::TokenStream; | 2374 | fn new() -> $S::TokenStream; |
2400 | }, | 2375 | }, |
2401 | Group { | 2376 | Group { |
2402 | }, | 2377 | }, |
2403 | } | ||
2404 | }; | ||
2405 | } | ||
2406 | macro_rules! associated_item { | ||
2407 | (type TokenStream) => | ||
2408 | (type TokenStream: 'static;); | ||
2409 | (type Group) => | ||
2410 | (type Group: 'static;); | ||
2411 | ($($item:tt)*) => ($($item)*;) | ||
2412 | } | 2378 | } |
2413 | macro_rules! declare_server_traits { | 2379 | }; |
2414 | ($($name:ident { | 2380 | } |
2415 | $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)* | 2381 | macro_rules! associated_item { |
2416 | }),* $(,)?) => { | 2382 | (type TokenStream) => |
2417 | pub trait Types { | 2383 | (type TokenStream: 'static;); |
2418 | $(associated_item!(type $name);)* | 2384 | (type Group) => |
2419 | } | 2385 | (type Group: 'static;); |
2420 | 2386 | ($($item:tt)*) => ($($item)*;) | |
2421 | $(pub trait $name: Types { | 2387 | } |
2422 | $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)* | 2388 | macro_rules! declare_server_traits { |
2423 | })* | 2389 | ($($name:ident { |
2424 | 2390 | $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)* | |
2425 | pub trait Server: Types $(+ $name)* {} | 2391 | }),* $(,)?) => { |
2426 | impl<S: Types $(+ $name)*> Server for S {} | 2392 | pub trait Types { |
2427 | } | 2393 | $(associated_item!(type $name);)* |
2428 | } | 2394 | } |
2429 | 2395 | ||
2430 | with_api!(Self, self_, declare_server_traits); | 2396 | $(pub trait $name: Types { |
2431 | struct G {} | 2397 | $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)* |
2432 | struct T {} | 2398 | })* |
2433 | struct Rustc; | ||
2434 | impl Types for Rustc { | ||
2435 | type TokenStream = T; | ||
2436 | type Group = G; | ||
2437 | } | ||
2438 | 2399 | ||
2439 | fn make<T>() -> T { loop {} } | 2400 | pub trait Server: Types $(+ $name)* {} |
2440 | impl TokenStream for Rustc { | 2401 | impl<S: Types $(+ $name)*> Server for S {} |
2441 | fn new() -> Self::TokenStream { | 2402 | } |
2442 | let group: Self::Group = make(); | 2403 | } |
2443 | make() | 2404 | |
2444 | } | 2405 | with_api!(Self, self_, declare_server_traits); |
2445 | } | 2406 | struct G {} |
2446 | "#, | 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 | }"#, | ||
2447 | expect![[r#" | 2421 | expect![[r#" |
2448 | 1061..1072 '{ loop {} }': T | 2422 | 1061..1072 '{ loop {} }': T |
2449 | 1063..1070 'loop {}': ! | 2423 | 1063..1070 'loop {}': ! |
@@ -2462,23 +2436,22 @@ fn proc_macro_server_types() { | |||
2462 | fn unify_impl_trait() { | 2436 | fn unify_impl_trait() { |
2463 | check_infer_with_mismatches( | 2437 | check_infer_with_mismatches( |
2464 | r#" | 2438 | r#" |
2465 | trait Trait<T> {} | 2439 | trait Trait<T> {} |
2466 | 2440 | ||
2467 | fn foo(x: impl Trait<u32>) { loop {} } | 2441 | fn foo(x: impl Trait<u32>) { loop {} } |
2468 | fn bar<T>(x: impl Trait<T>) -> T { loop {} } | 2442 | fn bar<T>(x: impl Trait<T>) -> T { loop {} } |
2469 | 2443 | ||
2470 | struct S<T>(T); | 2444 | struct S<T>(T); |
2471 | impl<T> Trait<T> for S<T> {} | 2445 | impl<T> Trait<T> for S<T> {} |
2472 | 2446 | ||
2473 | fn default<T>() -> T { loop {} } | 2447 | fn default<T>() -> T { loop {} } |
2474 | 2448 | ||
2475 | fn test() -> impl Trait<i32> { | 2449 | fn test() -> impl Trait<i32> { |
2476 | let s1 = S(default()); | 2450 | let s1 = S(default()); |
2477 | foo(s1); | 2451 | foo(s1); |
2478 | let x: i32 = bar(S(default())); | 2452 | let x: i32 = bar(S(default())); |
2479 | S(default()) | 2453 | S(default()) |
2480 | } | 2454 | }"#, |
2481 | "#, | ||
2482 | expect![[r#" | 2455 | expect![[r#" |
2483 | 26..27 'x': impl Trait<u32> | 2456 | 26..27 'x': impl Trait<u32> |
2484 | 46..57 '{ loop {} }': () | 2457 | 46..57 '{ loop {} }': () |
@@ -2519,30 +2492,29 @@ fn unify_impl_trait() { | |||
2519 | fn assoc_types_from_bounds() { | 2492 | fn assoc_types_from_bounds() { |
2520 | check_infer( | 2493 | check_infer( |
2521 | r#" | 2494 | r#" |
2522 | //- /main.rs | 2495 | //- /main.rs |
2523 | #[lang = "fn_once"] | 2496 | #[lang = "fn_once"] |
2524 | trait FnOnce<Args> { | 2497 | trait FnOnce<Args> { |
2525 | type Output; | 2498 | type Output; |
2526 | } | 2499 | } |
2527 | 2500 | ||
2528 | trait T { | 2501 | trait T { |
2529 | type O; | 2502 | type O; |
2530 | } | 2503 | } |
2531 | 2504 | ||
2532 | impl T for () { | 2505 | impl T for () { |
2533 | type O = (); | 2506 | type O = (); |
2534 | } | 2507 | } |
2535 | 2508 | ||
2536 | fn f<X, F>(_v: F) | 2509 | fn f<X, F>(_v: F) |
2537 | where | 2510 | where |
2538 | X: T, | 2511 | X: T, |
2539 | F: FnOnce(&X::O), | 2512 | F: FnOnce(&X::O), |
2540 | { } | 2513 | { } |
2541 | 2514 | ||
2542 | fn main() { | 2515 | fn main() { |
2543 | f::<(), _>(|z| { z; }); | 2516 | f::<(), _>(|z| { z; }); |
2544 | } | 2517 | }"#, |
2545 | "#, | ||
2546 | expect![[r#" | 2518 | expect![[r#" |
2547 | 133..135 '_v': F | 2519 | 133..135 '_v': F |
2548 | 178..181 '{ }': () | 2520 | 178..181 '{ }': () |
@@ -2628,76 +2600,75 @@ fn test() { | |||
2628 | fn iterator_chain() { | 2600 | fn iterator_chain() { |
2629 | check_infer_with_mismatches( | 2601 | check_infer_with_mismatches( |
2630 | r#" | 2602 | r#" |
2631 | //- /main.rs | 2603 | //- /main.rs |
2632 | #[lang = "fn_once"] | 2604 | #[lang = "fn_once"] |
2633 | trait FnOnce<Args> { | 2605 | trait FnOnce<Args> { |
2634 | type Output; | 2606 | type Output; |
2635 | } | 2607 | } |
2636 | #[lang = "fn_mut"] | 2608 | #[lang = "fn_mut"] |
2637 | trait FnMut<Args>: FnOnce<Args> { } | 2609 | trait FnMut<Args>: FnOnce<Args> { } |
2638 | 2610 | ||
2639 | enum Option<T> { Some(T), None } | 2611 | enum Option<T> { Some(T), None } |
2640 | use Option::*; | 2612 | use Option::*; |
2641 | 2613 | ||
2642 | pub trait Iterator { | 2614 | pub trait Iterator { |
2643 | type Item; | 2615 | type Item; |
2644 | 2616 | ||
2645 | fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> | 2617 | fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> |
2646 | where | 2618 | where |
2647 | F: FnMut(Self::Item) -> Option<B>, | 2619 | F: FnMut(Self::Item) -> Option<B>, |
2648 | { loop {} } | 2620 | { loop {} } |
2649 | 2621 | ||
2650 | fn for_each<F>(self, f: F) | 2622 | fn for_each<F>(self, f: F) |
2651 | where | 2623 | where |
2652 | F: FnMut(Self::Item), | 2624 | F: FnMut(Self::Item), |
2653 | { loop {} } | 2625 | { loop {} } |
2654 | } | 2626 | } |
2655 | 2627 | ||
2656 | pub trait IntoIterator { | 2628 | pub trait IntoIterator { |
2657 | type Item; | 2629 | type Item; |
2658 | type IntoIter: Iterator<Item = Self::Item>; | 2630 | type IntoIter: Iterator<Item = Self::Item>; |
2659 | fn into_iter(self) -> Self::IntoIter; | 2631 | fn into_iter(self) -> Self::IntoIter; |
2660 | } | 2632 | } |
2661 | 2633 | ||
2662 | pub struct FilterMap<I, F> { } | 2634 | pub struct FilterMap<I, F> { } |
2663 | impl<B, I: Iterator, F> Iterator for FilterMap<I, F> | 2635 | impl<B, I: Iterator, F> Iterator for FilterMap<I, F> |
2664 | where | 2636 | where |
2665 | F: FnMut(I::Item) -> Option<B>, | 2637 | F: FnMut(I::Item) -> Option<B>, |
2666 | { | 2638 | { |
2667 | type Item = B; | 2639 | type Item = B; |
2668 | } | 2640 | } |
2669 | 2641 | ||
2670 | #[stable(feature = "rust1", since = "1.0.0")] | 2642 | #[stable(feature = "rust1", since = "1.0.0")] |
2671 | impl<I: Iterator> IntoIterator for I { | 2643 | impl<I: Iterator> IntoIterator for I { |
2672 | type Item = I::Item; | 2644 | type Item = I::Item; |
2673 | type IntoIter = I; | 2645 | type IntoIter = I; |
2674 | 2646 | ||
2675 | fn into_iter(self) -> I { | 2647 | fn into_iter(self) -> I { |
2676 | self | 2648 | self |
2677 | } | 2649 | } |
2678 | } | 2650 | } |
2679 | 2651 | ||
2680 | struct Vec<T> {} | 2652 | struct Vec<T> {} |
2681 | impl<T> Vec<T> { | 2653 | impl<T> Vec<T> { |
2682 | fn new() -> Self { loop {} } | 2654 | fn new() -> Self { loop {} } |
2683 | } | 2655 | } |
2684 | 2656 | ||
2685 | impl<T> IntoIterator for Vec<T> { | 2657 | impl<T> IntoIterator for Vec<T> { |
2686 | type Item = T; | 2658 | type Item = T; |
2687 | type IntoIter = IntoIter<T>; | 2659 | type IntoIter = IntoIter<T>; |
2688 | } | 2660 | } |
2689 | 2661 | ||
2690 | pub struct IntoIter<T> { } | 2662 | pub struct IntoIter<T> { } |
2691 | impl<T> Iterator for IntoIter<T> { | 2663 | impl<T> Iterator for IntoIter<T> { |
2692 | type Item = T; | 2664 | type Item = T; |
2693 | } | 2665 | } |
2694 | 2666 | ||
2695 | fn main() { | 2667 | fn main() { |
2696 | Vec::<i32>::new().into_iter() | 2668 | Vec::<i32>::new().into_iter() |
2697 | .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 }) |
2698 | .for_each(|y| { y; }); | 2670 | .for_each(|y| { y; }); |
2699 | } | 2671 | }"#, |
2700 | "#, | ||
2701 | expect![[r#" | 2672 | expect![[r#" |
2702 | 226..230 'self': Self | 2673 | 226..230 'self': Self |
2703 | 232..233 'f': F | 2674 | 232..233 'f': F |
@@ -2779,14 +2750,13 @@ fn main() { | |||
2779 | fn trait_object_no_coercion() { | 2750 | fn trait_object_no_coercion() { |
2780 | check_infer_with_mismatches( | 2751 | check_infer_with_mismatches( |
2781 | r#" | 2752 | r#" |
2782 | trait Foo {} | 2753 | trait Foo {} |
2783 | 2754 | ||
2784 | fn foo(x: &dyn Foo) {} | 2755 | fn foo(x: &dyn Foo) {} |
2785 | 2756 | ||
2786 | fn test(x: &dyn Foo) { | 2757 | fn test(x: &dyn Foo) { |
2787 | foo(x); | 2758 | foo(x); |
2788 | } | 2759 | }"#, |
2789 | "#, | ||
2790 | expect![[r#" | 2760 | expect![[r#" |
2791 | 21..22 'x': &dyn Foo | 2761 | 21..22 'x': &dyn Foo |
2792 | 34..36 '{}': () | 2762 | 34..36 '{}': () |
@@ -2803,23 +2773,22 @@ fn trait_object_no_coercion() { | |||
2803 | fn builtin_copy() { | 2773 | fn builtin_copy() { |
2804 | check_infer_with_mismatches( | 2774 | check_infer_with_mismatches( |
2805 | r#" | 2775 | r#" |
2806 | #[lang = "copy"] | 2776 | #[lang = "copy"] |
2807 | trait Copy {} | 2777 | trait Copy {} |
2808 | 2778 | ||
2809 | struct IsCopy; | 2779 | struct IsCopy; |
2810 | impl Copy for IsCopy {} | 2780 | impl Copy for IsCopy {} |
2811 | struct NotCopy; | 2781 | struct NotCopy; |
2812 | 2782 | ||
2813 | trait Test { fn test(&self) -> bool; } | 2783 | trait Test { fn test(&self) -> bool; } |
2814 | impl<T: Copy> Test for T {} | 2784 | impl<T: Copy> Test for T {} |
2815 | 2785 | ||
2816 | fn test() { | 2786 | fn test() { |
2817 | IsCopy.test(); | 2787 | IsCopy.test(); |
2818 | NotCopy.test(); | 2788 | NotCopy.test(); |
2819 | (IsCopy, IsCopy).test(); | 2789 | (IsCopy, IsCopy).test(); |
2820 | (IsCopy, NotCopy).test(); | 2790 | (IsCopy, NotCopy).test(); |
2821 | } | 2791 | }"#, |
2822 | "#, | ||
2823 | expect![[r#" | 2792 | expect![[r#" |
2824 | 110..114 'self': &Self | 2793 | 110..114 'self': &Self |
2825 | 166..267 '{ ...t(); }': () | 2794 | 166..267 '{ ...t(); }': () |
@@ -2843,24 +2812,23 @@ fn builtin_copy() { | |||
2843 | fn builtin_fn_def_copy() { | 2812 | fn builtin_fn_def_copy() { |
2844 | check_infer_with_mismatches( | 2813 | check_infer_with_mismatches( |
2845 | r#" | 2814 | r#" |
2846 | #[lang = "copy"] | 2815 | #[lang = "copy"] |
2847 | trait Copy {} | 2816 | trait Copy {} |
2848 | 2817 | ||
2849 | fn foo() {} | 2818 | fn foo() {} |
2850 | fn bar<T: Copy>(T) -> T {} | 2819 | fn bar<T: Copy>(T) -> T {} |
2851 | struct Struct(usize); | 2820 | struct Struct(usize); |
2852 | enum Enum { Variant(usize) } | 2821 | enum Enum { Variant(usize) } |
2853 | 2822 | ||
2854 | trait Test { fn test(&self) -> bool; } | 2823 | trait Test { fn test(&self) -> bool; } |
2855 | impl<T: Copy> Test for T {} | 2824 | impl<T: Copy> Test for T {} |
2856 | 2825 | ||
2857 | fn test() { | 2826 | fn test() { |
2858 | foo.test(); | 2827 | foo.test(); |
2859 | bar.test(); | 2828 | bar.test(); |
2860 | Struct.test(); | 2829 | Struct.test(); |
2861 | Enum::Variant.test(); | 2830 | Enum::Variant.test(); |
2862 | } | 2831 | }"#, |
2863 | "#, | ||
2864 | expect![[r#" | 2832 | expect![[r#" |
2865 | 41..43 '{}': () | 2833 | 41..43 '{}': () |
2866 | 60..61 'T': {unknown} | 2834 | 60..61 'T': {unknown} |
@@ -2884,18 +2852,17 @@ fn builtin_fn_def_copy() { | |||
2884 | fn builtin_fn_ptr_copy() { | 2852 | fn builtin_fn_ptr_copy() { |
2885 | check_infer_with_mismatches( | 2853 | check_infer_with_mismatches( |
2886 | r#" | 2854 | r#" |
2887 | #[lang = "copy"] | 2855 | #[lang = "copy"] |
2888 | trait Copy {} | 2856 | trait Copy {} |
2889 | 2857 | ||
2890 | trait Test { fn test(&self) -> bool; } | 2858 | trait Test { fn test(&self) -> bool; } |
2891 | impl<T: Copy> Test for T {} | 2859 | impl<T: Copy> Test for T {} |
2892 | 2860 | ||
2893 | 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) { |
2894 | f1.test(); | 2862 | f1.test(); |
2895 | f2.test(); | 2863 | f2.test(); |
2896 | f3.test(); | 2864 | f3.test(); |
2897 | } | 2865 | }"#, |
2898 | "#, | ||
2899 | expect![[r#" | 2866 | expect![[r#" |
2900 | 54..58 'self': &Self | 2867 | 54..58 'self': &Self |
2901 | 108..110 'f1': fn() | 2868 | 108..110 'f1': fn() |
@@ -2916,19 +2883,18 @@ fn builtin_fn_ptr_copy() { | |||
2916 | fn builtin_sized() { | 2883 | fn builtin_sized() { |
2917 | check_infer_with_mismatches( | 2884 | check_infer_with_mismatches( |
2918 | r#" | 2885 | r#" |
2919 | #[lang = "sized"] | 2886 | #[lang = "sized"] |
2920 | trait Sized {} | 2887 | trait Sized {} |
2921 | 2888 | ||
2922 | trait Test { fn test(&self) -> bool; } | 2889 | trait Test { fn test(&self) -> bool; } |
2923 | impl<T: Sized> Test for T {} | 2890 | impl<T: Sized> Test for T {} |
2924 | 2891 | ||
2925 | fn test() { | 2892 | fn test() { |
2926 | 1u8.test(); | 2893 | 1u8.test(); |
2927 | (*"foo").test(); // not Sized | 2894 | (*"foo").test(); // not Sized |
2928 | (1u8, 1u8).test(); | 2895 | (1u8, 1u8).test(); |
2929 | (1u8, *"foo").test(); // not Sized | 2896 | (1u8, *"foo").test(); // not Sized |
2930 | } | 2897 | }"#, |
2931 | "#, | ||
2932 | expect![[r#" | 2898 | expect![[r#" |
2933 | 56..60 'self': &Self | 2899 | 56..60 'self': &Self |
2934 | 113..228 '{ ...ized }': () | 2900 | 113..228 '{ ...ized }': () |
@@ -2998,19 +2964,18 @@ impl<A: Step> iter::Iterator for ops::Range<A> { | |||
2998 | fn infer_closure_arg() { | 2964 | fn infer_closure_arg() { |
2999 | check_infer( | 2965 | check_infer( |
3000 | r#" | 2966 | r#" |
3001 | //- /lib.rs | 2967 | //- /lib.rs |
3002 | 2968 | ||
3003 | enum Option<T> { | 2969 | enum Option<T> { |
3004 | None, | 2970 | None, |
3005 | Some(T) | 2971 | Some(T) |
3006 | } | 2972 | } |
3007 | 2973 | ||
3008 | fn foo() { | 2974 | fn foo() { |
3009 | let s = Option::None; | 2975 | let s = Option::None; |
3010 | let f = |x: Option<i32>| {}; | 2976 | let f = |x: Option<i32>| {}; |
3011 | (&f)(s) | 2977 | (&f)(s) |
3012 | } | 2978 | }"#, |
3013 | "#, | ||
3014 | expect![[r#" | 2979 | expect![[r#" |
3015 | 52..126 '{ ...)(s) }': () | 2980 | 52..126 '{ ...)(s) }': () |
3016 | 62..63 's': Option<i32> | 2981 | 62..63 's': Option<i32> |
@@ -3079,46 +3044,45 @@ fn infer_box_fn_arg() { | |||
3079 | // The type mismatch is a bug | 3044 | // The type mismatch is a bug |
3080 | check_infer_with_mismatches( | 3045 | check_infer_with_mismatches( |
3081 | r#" | 3046 | r#" |
3082 | //- /lib.rs deps:std | 3047 | //- /lib.rs deps:std |
3083 | 3048 | ||
3084 | #[lang = "fn_once"] | 3049 | #[lang = "fn_once"] |
3085 | pub trait FnOnce<Args> { | 3050 | pub trait FnOnce<Args> { |
3086 | type Output; | 3051 | type Output; |
3087 | 3052 | ||
3088 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | 3053 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; |
3089 | } | 3054 | } |
3090 | 3055 | ||
3091 | #[lang = "deref"] | 3056 | #[lang = "deref"] |
3092 | pub trait Deref { | 3057 | pub trait Deref { |
3093 | type Target: ?Sized; | 3058 | type Target: ?Sized; |
3094 | 3059 | ||
3095 | fn deref(&self) -> &Self::Target; | 3060 | fn deref(&self) -> &Self::Target; |
3096 | } | 3061 | } |
3097 | 3062 | ||
3098 | #[lang = "owned_box"] | 3063 | #[lang = "owned_box"] |
3099 | pub struct Box<T: ?Sized> { | 3064 | pub struct Box<T: ?Sized> { |
3100 | inner: *mut T, | 3065 | inner: *mut T, |
3101 | } | 3066 | } |
3102 | 3067 | ||
3103 | impl<T: ?Sized> Deref for Box<T> { | 3068 | impl<T: ?Sized> Deref for Box<T> { |
3104 | type Target = T; | 3069 | type Target = T; |
3105 | 3070 | ||
3106 | fn deref(&self) -> &T { | 3071 | fn deref(&self) -> &T { |
3107 | &self.inner | 3072 | &self.inner |
3108 | } | 3073 | } |
3109 | } | 3074 | } |
3110 | 3075 | ||
3111 | enum Option<T> { | 3076 | enum Option<T> { |
3112 | None, | 3077 | None, |
3113 | Some(T) | 3078 | Some(T) |
3114 | } | 3079 | } |
3115 | 3080 | ||
3116 | fn foo() { | 3081 | fn foo() { |
3117 | let s = Option::None; | 3082 | let s = Option::None; |
3118 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); | 3083 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); |
3119 | f(&s); | 3084 | f(&s); |
3120 | } | 3085 | }"#, |
3121 | "#, | ||
3122 | expect![[r#" | 3086 | expect![[r#" |
3123 | 100..104 'self': Self | 3087 | 100..104 'self': Self |
3124 | 106..110 'args': Args | 3088 | 106..110 'args': Args |
@@ -3284,8 +3248,7 @@ fn f() { | |||
3284 | ().method(); | 3248 | ().method(); |
3285 | //^^^^^^^^^^^ u8 | 3249 | //^^^^^^^^^^^ u8 |
3286 | } | 3250 | } |
3287 | } | 3251 | }"#, |
3288 | "#, | ||
3289 | expect![[r#" | 3252 | expect![[r#" |
3290 | 46..50 'self': &Self | 3253 | 46..50 'self': &Self |
3291 | 58..63 '{ 0 }': u8 | 3254 | 58..63 '{ 0 }': u8 |
@@ -3339,8 +3302,7 @@ fn f() { | |||
3339 | fn inner() -> S { | 3302 | fn inner() -> S { |
3340 | let s = inner(); | 3303 | let s = inner(); |
3341 | } | 3304 | } |
3342 | } | 3305 | }"#, |
3343 | "#, | ||
3344 | expect![[r#" | 3306 | expect![[r#" |
3345 | 17..73 '{ ... } }': () | 3307 | 17..73 '{ ... } }': () |
3346 | 39..71 '{ ... }': () | 3308 | 39..71 '{ ... }': () |
@@ -3375,8 +3337,7 @@ fn test() { | |||
3375 | let x = A; | 3337 | let x = A; |
3376 | let y = A; | 3338 | let y = A; |
3377 | let r = x.do_op(y); | 3339 | let r = x.do_op(y); |
3378 | } | 3340 | }"#, |
3379 | "#, | ||
3380 | expect![[r#" | 3341 | expect![[r#" |
3381 | 63..67 'self': Self | 3342 | 63..67 'self': Self |
3382 | 69..72 'rhs': RHS | 3343 | 69..72 'rhs': RHS |
@@ -3425,9 +3386,7 @@ impl foo::Bar for F { | |||
3425 | fn foo() { | 3386 | fn foo() { |
3426 | use foo::Bar; | 3387 | use foo::Bar; |
3427 | let x = <F as Bar>::boo(); | 3388 | let x = <F as Bar>::boo(); |
3428 | } | 3389 | }"#, |
3429 | |||
3430 | "#, | ||
3431 | expect![[r#" | 3390 | expect![[r#" |
3432 | 132..163 '{ ... }': Bar::Output<Self> | 3391 | 132..163 '{ ... }': Bar::Output<Self> |
3433 | 146..153 'loop {}': ! | 3392 | 146..153 'loop {}': ! |
@@ -3465,8 +3424,7 @@ fn foo() { | |||
3465 | 3424 | ||
3466 | pub trait Deserialize { | 3425 | pub trait Deserialize { |
3467 | fn deserialize() -> u8; | 3426 | fn deserialize() -> u8; |
3468 | } | 3427 | }"#, |
3469 | "#, | ||
3470 | ); | 3428 | ); |
3471 | } | 3429 | } |
3472 | 3430 | ||