1 use expect_test::expect;
3 use super::{check_infer, check_infer_with_mismatches, check_types};
9 //- /main.rs crate:main deps:core
12 impl Future for IntFuture {
22 //- /core.rs crate:core
23 #[prelude_import] use future::*;
25 #[lang = "future_trait"]
38 //- /main.rs crate:main deps:core
39 async fn foo() -> u64 {
49 //- /core.rs crate:core
50 #[prelude_import] use future::*;
52 #[lang = "future_trait"]
62 fn infer_desugar_async() {
65 //- /main.rs crate:main deps:core
66 async fn foo() -> u64 {
73 } //^ impl Future<Output = u64>
75 //- /core.rs crate:core
76 #[prelude_import] use future::*;
88 fn infer_async_block() {
91 //- /main.rs crate:main deps:core
95 // ^ impl Future<Output = i32>
99 let b = async {}.await;
103 let y = Option::None;
107 let _: Option<u64> = c.await;
109 // ^ impl Future<Output = Option<u64>>
112 enum Option<T> { None, Some(T) }
114 //- /core.rs crate:core
115 #[prelude_import] use future::*;
117 #[lang = "future_trait"]
131 //- /main.rs crate:main deps:core
133 let r: Result<i32, u64> = Result::Ok(1);
138 //- /core.rs crate:core
139 #[prelude_import] use ops::*;
147 #[prelude_import] use result::*;
154 impl<O, E> crate::ops::Try for Result<O, E> {
164 fn infer_for_loop() {
167 //- /main.rs crate:main deps:core,alloc
168 use alloc::collections::Vec;
178 //- /core.rs crate:core
179 #[prelude_import] use iter::*;
186 //- /alloc.rs crate:alloc deps:core
190 pub fn new() -> Self { Vec {} }
191 pub fn push(&mut self, t: T) { }
194 impl<T> IntoIterator for Vec<T> {
206 //- /main.rs crate:main deps:std
210 impl std::ops::Neg for Bar {
220 //- /std.rs crate:std
221 #[prelude_import] use ops::*;
236 //- /main.rs crate:main deps:std
240 impl std::ops::Not for Bar {
250 //- /std.rs crate:std
251 #[prelude_import] use ops::*;
263 fn infer_from_bound_1() {
268 impl<U> Trait<U> for S<U> {}
269 fn foo<T: Trait<u32>>(t: T) {}
278 104..143 '{ ...(s); }': ()
280 118..119 'S': S<u32>(u32) -> S<u32>
281 118..128 'S(unknown)': S<u32>
282 120..127 'unknown': u32
283 134..137 'foo': fn foo<S<u32>>(S<u32>)
284 134..140 'foo(s)': ()
291 fn infer_from_bound_2() {
296 impl<U> Trait<U> for S<U> {}
297 fn foo<U, T: Trait<U>>(t: T) -> U {}
306 110..162 '{ ...(s); }': ()
308 124..125 'S': S<u32>(u32) -> S<u32>
309 124..134 'S(unknown)': S<u32>
310 126..133 'unknown': u32
312 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32
313 153..159 'foo(s)': u32
320 fn trait_default_method_self_bound_implements_trait() {
321 cov_mark::check!(trait_self_implements_self);
325 fn foo(&self) -> i64;
337 79..89 'self.foo()': i64
343 fn trait_default_method_self_bound_implements_super_trait() {
347 fn foo(&self) -> i64;
349 trait Trait: SuperTrait {
358 94..129 '{ ... }': ()
360 112..116 'self': &Self
361 112..122 'self.foo()': i64
367 fn infer_project_associated_type() {
374 impl Iterable for S { type Item = u32; }
375 fn test<T: Iterable>() {
376 let x: <S as Iterable>::Item = 1;
377 let y: <T as Iterable>::Item = no_matter;
378 let z: T::Item = no_matter;
379 let a: <T>::Item = no_matter;
383 108..261 '{ ...ter; }': ()
386 156..157 'y': Iterable::Item<T>
387 183..192 'no_matter': Iterable::Item<T>
388 202..203 'z': Iterable::Item<T>
389 215..224 'no_matter': Iterable::Item<T>
390 234..235 'a': Iterable::Item<T>
391 249..258 'no_matter': Iterable::Item<T>
397 fn infer_return_associated_type() {
404 impl Iterable for S { type Item = u32; }
405 fn foo1<T: Iterable>(t: T) -> T::Item {}
406 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {}
407 fn foo3<T: Iterable>(t: T) -> <T>::Item {}
421 234..300 '{ ...(S); }': ()
423 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item
424 248..255 'foo1(S)': u32
427 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item
428 269..276 'foo2(S)': u32
431 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item
432 290..297 'foo3(S)': u32
439 fn infer_associated_type_bound() {
445 fn test<T: Iterable<Item=u32>>() {
446 let y: T::Item = unknown;
450 67..100 '{ ...own; }': ()
452 90..97 'unknown': u32
458 fn infer_const_body() {
461 const A: u32 = 1 + 1;
462 static B: u64 = { let x = 1; x };
468 38..54 '{ let ...1; x }': u64
477 fn tuple_struct_fields() {
488 37..86 '{ ... a.1 }': u64
490 51..52 'S': S(i32, u64) -> S
504 fn tuple_struct_with_fn() {
507 struct S(fn(u32) -> u64);
515 43..101 '{ ...0(2) }': u64
517 57..58 'S': S(fn(u32) -> u64) -> S
518 57..67 'S(|i| 2*i)': S
519 59..66 '|i| 2*i': |u32| -> u64
526 81..84 'a.0': fn(u32) -> u64
530 93..96 'a.0': fn(u32) -> u64
538 fn indexing_arrays() {
540 "fn main() { &mut [9][2]; }",
542 10..26 '{ &mut...[2]; }': ()
543 12..23 '&mut [9][2]': &mut {unknown}
544 17..20 '[9]': [i32; _]
545 17..23 '[9][2]': {unknown}
553 fn infer_ops_index() {
556 //- /main.rs crate:main deps:std
560 impl std::ops::Index<u32> for Bar {
570 //- /std.rs crate:std
571 #[prelude_import] use ops::*;
574 pub trait Index<Idx> {
583 fn infer_ops_index_int() {
586 //- /main.rs crate:main deps:std
590 impl std::ops::Index<u32> for Bar {
595 impl std::ops::Index<Range> for Bar {
606 //- /std.rs crate:std
607 #[prelude_import] use ops::*;
610 pub trait Index<Idx> {
619 fn infer_ops_index_autoderef() {
622 //- /main.rs crate:main deps:std
624 let a = &[1u32, 2, 3];
629 //- /std.rs crate:std
630 impl<T> ops::Index<u32> for [T] {
634 #[prelude_import] use ops::*;
637 pub trait Index<Idx> {
652 fn deref(&self) -> &Self::Target;
656 impl<T> Deref for Arc<T> {
662 fn foo(&self) -> u128 {}
673 fn deref_trait_with_inference_var() {
680 fn deref(&self) -> &Self::Target;
684 fn new_arc<T>() -> Arc<T> {}
685 impl<T> Deref for Arc<T> {
703 fn deref_trait_infinite_recursion() {
709 fn deref(&self) -> &Self::Target;
726 fn deref_trait_with_question_mark_size() {
732 fn deref(&self) -> &Self::Target;
736 impl<T> Deref for Arc<T> {
742 fn foo(&self) -> u128 {}
753 fn obligation_from_function_clause() {
759 impl Trait<u32> for S {}
761 fn foo<T: Trait<U>, U>(t: T) -> U {}
771 fn obligation_from_method_clause() {
778 impl Trait<isize> for S {}
782 fn foo<T: Trait<U>, U>(&self, t: T) -> U {}
793 fn obligation_from_self_method_clause() {
799 impl Trait<i64> for S {}
802 fn foo<U>(&self) -> U where Self: Trait<U> {}
813 fn obligation_from_impl_clause() {
819 impl Trait<&str> for S {}
822 impl<U, T: Trait<U>> O<T> {
823 fn foo(&self) -> U {}
834 fn generic_param_env_1() {
838 trait Trait { fn foo(self) -> u128; }
841 impl<T> Trait for T where T: Clone {}
842 fn test<T: Clone>(t: T) { t.foo(); }
849 fn generic_param_env_1_not_met() {
854 trait Trait { fn foo(self) -> u128; }
857 impl<T> Trait for T where T: Clone {}
858 fn test<T>(t: T) { t.foo(); }
865 fn generic_param_env_2() {
868 trait Trait { fn foo(self) -> u128; }
871 fn test<T: Trait>(t: T) { t.foo(); }
878 fn generic_param_env_2_not_met() {
881 trait Trait { fn foo(self) -> u128; }
884 fn test<T>(t: T) { t.foo(); }
891 fn generic_param_env_deref() {
899 impl<T> Deref for T where T: Trait {
902 fn test<T: Trait>(t: T) { (*t); }
909 fn associated_type_placeholder() {
910 // inside the generic function, the associated type gets normalized to a placeholder `ApplL::Out<T>` [https://rust-lang.github.io/rustc-guide/traits/associated-types.html#placeholder-associated-types].
917 pub struct RefMutL<T>;
919 impl<T> ApplyL for RefMutL<T> {
920 type Out = <T as ApplyL>::Out;
923 fn test<T: ApplyL>() {
924 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
932 fn associated_type_placeholder_2() {
938 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
940 fn test<T: ApplyL>(t: T) {
949 fn argument_impl_trait() {
950 check_infer_with_mismatches(
954 fn foo2(&self) -> i64;
956 fn bar(x: impl Trait<u16>) {}
958 impl<T> Trait<T> for S<T> {}
960 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
976 77..78 'x': impl Trait<u16>
978 154..155 'x': impl Trait<u64>
979 174..175 'y': &impl Trait<u32>
980 195..323 '{ ...2(); }': ()
981 201..202 'x': impl Trait<u64>
982 208..209 'y': &impl Trait<u32>
984 223..224 'S': S<u16>(u16) -> S<u16>
985 223..227 'S(1)': S<u16>
987 233..236 'bar': fn bar(S<u16>)
988 233..239 'bar(z)': ()
990 245..246 'x': impl Trait<u64>
991 245..252 'x.foo()': u64
992 258..259 'y': &impl Trait<u32>
993 258..265 'y.foo()': u32
995 271..278 'z.foo()': u16
996 284..285 'x': impl Trait<u64>
997 284..292 'x.foo2()': i64
998 298..299 'y': &impl Trait<u32>
999 298..306 'y.foo2()': i64
1000 312..313 'z': S<u16>
1001 312..320 'z.foo2()': i64
1007 fn argument_impl_trait_type_args_1() {
1008 check_infer_with_mismatches(
1012 // this function has an implicit Self param, an explicit type param,
1013 // and an implicit impl Trait param!
1014 fn bar<T>(x: impl Trait) -> T { loop {} }
1016 fn foo<T>(x: impl Trait) -> T { loop {} }
1027 <F as Foo>::bar::<u32>(S);
1031 foo::<u32, i32>(S); // we should ignore the extraneous i32
1035 155..156 'x': impl Trait
1036 175..186 '{ loop {} }': T
1037 177..184 'loop {}': !
1039 199..200 'x': impl Trait
1040 219..230 '{ loop {} }': T
1041 221..228 'loop {}': !
1043 300..509 '{ ... i32 }': ()
1044 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1045 306..317 'Foo::bar(S)': {unknown}
1047 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1048 323..341 '<F as ...bar(S)': {unknown}
1050 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1051 347..356 'F::bar(S)': {unknown}
1053 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1054 362..380 'Foo::b...32>(S)': u32
1056 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1057 386..411 '<F as ...32>(S)': u32
1059 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1060 418..424 'foo(S)': {unknown}
1062 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1063 430..443 'foo::<u32>(S)': u32
1065 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1066 449..467 'foo::<...32>(S)': u32
1073 fn argument_impl_trait_type_args_2() {
1074 check_infer_with_mismatches(
1081 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1087 F::<u32>.foo::<i32>(S);
1088 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1093 93..94 'x': impl Trait
1094 118..129 '{ loop {} }': (T, U)
1095 120..127 'loop {}': !
1097 143..283 '{ ...ored }': ()
1098 149..150 'F': F<{unknown}>
1099 149..157 'F.foo(S)': ({unknown}, {unknown})
1101 163..171 'F::<u32>': F<u32>
1102 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1104 184..192 'F::<u32>': F<u32>
1105 184..206 'F::<u3...32>(S)': (u32, i32)
1107 212..220 'F::<u32>': F<u32>
1108 212..239 'F::<u3...32>(S)': (u32, i32)
1115 fn argument_impl_trait_to_fn_pointer() {
1116 check_infer_with_mismatches(
1119 fn foo(x: impl Trait) { loop {} }
1124 let f: fn(S) -> () = foo;
1128 22..23 'x': impl Trait
1129 37..48 '{ loop {} }': ()
1132 90..123 '{ ...foo; }': ()
1134 117..120 'foo': fn foo(S)
1145 fn foo2(&self) -> i64;
1147 fn bar() -> impl Trait<u64> {}
1149 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1162 29..33 'self': &Self
1163 54..58 'self': &Self
1165 110..111 'x': impl Trait<u64>
1166 130..131 'y': &impl Trait<u64>
1167 151..268 '{ ...2(); }': ()
1168 157..158 'x': impl Trait<u64>
1169 164..165 'y': &impl Trait<u64>
1170 175..176 'z': impl Trait<u64>
1171 179..182 'bar': fn bar() -> impl Trait<u64>
1172 179..184 'bar()': impl Trait<u64>
1173 190..191 'x': impl Trait<u64>
1174 190..197 'x.foo()': u64
1175 203..204 'y': &impl Trait<u64>
1176 203..210 'y.foo()': u64
1177 216..217 'z': impl Trait<u64>
1178 216..223 'z.foo()': u64
1179 229..230 'x': impl Trait<u64>
1180 229..237 'x.foo2()': i64
1181 243..244 'y': &impl Trait<u64>
1182 243..251 'y.foo2()': i64
1183 257..258 'z': impl Trait<u64>
1184 257..265 'z.foo2()': i64
1190 fn simple_return_pos_impl_trait() {
1191 cov_mark::check!(lower_rpit);
1197 fn bar() -> impl Trait<u64> { loop {} }
1205 29..33 'self': &Self
1206 71..82 '{ loop {} }': !
1209 94..129 '{ ...o(); }': ()
1210 104..105 'a': impl Trait<u64>
1211 108..111 'bar': fn bar() -> impl Trait<u64>
1212 108..113 'bar()': impl Trait<u64>
1213 119..120 'a': impl Trait<u64>
1214 119..126 'a.foo()': u64
1220 fn more_return_pos_impl_trait() {
1225 fn next(&mut self) -> Self::Item;
1230 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 {} }
1237 let (c, d) = baz(1u128);
1243 49..53 'self': &mut Self
1244 101..105 'self': &Self
1245 184..195 '{ loop {} }': ({unknown}, {unknown})
1246 186..193 'loop {}': !
1249 268..279 '{ loop {} }': ({unknown}, {unknown})
1250 270..277 'loop {}': !
1252 291..413 '{ ...o(); }': ()
1253 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1254 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1255 305..306 'b': impl Trait<u64>
1256 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1257 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1258 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1259 321..329 'a.next()': impl Trait<u32>
1260 321..335 'a.next().foo()': u32
1261 341..342 'b': impl Trait<u64>
1262 341..348 'b.foo()': u64
1263 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1264 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1265 362..363 'd': impl Trait<u128>
1266 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1267 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1268 371..376 '1u128': u128
1269 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1270 383..391 'c.next()': impl Trait<u128>
1271 383..397 'c.next().foo()': u128
1272 403..404 'd': impl Trait<u128>
1273 403..410 'd.foo()': u128
1284 fn foo2(&self) -> i64;
1286 fn bar() -> dyn Trait<u64> {}
1288 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1301 29..33 'self': &Self
1302 54..58 'self': &Self
1304 109..110 'x': dyn Trait<u64>
1305 128..129 'y': &dyn Trait<u64>
1306 148..265 '{ ...2(); }': ()
1307 154..155 'x': dyn Trait<u64>
1308 161..162 'y': &dyn Trait<u64>
1309 172..173 'z': dyn Trait<u64>
1310 176..179 'bar': fn bar() -> dyn Trait<u64>
1311 176..181 'bar()': dyn Trait<u64>
1312 187..188 'x': dyn Trait<u64>
1313 187..194 'x.foo()': u64
1314 200..201 'y': &dyn Trait<u64>
1315 200..207 'y.foo()': u64
1316 213..214 'z': dyn Trait<u64>
1317 213..220 'z.foo()': u64
1318 226..227 'x': dyn Trait<u64>
1319 226..234 'x.foo2()': i64
1320 240..241 'y': &dyn Trait<u64>
1321 240..248 'y.foo2()': i64
1322 254..255 'z': dyn Trait<u64>
1323 254..262 'z.foo2()': i64
1329 fn dyn_trait_in_impl() {
1333 fn foo(&self) -> (T, U);
1336 impl<T, U> S<T, U> {
1337 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1339 trait Trait2<T, U> {
1340 fn baz(&self) -> (T, U);
1342 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1344 fn test(s: S<u32, i32>) {
1349 32..36 'self': &Self
1350 102..106 'self': &S<T, U>
1351 128..139 '{ loop {} }': &dyn Trait<T, U>
1352 130..137 'loop {}': !
1354 175..179 'self': &Self
1355 251..252 's': S<u32, i32>
1356 267..289 '{ ...z(); }': ()
1357 273..274 's': S<u32, i32>
1358 273..280 's.bar()': &dyn Trait<u32, i32>
1359 273..286 's.bar().baz()': (u32, i32)
1365 fn dyn_trait_bare() {
1369 fn foo(&self) -> u64;
1371 fn bar() -> Trait {}
1373 fn test(x: Trait, y: &Trait) -> u64 {
1383 26..30 'self': &Self
1385 72..73 'x': dyn Trait
1386 82..83 'y': &dyn Trait
1387 100..175 '{ ...o(); }': ()
1388 106..107 'x': dyn Trait
1389 113..114 'y': &dyn Trait
1390 124..125 'z': dyn Trait
1391 128..131 'bar': fn bar() -> dyn Trait
1392 128..133 'bar()': dyn Trait
1393 139..140 'x': dyn Trait
1394 139..146 'x.foo()': u64
1395 152..153 'y': &dyn Trait
1396 152..159 'y.foo()': u64
1397 165..166 'z': dyn Trait
1398 165..172 'z.foo()': u64
1408 fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) {}
1411 23..24 'a': impl Trait
1413 69..70 'c': impl Trait
1416 123..124 'f': impl Trait
1424 fn error_bound_chalk() {
1428 fn foo(&self) -> u32 {}
1431 fn test(x: (impl Trait + UnknownTrait)) {
1439 fn assoc_type_bindings() {
1446 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1447 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1448 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1451 impl<T> Trait for S<T> { type Type = T; }
1453 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1472 262..263 'y': impl Trait<Type = i64>
1473 289..397 '{ ...r>); }': ()
1474 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1475 295..301 'get(x)': u32
1477 307..311 'get2': fn get2<u32, T>(T) -> u32
1478 307..314 'get2(x)': u32
1480 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1481 320..326 'get(y)': i64
1482 324..325 'y': impl Trait<Type = i64>
1483 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1484 332..339 'get2(y)': i64
1485 337..338 'y': impl Trait<Type = i64>
1486 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1487 345..356 'get(set(S))': u64
1488 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1489 349..355 'set(S)': S<u64>
1490 353..354 'S': S<u64>
1491 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1492 362..374 'get2(set(S))': u64
1493 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1494 367..373 'set(S)': S<u64>
1495 371..372 'S': S<u64>
1496 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1497 380..394 'get2(S::<str>)': str
1498 385..393 'S::<str>': S<str>
1504 fn impl_trait_assoc_binding_projection_bug() {
1507 //- /main.rs crate:main deps:std
1508 pub trait Language {
1511 pub enum RustLanguage {}
1512 impl Language for RustLanguage {
1513 type Kind = SyntaxKind;
1515 struct SyntaxNode<L> {}
1516 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1519 fn clone(&self) -> Self;
1522 fn api_walkthrough() {
1528 //- /std.rs crate:std
1529 #[prelude_import] use iter::*;
1531 trait IntoIterator {
1537 impl<T: Iterator> IntoIterator for T {
1538 type Item = <T as Iterator>::Item;
1546 fn projection_eq_within_chalk() {
1555 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1557 fn test<T: Trait1<Type = u32>>(x: T) {
1564 169..185 '{ ...o(); }': ()
1566 175..182 'x.foo()': u32
1572 fn where_clause_trait_in_scope_for_method_resolution() {
1577 fn foo(&self) -> u32 {}
1581 fn test<T: foo::Trait>(x: T) {
1589 fn super_trait_method_resolution() {
1594 fn foo(&self) -> u32 {}
1597 trait Trait1: foo::SuperTrait {}
1598 trait Trait2 where Self: foo::SuperTrait {}
1600 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1606 49..53 'self': &Self
1610 193..222 '{ ...o(); }': ()
1612 199..206 'x.foo()': u32
1614 212..219 'y.foo()': u32
1620 fn super_trait_impl_trait_method_resolution() {
1625 fn foo(&self) -> u32 {}
1628 trait Trait1: foo::SuperTrait {}
1630 fn test(x: &impl Trait1) {
1635 49..53 'self': &Self
1637 115..116 'x': &impl Trait1
1638 132..148 '{ ...o(); }': ()
1639 138..139 'x': &impl Trait1
1640 138..145 'x.foo()': u32
1646 fn super_trait_cycle() {
1647 // This just needs to not crash
1653 fn test<T: A>(x: T) {
1659 49..65 '{ ...o(); }': ()
1661 55..62 'x.foo()': {unknown}
1667 fn super_trait_assoc_type_bounds() {
1670 trait SuperTrait { type Type; }
1671 trait Trait where Self: SuperTrait {}
1673 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1674 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1677 impl<T> SuperTrait for S<T> { type Type = T; }
1678 impl<T> Trait for S<T> {}
1690 258..279 '{ ...S)); }': ()
1691 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1692 264..276 'get2(set(S))': u64
1693 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1694 269..275 'set(S)': S<u64>
1695 273..274 'S': S<u64>
1702 check_infer_with_mismatches(
1704 trait FnOnce<Args> {
1707 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1710 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1711 f.call_once((1, 2));
1718 155..183 '{ ...2)); }': ()
1720 161..180 'f.call...1, 2))': u128
1721 173..179 '(1, 2)': (u32, u64)
1729 fn fn_ptr_and_item() {
1730 check_infer_with_mismatches(
1733 trait FnOnce<Args> {
1736 fn call_once(self, args: Args) -> Self::Output;
1745 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1746 fn foo(&self) -> (A1, R) { loop {} }
1749 enum Opt<T> { None, Some(T) }
1751 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1755 let bar: Bar<fn(u8) -> u32>;
1759 let f: fn(u8) -> u32;
1766 139..143 'self': &Self
1767 243..247 'self': &Bar<F>
1768 260..271 '{ loop {} }': (A1, R)
1769 262..269 'loop {}': !
1771 355..359 'self': Opt<T>
1773 377..388 '{ loop {} }': Opt<U>
1774 379..386 'loop {}': !
1776 402..518 '{ ...(f); }': ()
1777 412..415 'bar': Bar<fn(u8) -> u32>
1778 441..444 'bar': Bar<fn(u8) -> u32>
1779 441..450 'bar.foo()': (u8, u32)
1780 461..464 'opt': Opt<u8>
1781 483..484 'f': fn(u8) -> u32
1782 505..508 'opt': Opt<u8>
1783 505..515 'opt.map(f)': Opt<u32>
1784 513..514 'f': fn(u8) -> u32
1790 fn fn_trait_deref_with_ty_default() {
1797 fn deref(&self) -> &Self::Target;
1801 trait FnOnce<Args> {
1804 fn call_once(self, args: Args) -> Self::Output;
1810 fn foo(&self) -> usize {}
1813 struct Lazy<T, F = fn() -> T>(F);
1815 impl<T, F> Lazy<T, F> {
1816 pub fn new(f: F) -> Lazy<T, F> {}
1819 impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
1824 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1825 let r1 = lazy1.foo();
1827 fn make_foo_fn() -> Foo {}
1828 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1829 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1830 let r2 = lazy2.foo();
1834 64..68 'self': &Self
1835 165..169 'self': Self
1836 171..175 'args': Args
1837 239..243 'self': &Foo
1841 443..689 '{ ...o(); }': ()
1842 453..458 'lazy1': Lazy<Foo, || -> Foo>
1843 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1844 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1845 485..491 '|| Foo': || -> Foo
1847 502..504 'r1': usize
1848 507..512 'lazy1': Lazy<Foo, || -> Foo>
1849 507..518 'lazy1.foo()': usize
1850 560..575 'make_foo_fn_ptr': fn() -> Foo
1851 591..602 'make_foo_fn': fn make_foo_fn() -> Foo
1852 612..617 'lazy2': Lazy<Foo, fn() -> Foo>
1853 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1854 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1855 644..659 'make_foo_fn_ptr': fn() -> Foo
1856 670..672 'r2': usize
1857 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1858 675..686 'lazy2.foo()': usize
1866 check_infer_with_mismatches(
1869 trait FnOnce<Args> {
1873 enum Option<T> { Some(T), None }
1875 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1879 let x = Option::Some(1u32);
1882 let y: Option<i64> = x.map(|_v| 1);
1886 147..151 'self': Option<T>
1888 172..183 '{ loop {} }': Option<U>
1889 174..181 'loop {}': !
1891 197..316 '{ ... 1); }': ()
1892 207..208 'x': Option<u32>
1893 211..223 'Option::Some': Some<u32>(u32) -> Option<u32>
1894 211..229 'Option...(1u32)': Option<u32>
1895 224..228 '1u32': u32
1896 235..236 'x': Option<u32>
1897 235..251 'x.map(...v + 1)': Option<u32>
1898 241..250 '|v| v + 1': |u32| -> u32
1901 245..250 'v + 1': u32
1903 257..258 'x': Option<u32>
1904 257..273 'x.map(... 1u64)': Option<u64>
1905 263..272 '|_v| 1u64': |u32| -> u64
1907 268..272 '1u64': u64
1908 283..284 'y': Option<i64>
1909 300..301 'x': Option<u32>
1910 300..313 'x.map(|_v| 1)': Option<i64>
1911 306..312 '|_v| 1': |u32| -> i64
1920 check_infer_with_mismatches(
1922 trait FnOnce<Args> {
1926 fn test<F: FnOnce(u32) -> u64>(f: F) {
1930 let h = |v| 1u128 + v;
1935 78..154 '{ ...+ v; }': ()
1937 84..88 'f(1)': {unknown}
1939 98..99 'g': |u64| -> i32
1940 102..111 '|v| v + 1': |u64| -> i32
1943 106..111 'v + 1': i32
1945 117..118 'g': |u64| -> i32
1946 117..124 'g(1u64)': i32
1947 119..123 '1u64': u64
1948 134..135 'h': |u128| -> u128
1949 138..151 '|v| 1u128 + v': |u128| -> u128
1951 142..147 '1u128': u128
1952 142..151 '1u128 + v': u128
1959 fn closure_as_argument_inference_order() {
1960 check_infer_with_mismatches(
1963 trait FnOnce<Args> {
1967 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 {} }
1972 fn method(self) -> u64;
1974 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 {} }
1979 let x1 = foo1(S, |s| s.method());
1980 let x2 = foo2(|s| s.method(), S);
1981 let x3 = S.foo1(S, |s| s.method());
1982 let x4 = S.foo2(|s| s.method(), S);
1988 111..122 '{ loop {} }': U
1989 113..120 'loop {}': !
1993 173..184 '{ loop {} }': U
1994 175..182 'loop {}': !
2000 294..305 '{ loop {} }': U
2001 296..303 'loop {}': !
2006 366..377 '{ loop {} }': U
2007 368..375 'loop {}': !
2009 391..550 '{ ... S); }': ()
2011 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2012 406..429 'foo1(S...hod())': u64
2014 414..428 '|s| s.method()': |S| -> u64
2017 418..428 's.method()': u64
2019 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2020 444..467 'foo2(|...(), S)': u64
2021 449..463 '|s| s.method()': |S| -> u64
2024 453..463 's.method()': u64
2028 482..507 'S.foo1...hod())': u64
2030 492..506 '|s| s.method()': |S| -> u64
2033 496..506 's.method()': u64
2036 522..547 'S.foo2...(), S)': u64
2037 529..543 '|s| s.method()': |S| -> u64
2040 533..543 's.method()': u64
2047 fn fn_item_fn_trait() {
2051 trait FnOnce<Args> {
2059 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2063 } //^^^^^^^^^^^^^^^^^^ S
2069 fn unselected_projection_in_trait_env_1() {
2078 fn foo(&self) -> u32;
2081 fn test<T: Trait>() where T::Item: Trait2 {
2082 let x: T::Item = no_matter;
2090 fn unselected_projection_in_trait_env_2() {
2098 fn foo(&self) -> u32;
2101 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2102 let x: T::Item = no_matter;
2110 fn unselected_projection_on_impl_self() {
2117 fn f(&self, x: Self::Item);
2124 fn f(&self, x: Self::Item) { let y = x; }
2131 fn f(&self, x: <Self>::Item) { let y = x; }
2135 40..44 'self': &Self
2136 46..47 'x': Trait::Item<Self>
2139 147..161 '{ let y = x; }': ()
2142 228..232 'self': &S2
2144 251..265 '{ let y = x; }': ()
2152 fn unselected_projection_on_trait_self() {
2158 fn f(&self) -> Self::Item { loop {} }
2174 fn unselected_projection_chalk_fold() {
2178 trait Fold<I: Interner, TI = I> {
2182 struct Ty<I: Interner> {}
2183 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2184 type Result = Ty<TI>;
2187 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2194 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2202 fn trait_impl_self_ty() {
2211 impl Trait<Self> for S {}
2221 fn trait_impl_self_ty_cycle() {
2230 impl Trait for S<Self> {}
2240 fn unselected_projection_in_trait_env_cycle_1() {
2241 // this is a legitimate cycle
2250 fn test<T: Trait>() where T: Trait2<T::Item> {
2251 let x: T::Item = no_matter;
2258 fn unselected_projection_in_trait_env_cycle_2() {
2259 // this is a legitimate cycle
2267 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2268 let x: T::Item = no_matter;
2275 fn inline_assoc_type_bounds_1() {
2281 trait OtherTrait<T> {
2285 // workaround for Chalk assoc type normalization problems
2287 impl<T: Iterator> Iterator for S<T> {
2288 type Item = <T as Iterator>::Item;
2291 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2292 let x: <S<I> as Iterator>::Item;
2300 fn inline_assoc_type_bounds_2() {
2307 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2308 let x: <<I as Iterator>::Item as Iterator>::Item;
2316 fn proc_macro_server_types() {
2319 macro_rules! with_api {
2320 ($S:ident, $self:ident, $m:ident) => {
2323 fn new() -> $S::TokenStream;
2330 macro_rules! associated_item {
2331 (type TokenStream) =>
2332 (type TokenStream: 'static;);
2334 (type Group: 'static;);
2335 ($($item:tt)*) => ($($item)*;)
2337 macro_rules! declare_server_traits {
2339 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2342 $(associated_item!(type $name);)*
2345 $(pub trait $name: Types {
2346 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2349 pub trait Server: Types $(+ $name)* {}
2350 impl<S: Types $(+ $name)*> Server for S {}
2354 with_api!(Self, self_, declare_server_traits);
2358 impl Types for Rustc {
2359 type TokenStream = T;
2363 fn make<T>() -> T { loop {} }
2364 impl TokenStream for Rustc {
2365 fn new() -> Self::TokenStream {
2366 let group: Self::Group = make();
2372 1061..1072 '{ loop {} }': T
2373 1063..1070 'loop {}': !
2375 1136..1199 '{ ... }': T
2376 1150..1155 'group': G
2377 1171..1175 'make': fn make<G>() -> G
2378 1171..1177 'make()': G
2379 1187..1191 'make': fn make<T>() -> T
2380 1187..1193 'make()': T
2386 fn unify_impl_trait() {
2387 check_infer_with_mismatches(
2391 fn foo(x: impl Trait<u32>) { loop {} }
2392 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2395 impl<T> Trait<T> for S<T> {}
2397 fn default<T>() -> T { loop {} }
2399 fn test() -> impl Trait<i32> {
2400 let s1 = S(default());
2402 let x: i32 = bar(S(default()));
2407 26..27 'x': impl Trait<u32>
2408 46..57 '{ loop {} }': ()
2411 68..69 'x': impl Trait<T>
2412 91..102 '{ loop {} }': T
2413 93..100 'loop {}': !
2415 171..182 '{ loop {} }': T
2416 173..180 'loop {}': !
2418 213..309 '{ ...t()) }': S<{unknown}>
2419 223..225 's1': S<u32>
2420 228..229 'S': S<u32>(u32) -> S<u32>
2421 228..240 'S(default())': S<u32>
2422 230..237 'default': fn default<u32>() -> u32
2423 230..239 'default()': u32
2424 246..249 'foo': fn foo(S<u32>)
2425 246..253 'foo(s1)': ()
2426 250..252 's1': S<u32>
2428 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2429 272..289 'bar(S(...lt()))': i32
2430 276..277 'S': S<i32>(i32) -> S<i32>
2431 276..288 'S(default())': S<i32>
2432 278..285 'default': fn default<i32>() -> i32
2433 278..287 'default()': i32
2434 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2435 295..307 'S(default())': S<{unknown}>
2436 297..304 'default': fn default<{unknown}>() -> {unknown}
2437 297..306 'default()': {unknown}
2443 fn assoc_types_from_bounds() {
2448 trait FnOnce<Args> {
2467 f::<(), _>(|z| { z; });
2473 193..224 '{ ... }); }': ()
2474 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2475 199..221 'f::<()... z; })': ()
2476 210..220 '|z| { z; }': |&()| -> ()
2478 214..220 '{ z; }': ()
2485 fn associated_type_bound() {
2489 type Item: OtherTrait<u32>;
2491 pub trait OtherTrait<T> {
2495 // this is just a workaround for chalk#234
2497 impl<T: Trait> Trait for S<T> {
2498 type Item = <T as Trait>::Item;
2501 fn test<T: Trait>() {
2502 let y: <S<T> as Trait>::Item = no_matter;
2510 fn dyn_trait_through_chalk() {
2518 impl<T> Deref for Box<T> {
2525 fn test(x: Box<dyn Trait>) {
2533 fn string_to_owned() {
2539 fn to_owned(&self) -> Self::Owned;
2541 impl ToOwned for str {
2542 type Owned = String;
2552 fn iterator_chain() {
2553 check_infer_with_mismatches(
2557 trait FnOnce<Args> {
2561 trait FnMut<Args>: FnOnce<Args> { }
2563 enum Option<T> { Some(T), None }
2566 pub trait Iterator {
2569 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2571 F: FnMut(Self::Item) -> Option<B>,
2574 fn for_each<F>(self, f: F)
2576 F: FnMut(Self::Item),
2580 pub trait IntoIterator {
2582 type IntoIter: Iterator<Item = Self::Item>;
2583 fn into_iter(self) -> Self::IntoIter;
2586 pub struct FilterMap<I, F> { }
2587 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2589 F: FnMut(I::Item) -> Option<B>,
2594 #[stable(feature = "rust1", since = "1.0.0")]
2595 impl<I: Iterator> IntoIterator for I {
2596 type Item = I::Item;
2599 fn into_iter(self) -> I {
2606 fn new() -> Self { loop {} }
2609 impl<T> IntoIterator for Vec<T> {
2611 type IntoIter = IntoIter<T>;
2614 pub struct IntoIter<T> { }
2615 impl<T> Iterator for IntoIter<T> {
2620 Vec::<i32>::new().into_iter()
2621 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2622 .for_each(|y| { y; });
2626 226..230 'self': Self
2628 317..328 '{ loop {} }': FilterMap<Self, F>
2629 319..326 'loop {}': !
2631 349..353 'self': Self
2633 405..416 '{ loop {} }': ()
2634 407..414 'loop {}': !
2636 525..529 'self': Self
2638 865..885 '{ ... }': I
2640 944..955 '{ loop {} }': Vec<T>
2641 946..953 'loop {}': !
2643 1142..1269 '{ ... }); }': ()
2644 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2645 1148..1165 'Vec::<...:new()': Vec<i32>
2646 1148..1177 'Vec::<...iter()': IntoIter<i32>
2647 1148..1240 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2648 1148..1266 'Vec::<... y; })': ()
2649 1194..1239 '|x| if...None }': |i32| -> Option<u32>
2651 1198..1239 'if x >...None }': Option<u32>
2653 1201..1206 'x > 0': bool
2655 1207..1225 '{ Some...u32) }': Option<u32>
2656 1209..1213 'Some': Some<u32>(u32) -> Option<u32>
2657 1209..1223 'Some(x as u32)': Option<u32>
2659 1214..1222 'x as u32': u32
2660 1231..1239 '{ None }': Option<u32>
2661 1233..1237 'None': Option<u32>
2662 1255..1265 '|y| { y; }': |u32| -> ()
2664 1259..1265 '{ y; }': ()
2687 fn foo() -> Self::Output;
2691 type Output = T::OutputA;
2692 fn foo() -> Self::Output { loop {} }
2703 fn trait_object_no_coercion() {
2704 check_infer_with_mismatches(
2708 fn foo(x: &dyn Foo) {}
2710 fn test(x: &dyn Foo) {
2715 21..22 'x': &dyn Foo
2717 46..47 'x': &dyn Foo
2718 59..74 '{ foo(x); }': ()
2719 65..68 'foo': fn foo(&dyn Foo)
2721 69..70 'x': &dyn Foo
2728 check_infer_with_mismatches(
2734 impl Copy for IsCopy {}
2737 trait Test { fn test(&self) -> bool; }
2738 impl<T: Copy> Test for T {}
2743 (IsCopy, IsCopy).test();
2744 (IsCopy, NotCopy).test();
2748 110..114 'self': &Self
2749 166..267 '{ ...t(); }': ()
2750 172..178 'IsCopy': IsCopy
2751 172..185 'IsCopy.test()': bool
2752 191..198 'NotCopy': NotCopy
2753 191..205 'NotCopy.test()': {unknown}
2754 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy)
2755 211..234 '(IsCop...test()': bool
2756 212..218 'IsCopy': IsCopy
2757 220..226 'IsCopy': IsCopy
2758 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy)
2759 240..264 '(IsCop...test()': {unknown}
2760 241..247 'IsCopy': IsCopy
2761 249..256 'NotCopy': NotCopy
2767 fn builtin_fn_def_copy() {
2768 check_infer_with_mismatches(
2774 fn bar<T: Copy>(T) -> T {}
2775 struct Struct(usize);
2776 enum Enum { Variant(usize) }
2778 trait Test { fn test(&self) -> bool; }
2779 impl<T: Copy> Test for T {}
2785 Enum::Variant.test();
2790 60..61 'T': {unknown}
2792 68..70: expected T, got ()
2793 145..149 'self': &Self
2794 201..281 '{ ...t(); }': ()
2795 207..210 'foo': fn foo()
2796 207..217 'foo.test()': bool
2797 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2798 223..233 'bar.test()': bool
2799 239..245 'Struct': Struct(usize) -> Struct
2800 239..252 'Struct.test()': bool
2801 258..271 'Enum::Variant': Variant(usize) -> Enum
2802 258..278 'Enum::...test()': bool
2808 fn builtin_fn_ptr_copy() {
2809 check_infer_with_mismatches(
2814 trait Test { fn test(&self) -> bool; }
2815 impl<T: Copy> Test for T {}
2817 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2824 54..58 'self': &Self
2826 118..120 'f2': fn(usize) -> u8
2827 139..141 'f3': fn(u8, u8) -> &u8
2828 162..210 '{ ...t(); }': ()
2830 168..177 'f1.test()': bool
2831 183..185 'f2': fn(usize) -> u8
2832 183..192 'f2.test()': bool
2833 198..200 'f3': fn(u8, u8) -> &u8
2834 198..207 'f3.test()': bool
2840 fn builtin_sized() {
2841 check_infer_with_mismatches(
2846 trait Test { fn test(&self) -> bool; }
2847 impl<T: Sized> Test for T {}
2851 (*"foo").test(); // not Sized
2853 (1u8, *"foo").test(); // not Sized
2857 56..60 'self': &Self
2858 113..228 '{ ...ized }': ()
2860 119..129 '1u8.test()': bool
2861 135..150 '(*"foo").test()': {unknown}
2862 136..142 '*"foo"': str
2863 137..142 '"foo"': &str
2864 169..179 '(1u8, 1u8)': (u8, u8)
2865 169..186 '(1u8, ...test()': bool
2868 192..205 '(1u8, *"foo")': (u8, str)
2869 192..212 '(1u8, ...test()': {unknown}
2871 198..204 '*"foo"': str
2872 199..204 '"foo"': &str
2878 fn integer_range_iterate() {
2881 //- /main.rs crate:main deps:core
2883 for x in 0..100 { x; }
2886 //- /core.rs crate:core
2888 pub struct Range<Idx> {
2895 pub trait Iterator {
2899 pub trait IntoIterator {
2901 type IntoIter: Iterator<Item = Self::Item>;
2904 impl<T> IntoIterator for T where T: Iterator {
2905 type Item = <T as Iterator>::Item;
2906 type IntoIter = Self;
2911 impl Step for i32 {}
2912 impl Step for i64 {}
2914 impl<A: Step> iter::Iterator for ops::Range<A> {
2922 fn infer_closure_arg() {
2933 let s = Option::None;
2934 let f = |x: Option<i32>| {};
2939 52..126 '{ ...)(s) }': ()
2940 62..63 's': Option<i32>
2941 66..78 'Option::None': Option<i32>
2942 88..89 'f': |Option<i32>| -> ()
2943 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
2944 93..94 'x': Option<i32>
2946 117..124 '(&f)(s)': ()
2947 118..120 '&f': &|Option<i32>| -> ()
2948 119..120 'f': |Option<i32>| -> ()
2949 122..123 's': Option<i32>
2955 fn infer_fn_trait_arg() {
2956 check_infer_with_mismatches(
2958 //- /lib.rs deps:std
2961 pub trait FnOnce<Args> {
2964 extern "rust-call" fn call_once(&self, args: Args) -> Self::Output;
2968 pub trait Fn<Args>:FnOnce<Args> {
2969 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
2977 fn foo<F, T>(f: F) -> T
2979 F: Fn(Option<i32>) -> T,
2986 101..105 'self': &Self
2987 107..111 'args': Args
2988 220..224 'self': &Self
2989 226..230 'args': Args
2991 359..389 '{ ...f(s) }': T
2992 369..370 's': Option<i32>
2993 373..377 'None': Option<i32>
2996 385..386 's': Option<i32>
3002 fn infer_box_fn_arg() {
3003 // The type mismatch is a bug
3004 check_infer_with_mismatches(
3006 //- /lib.rs deps:std
3009 pub trait FnOnce<Args> {
3012 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3017 type Target: ?Sized;
3019 fn deref(&self) -> &Self::Target;
3022 #[lang = "owned_box"]
3023 pub struct Box<T: ?Sized> {
3027 impl<T: ?Sized> Deref for Box<T> {
3030 fn deref(&self) -> &T {
3041 let s = Option::None;
3042 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3047 100..104 'self': Self
3048 106..110 'args': Args
3049 214..218 'self': &Self
3050 384..388 'self': &Box<T>
3051 396..423 '{ ... }': &T
3052 406..417 '&self.inner': &*mut T
3053 407..411 'self': &Box<T>
3054 407..417 'self.inner': *mut T
3055 478..576 '{ ...&s); }': ()
3056 488..489 's': Option<i32>
3057 492..504 'Option::None': Option<i32>
3058 514..515 'f': Box<dyn FnOnce(&Option<i32>)>
3059 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3060 554..561 '|ps| {}': |{unknown}| -> ()
3061 555..557 'ps': {unknown}
3063 568..569 'f': Box<dyn FnOnce(&Option<i32>)>
3064 568..573 'f(&s)': FnOnce::Output<dyn FnOnce(&Option<i32>), (&Option<i32>,)>
3065 570..572 '&s': &Option<i32>
3066 571..572 's': Option<i32>
3067 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|_| -> ()>
3073 fn infer_dyn_fn_output() {
3077 pub trait FnOnce<Args> {
3079 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3083 pub trait Fn<Args>: FnOnce<Args> {
3084 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3088 let f: &dyn Fn() -> i32;
3096 fn infer_dyn_fn_once_output() {
3100 pub trait FnOnce<Args> {
3102 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3106 let f: dyn FnOnce() -> i32;
3114 fn variable_kinds_1() {
3117 trait Trait<T> { fn get(self, t: T) -> T; }
3119 impl Trait<u128> for S {}
3120 impl Trait<f32> for S {}
3132 fn variable_kinds_2() {
3135 trait Trait { fn get(self) -> Self; }
3136 impl Trait for u128 {}
3137 impl Trait for f32 {}
3149 fn underscore_import() {
3154 fn method(&self) -> u8 { 0 }
3159 impl crate::tr::Tr for Tr {}
3161 use crate::tr::Tr as _;
3176 fn method(&self) -> u8 { 0 }
3193 fn trait_in_scope_with_inner_item() {
3198 fn method(&self) -> u8 { 0 }
3214 46..50 'self': &Self
3217 115..185 '{ ... } }': ()
3218 132..183 '{ ... }': ()
3220 142..153 '().method()': u8
3226 fn inner_use_in_block() {
3231 fn method(&self) -> u8 { 0 }
3247 //^^^^^^^^^^^ {unknown}
3251 //^^^^^^^^^^^ {unknown}
3258 fn nested_inner_function_calling_self() {
3269 17..73 '{ ... } }': ()
3270 39..71 '{ ... }': ()
3272 57..62 'inner': fn inner() -> S