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> {
167 //- /main.rs crate:main deps:core
169 let r: Result<i32, u64> = Result::Ok(1);
174 //- /core.rs crate:core
175 #[prelude_import] use ops::*;
183 #[prelude_import] use result::*;
191 impl<O, E> crate::ops::Try for Result<O, E> {
193 type Error = Result<Infallible, E>;
201 fn infer_for_loop() {
204 //- /main.rs crate:main deps:core,alloc
205 use alloc::collections::Vec;
215 //- /core.rs crate:core
216 #[prelude_import] use iter::*;
223 //- /alloc.rs crate:alloc deps:core
227 pub fn new() -> Self { Vec {} }
228 pub fn push(&mut self, t: T) { }
231 impl<T> IntoIterator for Vec<T> {
243 //- /main.rs crate:main deps:std
247 impl std::ops::Neg for Bar {
257 //- /std.rs crate:std
258 #[prelude_import] use ops::*;
273 //- /main.rs crate:main deps:std
277 impl std::ops::Not for Bar {
287 //- /std.rs crate:std
288 #[prelude_import] use ops::*;
300 fn infer_from_bound_1() {
305 impl<U> Trait<U> for S<U> {}
306 fn foo<T: Trait<u32>>(t: T) {}
314 104..143 '{ ...(s); }': ()
316 118..119 'S': S<u32>(u32) -> S<u32>
317 118..128 'S(unknown)': S<u32>
318 120..127 'unknown': u32
319 134..137 'foo': fn foo<S<u32>>(S<u32>)
320 134..140 'foo(s)': ()
327 fn infer_from_bound_2() {
332 impl<U> Trait<U> for S<U> {}
333 fn foo<U, T: Trait<U>>(t: T) -> U {}
341 110..162 '{ ...(s); }': ()
343 124..125 'S': S<u32>(u32) -> S<u32>
344 124..134 'S(unknown)': S<u32>
345 126..133 'unknown': u32
347 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32
348 153..159 'foo(s)': u32
355 fn trait_default_method_self_bound_implements_trait() {
356 cov_mark::check!(trait_self_implements_self);
360 fn foo(&self) -> i64;
371 79..89 'self.foo()': i64
377 fn trait_default_method_self_bound_implements_super_trait() {
381 fn foo(&self) -> i64;
383 trait Trait: SuperTrait {
391 94..129 '{ ... }': ()
393 112..116 'self': &Self
394 112..122 'self.foo()': i64
400 fn infer_project_associated_type() {
407 impl Iterable for S { type Item = u32; }
408 fn test<T: Iterable>() {
409 let x: <S as Iterable>::Item = 1;
410 let y: <T as Iterable>::Item = no_matter;
411 let z: T::Item = no_matter;
412 let a: <T>::Item = no_matter;
415 108..261 '{ ...ter; }': ()
418 156..157 'y': Iterable::Item<T>
419 183..192 'no_matter': Iterable::Item<T>
420 202..203 'z': Iterable::Item<T>
421 215..224 'no_matter': Iterable::Item<T>
422 234..235 'a': Iterable::Item<T>
423 249..258 'no_matter': Iterable::Item<T>
429 fn infer_return_associated_type() {
436 impl Iterable for S { type Item = u32; }
437 fn foo1<T: Iterable>(t: T) -> T::Item {}
438 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {}
439 fn foo3<T: Iterable>(t: T) -> <T>::Item {}
452 234..300 '{ ...(S); }': ()
454 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item
455 248..255 'foo1(S)': u32
458 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item
459 269..276 'foo2(S)': u32
462 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item
463 290..297 'foo3(S)': u32
470 fn infer_associated_type_bound() {
476 fn test<T: Iterable<Item=u32>>() {
477 let y: T::Item = unknown;
480 67..100 '{ ...own; }': ()
482 90..97 'unknown': u32
488 fn infer_const_body() {
491 const A: u32 = 1 + 1;
492 static B: u64 = { let x = 1; x };"#,
497 38..54 '{ let ...1; x }': u64
506 fn tuple_struct_fields() {
516 37..86 '{ ... a.1 }': u64
518 51..52 'S': S(i32, u64) -> S
532 fn tuple_struct_with_fn() {
535 struct S(fn(u32) -> u64);
542 43..101 '{ ...0(2) }': u64
544 57..58 'S': S(fn(u32) -> u64) -> S
545 57..67 'S(|i| 2*i)': S
546 59..66 '|i| 2*i': |u32| -> u64
553 81..84 'a.0': fn(u32) -> u64
557 93..96 'a.0': fn(u32) -> u64
565 fn indexing_arrays() {
567 "fn main() { &mut [9][2]; }",
569 10..26 '{ &mut...[2]; }': ()
570 12..23 '&mut [9][2]': &mut {unknown}
571 17..20 '[9]': [i32; 1]
572 17..23 '[9][2]': {unknown}
580 fn infer_ops_index() {
583 //- /main.rs crate:main deps:std
587 impl std::ops::Index<u32> for Bar {
597 //- /std.rs crate:std
598 #[prelude_import] use ops::*;
601 pub trait Index<Idx> {
610 fn infer_ops_index_int() {
613 //- /main.rs crate:main deps:std
617 impl std::ops::Index<u32> for Bar {
622 impl std::ops::Index<Range> for Bar {
633 //- /std.rs crate:std
634 #[prelude_import] use ops::*;
637 pub trait Index<Idx> {
646 fn infer_ops_index_autoderef() {
649 //- /main.rs crate:main deps:std
651 let a = &[1u32, 2, 3];
656 //- /std.rs crate:std
657 impl<T> ops::Index<u32> for [T] {
661 #[prelude_import] use ops::*;
664 pub trait Index<Idx> {
679 fn deref(&self) -> &Self::Target;
683 impl<T> Deref for Arc<T> {
689 fn foo(&self) -> u128 {}
700 fn deref_trait_with_inference_var() {
707 fn deref(&self) -> &Self::Target;
711 fn new_arc<T>() -> Arc<T> {}
712 impl<T> Deref for Arc<T> {
730 fn deref_trait_infinite_recursion() {
736 fn deref(&self) -> &Self::Target;
753 fn deref_trait_with_question_mark_size() {
759 fn deref(&self) -> &Self::Target;
763 impl<T> Deref for Arc<T> {
769 fn foo(&self) -> u128 {}
780 fn obligation_from_function_clause() {
786 impl Trait<u32> for S {}
788 fn foo<T: Trait<U>, U>(t: T) -> U {}
798 fn obligation_from_method_clause() {
805 impl Trait<isize> for S {}
809 fn foo<T: Trait<U>, U>(&self, t: T) -> U {}
820 fn obligation_from_self_method_clause() {
826 impl Trait<i64> for S {}
829 fn foo<U>(&self) -> U where Self: Trait<U> {}
840 fn obligation_from_impl_clause() {
846 impl Trait<&str> for S {}
849 impl<U, T: Trait<U>> O<T> {
850 fn foo(&self) -> U {}
861 fn generic_param_env_1() {
865 trait Trait { fn foo(self) -> u128; }
868 impl<T> Trait for T where T: Clone {}
869 fn test<T: Clone>(t: T) { t.foo(); }
876 fn generic_param_env_1_not_met() {
881 trait Trait { fn foo(self) -> u128; }
884 impl<T> Trait for T where T: Clone {}
885 fn test<T>(t: T) { t.foo(); }
892 fn generic_param_env_2() {
895 trait Trait { fn foo(self) -> u128; }
898 fn test<T: Trait>(t: T) { t.foo(); }
905 fn generic_param_env_2_not_met() {
908 trait Trait { fn foo(self) -> u128; }
911 fn test<T>(t: T) { t.foo(); }
918 fn generic_param_env_deref() {
926 impl<T> Deref for T where T: Trait {
929 fn test<T: Trait>(t: T) { (*t); }
936 fn associated_type_placeholder() {
937 // 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].
944 pub struct RefMutL<T>;
946 impl<T> ApplyL for RefMutL<T> {
947 type Out = <T as ApplyL>::Out;
950 fn test<T: ApplyL>() {
951 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
959 fn associated_type_placeholder_2() {
965 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
967 fn test<T: ApplyL>(t: T) {
976 fn argument_impl_trait() {
977 check_infer_with_mismatches(
981 fn foo2(&self) -> i64;
983 fn bar(x: impl Trait<u16>) {}
985 impl<T> Trait<T> for S<T> {}
987 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
1000 29..33 'self': &Self
1001 54..58 'self': &Self
1002 77..78 'x': impl Trait<u16>
1004 154..155 'x': impl Trait<u64>
1005 174..175 'y': &impl Trait<u32>
1006 195..323 '{ ...2(); }': ()
1007 201..202 'x': impl Trait<u64>
1008 208..209 'y': &impl Trait<u32>
1009 219..220 'z': S<u16>
1010 223..224 'S': S<u16>(u16) -> S<u16>
1011 223..227 'S(1)': S<u16>
1013 233..236 'bar': fn bar(S<u16>)
1014 233..239 'bar(z)': ()
1015 237..238 'z': S<u16>
1016 245..246 'x': impl Trait<u64>
1017 245..252 'x.foo()': u64
1018 258..259 'y': &impl Trait<u32>
1019 258..265 'y.foo()': u32
1020 271..272 'z': S<u16>
1021 271..278 'z.foo()': u16
1022 284..285 'x': impl Trait<u64>
1023 284..292 'x.foo2()': i64
1024 298..299 'y': &impl Trait<u32>
1025 298..306 'y.foo2()': i64
1026 312..313 'z': S<u16>
1027 312..320 'z.foo2()': i64
1033 fn argument_impl_trait_type_args_1() {
1034 check_infer_with_mismatches(
1038 // this function has an implicit Self param, an explicit type param,
1039 // and an implicit impl Trait param!
1040 fn bar<T>(x: impl Trait) -> T { loop {} }
1042 fn foo<T>(x: impl Trait) -> T { loop {} }
1053 <F as Foo>::bar::<u32>(S);
1057 foo::<u32, i32>(S); // we should ignore the extraneous i32
1060 155..156 'x': impl Trait
1061 175..186 '{ loop {} }': T
1062 177..184 'loop {}': !
1064 199..200 'x': impl Trait
1065 219..230 '{ loop {} }': T
1066 221..228 'loop {}': !
1068 300..509 '{ ... i32 }': ()
1069 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1070 306..317 'Foo::bar(S)': {unknown}
1072 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1073 323..341 '<F as ...bar(S)': {unknown}
1075 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1076 347..356 'F::bar(S)': {unknown}
1078 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1079 362..380 'Foo::b...32>(S)': u32
1081 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1082 386..411 '<F as ...32>(S)': u32
1084 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1085 418..424 'foo(S)': {unknown}
1087 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1088 430..443 'foo::<u32>(S)': u32
1090 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1091 449..467 'foo::<...32>(S)': u32
1098 fn argument_impl_trait_type_args_2() {
1099 check_infer_with_mismatches(
1106 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1112 F::<u32>.foo::<i32>(S);
1113 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1117 93..94 'x': impl Trait
1118 118..129 '{ loop {} }': (T, U)
1119 120..127 'loop {}': !
1121 143..283 '{ ...ored }': ()
1122 149..150 'F': F<{unknown}>
1123 149..157 'F.foo(S)': ({unknown}, {unknown})
1125 163..171 'F::<u32>': F<u32>
1126 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1128 184..192 'F::<u32>': F<u32>
1129 184..206 'F::<u3...32>(S)': (u32, i32)
1131 212..220 'F::<u32>': F<u32>
1132 212..239 'F::<u3...32>(S)': (u32, i32)
1139 fn argument_impl_trait_to_fn_pointer() {
1140 check_infer_with_mismatches(
1143 fn foo(x: impl Trait) { loop {} }
1148 let f: fn(S) -> () = foo;
1151 22..23 'x': impl Trait
1152 37..48 '{ loop {} }': ()
1155 90..123 '{ ...foo; }': ()
1157 117..120 'foo': fn foo(S)
1168 fn foo2(&self) -> i64;
1170 fn bar() -> impl Trait<u64> {}
1172 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1184 29..33 'self': &Self
1185 54..58 'self': &Self
1187 110..111 'x': impl Trait<u64>
1188 130..131 'y': &impl Trait<u64>
1189 151..268 '{ ...2(); }': ()
1190 157..158 'x': impl Trait<u64>
1191 164..165 'y': &impl Trait<u64>
1192 175..176 'z': impl Trait<u64>
1193 179..182 'bar': fn bar() -> impl Trait<u64>
1194 179..184 'bar()': impl Trait<u64>
1195 190..191 'x': impl Trait<u64>
1196 190..197 'x.foo()': u64
1197 203..204 'y': &impl Trait<u64>
1198 203..210 'y.foo()': u64
1199 216..217 'z': impl Trait<u64>
1200 216..223 'z.foo()': u64
1201 229..230 'x': impl Trait<u64>
1202 229..237 'x.foo2()': i64
1203 243..244 'y': &impl Trait<u64>
1204 243..251 'y.foo2()': i64
1205 257..258 'z': impl Trait<u64>
1206 257..265 'z.foo2()': i64
1212 fn simple_return_pos_impl_trait() {
1213 cov_mark::check!(lower_rpit);
1219 fn bar() -> impl Trait<u64> { loop {} }
1226 29..33 'self': &Self
1227 71..82 '{ loop {} }': !
1230 94..129 '{ ...o(); }': ()
1231 104..105 'a': impl Trait<u64>
1232 108..111 'bar': fn bar() -> impl Trait<u64>
1233 108..113 'bar()': impl Trait<u64>
1234 119..120 'a': impl Trait<u64>
1235 119..126 'a.foo()': u64
1241 fn more_return_pos_impl_trait() {
1246 fn next(&mut self) -> Self::Item;
1251 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1252 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1258 let (c, d) = baz(1u128);
1263 49..53 'self': &mut Self
1264 101..105 'self': &Self
1265 184..195 '{ loop {} }': ({unknown}, {unknown})
1266 186..193 'loop {}': !
1269 268..279 '{ loop {} }': ({unknown}, {unknown})
1270 270..277 'loop {}': !
1272 291..413 '{ ...o(); }': ()
1273 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1274 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1275 305..306 'b': impl Trait<u64>
1276 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1277 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1278 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1279 321..329 'a.next()': impl Trait<u32>
1280 321..335 'a.next().foo()': u32
1281 341..342 'b': impl Trait<u64>
1282 341..348 'b.foo()': u64
1283 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1284 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1285 362..363 'd': impl Trait<u128>
1286 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1287 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1288 371..376 '1u128': u128
1289 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1290 383..391 'c.next()': impl Trait<u128>
1291 383..397 'c.next().foo()': u128
1292 403..404 'd': impl Trait<u128>
1293 403..410 'd.foo()': u128
1304 fn foo2(&self) -> i64;
1306 fn bar() -> dyn Trait<u64> {}
1308 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1320 29..33 'self': &Self
1321 54..58 'self': &Self
1323 109..110 'x': dyn Trait<u64>
1324 128..129 'y': &dyn Trait<u64>
1325 148..265 '{ ...2(); }': ()
1326 154..155 'x': dyn Trait<u64>
1327 161..162 'y': &dyn Trait<u64>
1328 172..173 'z': dyn Trait<u64>
1329 176..179 'bar': fn bar() -> dyn Trait<u64>
1330 176..181 'bar()': dyn Trait<u64>
1331 187..188 'x': dyn Trait<u64>
1332 187..194 'x.foo()': u64
1333 200..201 'y': &dyn Trait<u64>
1334 200..207 'y.foo()': u64
1335 213..214 'z': dyn Trait<u64>
1336 213..220 'z.foo()': u64
1337 226..227 'x': dyn Trait<u64>
1338 226..234 'x.foo2()': i64
1339 240..241 'y': &dyn Trait<u64>
1340 240..248 'y.foo2()': i64
1341 254..255 'z': dyn Trait<u64>
1342 254..262 'z.foo2()': i64
1348 fn dyn_trait_in_impl() {
1352 fn foo(&self) -> (T, U);
1355 impl<T, U> S<T, U> {
1356 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1358 trait Trait2<T, U> {
1359 fn baz(&self) -> (T, U);
1361 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1363 fn test(s: S<u32, i32>) {
1367 32..36 'self': &Self
1368 102..106 'self': &S<T, U>
1369 128..139 '{ loop {} }': &dyn Trait<T, U>
1370 130..137 'loop {}': !
1372 175..179 'self': &Self
1373 251..252 's': S<u32, i32>
1374 267..289 '{ ...z(); }': ()
1375 273..274 's': S<u32, i32>
1376 273..280 's.bar()': &dyn Trait<u32, i32>
1377 273..286 's.bar().baz()': (u32, i32)
1383 fn dyn_trait_bare() {
1387 fn foo(&self) -> u64;
1389 fn bar() -> Trait {}
1391 fn test(x: Trait, y: &Trait) -> u64 {
1400 26..30 'self': &Self
1402 72..73 'x': dyn Trait
1403 82..83 'y': &dyn Trait
1404 100..175 '{ ...o(); }': ()
1405 106..107 'x': dyn Trait
1406 113..114 'y': &dyn Trait
1407 124..125 'z': dyn Trait
1408 128..131 'bar': fn bar() -> dyn Trait
1409 128..133 'bar()': dyn Trait
1410 139..140 'x': dyn Trait
1411 139..146 'x.foo()': u64
1412 152..153 'y': &dyn Trait
1413 152..159 'y.foo()': u64
1414 165..166 'z': dyn Trait
1415 165..172 'z.foo()': u64
1426 a: impl Trait + 'lifetime,
1429 d: impl ('lifetime),
1431 f: impl Trait + ?Sized
1435 28..29 'a': impl Trait
1437 82..83 'c': impl Trait
1440 148..149 'f': impl Trait
1448 fn error_bound_chalk() {
1452 fn foo(&self) -> u32 {}
1455 fn test(x: (impl Trait + UnknownTrait)) {
1463 fn assoc_type_bindings() {
1470 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1471 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1472 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1475 impl<T> Trait for S<T> { type Type = T; }
1477 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1495 262..263 'y': impl Trait<Type = i64>
1496 289..397 '{ ...r>); }': ()
1497 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1498 295..301 'get(x)': u32
1500 307..311 'get2': fn get2<u32, T>(T) -> u32
1501 307..314 'get2(x)': u32
1503 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1504 320..326 'get(y)': i64
1505 324..325 'y': impl Trait<Type = i64>
1506 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1507 332..339 'get2(y)': i64
1508 337..338 'y': impl Trait<Type = i64>
1509 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1510 345..356 'get(set(S))': u64
1511 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1512 349..355 'set(S)': S<u64>
1513 353..354 'S': S<u64>
1514 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1515 362..374 'get2(set(S))': u64
1516 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1517 367..373 'set(S)': S<u64>
1518 371..372 'S': S<u64>
1519 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1520 380..394 'get2(S::<str>)': str
1521 385..393 'S::<str>': S<str>
1527 fn impl_trait_assoc_binding_projection_bug() {
1530 //- /main.rs crate:main deps:std
1531 pub trait Language {
1534 pub enum RustLanguage {}
1535 impl Language for RustLanguage {
1536 type Kind = SyntaxKind;
1538 struct SyntaxNode<L> {}
1539 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1542 fn clone(&self) -> Self;
1545 fn api_walkthrough() {
1551 //- /std.rs crate:std
1552 #[prelude_import] use iter::*;
1554 trait IntoIterator {
1560 impl<T: Iterator> IntoIterator for T {
1561 type Item = <T as Iterator>::Item;
1569 fn projection_eq_within_chalk() {
1578 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1580 fn test<T: Trait1<Type = u32>>(x: T) {
1586 169..185 '{ ...o(); }': ()
1588 175..182 'x.foo()': u32
1594 fn where_clause_trait_in_scope_for_method_resolution() {
1599 fn foo(&self) -> u32 {}
1603 fn test<T: foo::Trait>(x: T) {
1611 fn super_trait_method_resolution() {
1616 fn foo(&self) -> u32 {}
1619 trait Trait1: foo::SuperTrait {}
1620 trait Trait2 where Self: foo::SuperTrait {}
1622 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1627 49..53 'self': &Self
1631 193..222 '{ ...o(); }': ()
1633 199..206 'x.foo()': u32
1635 212..219 'y.foo()': u32
1641 fn super_trait_impl_trait_method_resolution() {
1646 fn foo(&self) -> u32 {}
1649 trait Trait1: foo::SuperTrait {}
1651 fn test(x: &impl Trait1) {
1655 49..53 'self': &Self
1657 115..116 'x': &impl Trait1
1658 132..148 '{ ...o(); }': ()
1659 138..139 'x': &impl Trait1
1660 138..145 'x.foo()': u32
1666 fn super_trait_cycle() {
1667 // This just needs to not crash
1673 fn test<T: A>(x: T) {
1679 49..65 '{ ...o(); }': ()
1681 55..62 'x.foo()': {unknown}
1687 fn super_trait_assoc_type_bounds() {
1690 trait SuperTrait { type Type; }
1691 trait Trait where Self: SuperTrait {}
1693 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1694 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1697 impl<T> SuperTrait for S<T> { type Type = T; }
1698 impl<T> Trait for S<T> {}
1709 258..279 '{ ...S)); }': ()
1710 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1711 264..276 'get2(set(S))': u64
1712 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1713 269..275 'set(S)': S<u64>
1714 273..274 'S': S<u64>
1721 check_infer_with_mismatches(
1723 trait FnOnce<Args> {
1726 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1729 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1730 f.call_once((1, 2));
1736 155..183 '{ ...2)); }': ()
1738 161..180 'f.call...1, 2))': u128
1739 173..179 '(1, 2)': (u32, u64)
1747 fn fn_ptr_and_item() {
1748 check_infer_with_mismatches(
1751 trait FnOnce<Args> {
1754 fn call_once(self, args: Args) -> Self::Output;
1763 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1764 fn foo(&self) -> (A1, R) { loop {} }
1767 enum Opt<T> { None, Some(T) }
1769 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1773 let bar: Bar<fn(u8) -> u32>;
1777 let f: fn(u8) -> u32;
1783 139..143 'self': &Self
1784 243..247 'self': &Bar<F>
1785 260..271 '{ loop {} }': (A1, R)
1786 262..269 'loop {}': !
1788 355..359 'self': Opt<T>
1790 377..388 '{ loop {} }': Opt<U>
1791 379..386 'loop {}': !
1793 402..518 '{ ...(f); }': ()
1794 412..415 'bar': Bar<fn(u8) -> u32>
1795 441..444 'bar': Bar<fn(u8) -> u32>
1796 441..450 'bar.foo()': (u8, u32)
1797 461..464 'opt': Opt<u8>
1798 483..484 'f': fn(u8) -> u32
1799 505..508 'opt': Opt<u8>
1800 505..515 'opt.map(f)': Opt<u32>
1801 513..514 'f': fn(u8) -> u32
1807 fn fn_trait_deref_with_ty_default() {
1814 fn deref(&self) -> &Self::Target;
1818 trait FnOnce<Args> {
1821 fn call_once(self, args: Args) -> Self::Output;
1827 fn foo(&self) -> usize {}
1830 struct Lazy<T, F = fn() -> T>(F);
1832 impl<T, F> Lazy<T, F> {
1833 pub fn new(f: F) -> Lazy<T, F> {}
1836 impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
1841 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1842 let r1 = lazy1.foo();
1844 fn make_foo_fn() -> Foo {}
1845 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1846 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1847 let r2 = lazy2.foo();
1850 64..68 'self': &Self
1851 165..169 'self': Self
1852 171..175 'args': Args
1853 239..243 'self': &Foo
1857 443..689 '{ ...o(); }': ()
1858 453..458 'lazy1': Lazy<Foo, || -> Foo>
1859 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1860 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1861 485..491 '|| Foo': || -> Foo
1863 502..504 'r1': usize
1864 507..512 'lazy1': Lazy<Foo, || -> Foo>
1865 507..518 'lazy1.foo()': usize
1866 560..575 'make_foo_fn_ptr': fn() -> Foo
1867 591..602 'make_foo_fn': fn make_foo_fn() -> Foo
1868 612..617 'lazy2': Lazy<Foo, fn() -> Foo>
1869 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1870 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1871 644..659 'make_foo_fn_ptr': fn() -> Foo
1872 670..672 'r2': usize
1873 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1874 675..686 'lazy2.foo()': usize
1882 check_infer_with_mismatches(
1885 trait FnOnce<Args> {
1889 enum Option<T> { Some(T), None }
1891 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1895 let x = Option::Some(1u32);
1898 let y: Option<i64> = x.map(|_v| 1);
1901 147..151 'self': Option<T>
1903 172..183 '{ loop {} }': Option<U>
1904 174..181 'loop {}': !
1906 197..316 '{ ... 1); }': ()
1907 207..208 'x': Option<u32>
1908 211..223 'Option::Some': Some<u32>(u32) -> Option<u32>
1909 211..229 'Option...(1u32)': Option<u32>
1910 224..228 '1u32': u32
1911 235..236 'x': Option<u32>
1912 235..251 'x.map(...v + 1)': Option<u32>
1913 241..250 '|v| v + 1': |u32| -> u32
1916 245..250 'v + 1': u32
1918 257..258 'x': Option<u32>
1919 257..273 'x.map(... 1u64)': Option<u64>
1920 263..272 '|_v| 1u64': |u32| -> u64
1922 268..272 '1u64': u64
1923 283..284 'y': Option<i64>
1924 300..301 'x': Option<u32>
1925 300..313 'x.map(|_v| 1)': Option<i64>
1926 306..312 '|_v| 1': |u32| -> i64
1935 check_infer_with_mismatches(
1938 pub trait Add<Rhs = Self> {
1940 fn add(self, rhs: Rhs) -> Self::Output;
1943 trait FnOnce<Args> {
1949 fn add(self, rhs: u64) -> Self::Output {0}
1954 fn add(self, rhs: u128) -> Self::Output {0}
1957 fn test<F: FnOnce(u32) -> u64>(f: F) {
1961 let h = |v| 1u128 + v;
1966 203..207 'self': u64
1970 297..301 'self': u128
1971 303..306 'rhs': u128
1972 330..333 '{0}': u128
1975 374..450 '{ ...+ v; }': ()
1977 380..384 'f(1)': {unknown}
1979 394..395 'g': |u64| -> u64
1980 398..407 '|v| v + 1': |u64| -> u64
1983 402..407 'v + 1': u64
1985 413..414 'g': |u64| -> u64
1986 413..420 'g(1u64)': u64
1987 415..419 '1u64': u64
1988 430..431 'h': |u128| -> u128
1989 434..447 '|v| 1u128 + v': |u128| -> u128
1991 438..443 '1u128': u128
1992 438..447 '1u128 + v': u128
1999 fn closure_as_argument_inference_order() {
2000 check_infer_with_mismatches(
2003 trait FnOnce<Args> {
2007 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
2008 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
2012 fn method(self) -> u64;
2014 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
2015 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
2019 let x1 = foo1(S, |s| s.method());
2020 let x2 = foo2(|s| s.method(), S);
2021 let x3 = S.foo1(S, |s| s.method());
2022 let x4 = S.foo2(|s| s.method(), S);
2027 111..122 '{ loop {} }': U
2028 113..120 'loop {}': !
2032 173..184 '{ loop {} }': U
2033 175..182 'loop {}': !
2039 294..305 '{ loop {} }': U
2040 296..303 'loop {}': !
2045 366..377 '{ loop {} }': U
2046 368..375 'loop {}': !
2048 391..550 '{ ... S); }': ()
2050 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2051 406..429 'foo1(S...hod())': u64
2053 414..428 '|s| s.method()': |S| -> u64
2056 418..428 's.method()': u64
2058 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2059 444..467 'foo2(|...(), S)': u64
2060 449..463 '|s| s.method()': |S| -> u64
2063 453..463 's.method()': u64
2067 482..507 'S.foo1...hod())': u64
2069 492..506 '|s| s.method()': |S| -> u64
2072 496..506 's.method()': u64
2075 522..547 'S.foo2...(), S)': u64
2076 529..543 '|s| s.method()': |S| -> u64
2079 533..543 's.method()': u64
2086 fn fn_item_fn_trait() {
2090 trait FnOnce<Args> {
2098 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2102 } //^^^^^^^^^^^^^^^^^^ S
2108 fn unselected_projection_in_trait_env_1() {
2117 fn foo(&self) -> u32;
2120 fn test<T: Trait>() where T::Item: Trait2 {
2121 let x: T::Item = no_matter;
2129 fn unselected_projection_in_trait_env_2() {
2137 fn foo(&self) -> u32;
2140 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2141 let x: T::Item = no_matter;
2149 fn unselected_projection_on_impl_self() {
2156 fn f(&self, x: Self::Item);
2163 fn f(&self, x: Self::Item) { let y = x; }
2170 fn f(&self, x: <Self>::Item) { let y = x; }
2173 40..44 'self': &Self
2174 46..47 'x': Trait::Item<Self>
2177 147..161 '{ let y = x; }': ()
2180 228..232 'self': &S2
2182 251..265 '{ let y = x; }': ()
2190 fn unselected_projection_on_trait_self() {
2196 fn f(&self) -> Self::Item { loop {} }
2212 fn unselected_projection_chalk_fold() {
2216 trait Fold<I: Interner, TI = I> {
2220 struct Ty<I: Interner> {}
2221 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2222 type Result = Ty<TI>;
2225 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2232 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2240 fn trait_impl_self_ty() {
2249 impl Trait<Self> for S {}
2259 fn trait_impl_self_ty_cycle() {
2268 impl Trait for S<Self> {}
2278 fn unselected_projection_in_trait_env_cycle_1() {
2279 // this is a legitimate cycle
2288 fn test<T: Trait>() where T: Trait2<T::Item> {
2289 let x: T::Item = no_matter;
2296 fn unselected_projection_in_trait_env_cycle_2() {
2297 // this is a legitimate cycle
2305 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2306 let x: T::Item = no_matter;
2313 fn unselected_projection_in_trait_env_cycle_3() {
2314 // this is a cycle for rustc; we currently accept it
2323 fn test<T>() where T: Trait<OtherItem = T::Item> {
2324 let x: T::Item = no_matter;
2325 } //^ Trait::Item<T>
2331 fn unselected_projection_in_trait_env_no_cycle() {
2332 // this is not a cycle
2340 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2342 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2345 fn len(&self) -> usize;
2348 pub trait UnificationStoreMut: UnificationStoreBase {
2349 fn push(&mut self, value: Self::Key);
2352 fn test<T>(t: T) where T: UnificationStoreMut {
2357 } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2363 fn inline_assoc_type_bounds_1() {
2369 trait OtherTrait<T> {
2373 // workaround for Chalk assoc type normalization problems
2375 impl<T: Iterator> Iterator for S<T> {
2376 type Item = <T as Iterator>::Item;
2379 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2380 let x: <S<I> as Iterator>::Item;
2388 fn inline_assoc_type_bounds_2() {
2395 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2396 let x: <<I as Iterator>::Item as Iterator>::Item;
2404 fn proc_macro_server_types() {
2407 macro_rules! with_api {
2408 ($S:ident, $self:ident, $m:ident) => {
2411 fn new() -> $S::TokenStream;
2418 macro_rules! associated_item {
2419 (type TokenStream) =>
2420 (type TokenStream: 'static;);
2422 (type Group: 'static;);
2423 ($($item:tt)*) => ($($item)*;)
2425 macro_rules! declare_server_traits {
2427 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2430 $(associated_item!(type $name);)*
2433 $(pub trait $name: Types {
2434 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2437 pub trait Server: Types $(+ $name)* {}
2438 impl<S: Types $(+ $name)*> Server for S {}
2442 with_api!(Self, self_, declare_server_traits);
2446 impl Types for Rustc {
2447 type TokenStream = T;
2451 fn make<T>() -> T { loop {} }
2452 impl TokenStream for Rustc {
2453 fn new() -> Self::TokenStream {
2454 let group: Self::Group = make();
2459 1061..1072 '{ loop {} }': T
2460 1063..1070 'loop {}': !
2462 1136..1199 '{ ... }': T
2463 1150..1155 'group': G
2464 1171..1175 'make': fn make<G>() -> G
2465 1171..1177 'make()': G
2466 1187..1191 'make': fn make<T>() -> T
2467 1187..1193 'make()': T
2473 fn unify_impl_trait() {
2474 check_infer_with_mismatches(
2478 fn foo(x: impl Trait<u32>) { loop {} }
2479 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2482 impl<T> Trait<T> for S<T> {}
2484 fn default<T>() -> T { loop {} }
2486 fn test() -> impl Trait<i32> {
2487 let s1 = S(default());
2489 let x: i32 = bar(S(default()));
2493 26..27 'x': impl Trait<u32>
2494 46..57 '{ loop {} }': ()
2497 68..69 'x': impl Trait<T>
2498 91..102 '{ loop {} }': T
2499 93..100 'loop {}': !
2501 171..182 '{ loop {} }': T
2502 173..180 'loop {}': !
2504 213..309 '{ ...t()) }': S<{unknown}>
2505 223..225 's1': S<u32>
2506 228..229 'S': S<u32>(u32) -> S<u32>
2507 228..240 'S(default())': S<u32>
2508 230..237 'default': fn default<u32>() -> u32
2509 230..239 'default()': u32
2510 246..249 'foo': fn foo(S<u32>)
2511 246..253 'foo(s1)': ()
2512 250..252 's1': S<u32>
2514 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2515 272..289 'bar(S(...lt()))': i32
2516 276..277 'S': S<i32>(i32) -> S<i32>
2517 276..288 'S(default())': S<i32>
2518 278..285 'default': fn default<i32>() -> i32
2519 278..287 'default()': i32
2520 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2521 295..307 'S(default())': S<{unknown}>
2522 297..304 'default': fn default<{unknown}>() -> {unknown}
2523 297..306 'default()': {unknown}
2529 fn assoc_types_from_bounds() {
2534 trait FnOnce<Args> {
2553 f::<(), _>(|z| { z; });
2558 193..224 '{ ... }); }': ()
2559 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2560 199..221 'f::<()... z; })': ()
2561 210..220 '|z| { z; }': |&()| -> ()
2563 214..220 '{ z; }': ()
2570 fn associated_type_bound() {
2574 type Item: OtherTrait<u32>;
2576 pub trait OtherTrait<T> {
2580 // this is just a workaround for chalk#234
2582 impl<T: Trait> Trait for S<T> {
2583 type Item = <T as Trait>::Item;
2586 fn test<T: Trait>() {
2587 let y: <S<T> as Trait>::Item = no_matter;
2595 fn dyn_trait_through_chalk() {
2603 impl<T> Deref for Box<T> {
2610 fn test(x: Box<dyn Trait>) {
2618 fn string_to_owned() {
2624 fn to_owned(&self) -> Self::Owned;
2626 impl ToOwned for str {
2627 type Owned = String;
2637 fn iterator_chain() {
2638 check_infer_with_mismatches(
2642 trait FnOnce<Args> {
2646 trait FnMut<Args>: FnOnce<Args> { }
2648 enum Option<T> { Some(T), None }
2651 pub trait Iterator {
2654 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2656 F: FnMut(Self::Item) -> Option<B>,
2659 fn for_each<F>(self, f: F)
2661 F: FnMut(Self::Item),
2665 pub trait IntoIterator {
2667 type IntoIter: Iterator<Item = Self::Item>;
2668 fn into_iter(self) -> Self::IntoIter;
2671 pub struct FilterMap<I, F> { }
2672 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2674 F: FnMut(I::Item) -> Option<B>,
2679 #[stable(feature = "rust1", since = "1.0.0")]
2680 impl<I: Iterator> IntoIterator for I {
2681 type Item = I::Item;
2684 fn into_iter(self) -> I {
2691 fn new() -> Self { loop {} }
2694 impl<T> IntoIterator for Vec<T> {
2696 type IntoIter = IntoIter<T>;
2699 pub struct IntoIter<T> { }
2700 impl<T> Iterator for IntoIter<T> {
2705 Vec::<i32>::new().into_iter()
2706 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2707 .for_each(|y| { y; });
2710 226..230 'self': Self
2712 317..328 '{ loop {} }': FilterMap<Self, F>
2713 319..326 'loop {}': !
2715 349..353 'self': Self
2717 405..416 '{ loop {} }': ()
2718 407..414 'loop {}': !
2720 525..529 'self': Self
2722 865..885 '{ ... }': I
2724 944..955 '{ loop {} }': Vec<T>
2725 946..953 'loop {}': !
2727 1142..1269 '{ ... }); }': ()
2728 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2729 1148..1165 'Vec::<...:new()': Vec<i32>
2730 1148..1177 'Vec::<...iter()': IntoIter<i32>
2731 1148..1240 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2732 1148..1266 'Vec::<... y; })': ()
2733 1194..1239 '|x| if...None }': |i32| -> Option<u32>
2735 1198..1239 'if x >...None }': Option<u32>
2737 1201..1206 'x > 0': bool
2739 1207..1225 '{ Some...u32) }': Option<u32>
2740 1209..1213 'Some': Some<u32>(u32) -> Option<u32>
2741 1209..1223 'Some(x as u32)': Option<u32>
2743 1214..1222 'x as u32': u32
2744 1231..1239 '{ None }': Option<u32>
2745 1233..1237 'None': Option<u32>
2746 1255..1265 '|y| { y; }': |u32| -> ()
2748 1259..1265 '{ y; }': ()
2771 fn foo() -> Self::Output;
2775 type Output = T::OutputA;
2776 fn foo() -> Self::Output { loop {} }
2787 fn trait_object_no_coercion() {
2788 check_infer_with_mismatches(
2792 fn foo(x: &dyn Foo) {}
2794 fn test(x: &dyn Foo) {
2798 21..22 'x': &dyn Foo
2800 46..47 'x': &dyn Foo
2801 59..74 '{ foo(x); }': ()
2802 65..68 'foo': fn foo(&dyn Foo)
2804 69..70 'x': &dyn Foo
2811 check_infer_with_mismatches(
2817 impl Copy for IsCopy {}
2820 trait Test { fn test(&self) -> bool; }
2821 impl<T: Copy> Test for T {}
2826 (IsCopy, IsCopy).test();
2827 (IsCopy, NotCopy).test();
2830 110..114 'self': &Self
2831 166..267 '{ ...t(); }': ()
2832 172..178 'IsCopy': IsCopy
2833 172..185 'IsCopy.test()': bool
2834 191..198 'NotCopy': NotCopy
2835 191..205 'NotCopy.test()': {unknown}
2836 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy)
2837 211..234 '(IsCop...test()': bool
2838 212..218 'IsCopy': IsCopy
2839 220..226 'IsCopy': IsCopy
2840 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy)
2841 240..264 '(IsCop...test()': {unknown}
2842 241..247 'IsCopy': IsCopy
2843 249..256 'NotCopy': NotCopy
2849 fn builtin_fn_def_copy() {
2850 check_infer_with_mismatches(
2856 fn bar<T: Copy>(T) -> T {}
2857 struct Struct(usize);
2858 enum Enum { Variant(usize) }
2860 trait Test { fn test(&self) -> bool; }
2861 impl<T: Copy> Test for T {}
2867 Enum::Variant.test();
2871 60..61 'T': {unknown}
2873 68..70: expected T, got ()
2874 145..149 'self': &Self
2875 201..281 '{ ...t(); }': ()
2876 207..210 'foo': fn foo()
2877 207..217 'foo.test()': bool
2878 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2879 223..233 'bar.test()': bool
2880 239..245 'Struct': Struct(usize) -> Struct
2881 239..252 'Struct.test()': bool
2882 258..271 'Enum::Variant': Variant(usize) -> Enum
2883 258..278 'Enum::...test()': bool
2889 fn builtin_fn_ptr_copy() {
2890 check_infer_with_mismatches(
2895 trait Test { fn test(&self) -> bool; }
2896 impl<T: Copy> Test for T {}
2898 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2904 54..58 'self': &Self
2906 118..120 'f2': fn(usize) -> u8
2907 139..141 'f3': fn(u8, u8) -> &u8
2908 162..210 '{ ...t(); }': ()
2910 168..177 'f1.test()': bool
2911 183..185 'f2': fn(usize) -> u8
2912 183..192 'f2.test()': bool
2913 198..200 'f3': fn(u8, u8) -> &u8
2914 198..207 'f3.test()': bool
2920 fn builtin_sized() {
2921 check_infer_with_mismatches(
2926 trait Test { fn test(&self) -> bool; }
2927 impl<T: Sized> Test for T {}
2931 (*"foo").test(); // not Sized
2933 (1u8, *"foo").test(); // not Sized
2936 56..60 'self': &Self
2937 113..228 '{ ...ized }': ()
2939 119..129 '1u8.test()': bool
2940 135..150 '(*"foo").test()': {unknown}
2941 136..142 '*"foo"': str
2942 137..142 '"foo"': &str
2943 169..179 '(1u8, 1u8)': (u8, u8)
2944 169..186 '(1u8, ...test()': bool
2947 192..205 '(1u8, *"foo")': (u8, str)
2948 192..212 '(1u8, ...test()': {unknown}
2950 198..204 '*"foo"': str
2951 199..204 '"foo"': &str
2957 fn integer_range_iterate() {
2960 //- /main.rs crate:main deps:core
2962 for x in 0..100 { x; }
2965 //- /core.rs crate:core
2967 pub struct Range<Idx> {
2974 pub trait Iterator {
2978 pub trait IntoIterator {
2980 type IntoIter: Iterator<Item = Self::Item>;
2983 impl<T> IntoIterator for T where T: Iterator {
2984 type Item = <T as Iterator>::Item;
2985 type IntoIter = Self;
2990 impl Step for i32 {}
2991 impl Step for i64 {}
2993 impl<A: Step> iter::Iterator for ops::Range<A> {
3001 fn infer_closure_arg() {
3012 let s = Option::None;
3013 let f = |x: Option<i32>| {};
3017 52..126 '{ ...)(s) }': ()
3018 62..63 's': Option<i32>
3019 66..78 'Option::None': Option<i32>
3020 88..89 'f': |Option<i32>| -> ()
3021 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
3022 93..94 'x': Option<i32>
3024 117..124 '(&f)(s)': ()
3025 118..120 '&f': &|Option<i32>| -> ()
3026 119..120 'f': |Option<i32>| -> ()
3027 122..123 's': Option<i32>
3033 fn infer_fn_trait_arg() {
3034 check_infer_with_mismatches(
3036 //- /lib.rs deps:std
3039 pub trait FnOnce<Args> {
3042 extern "rust-call" fn call_once(&self, args: Args) -> Self::Output;
3046 pub trait Fn<Args>:FnOnce<Args> {
3047 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3055 fn foo<F, T>(f: F) -> T
3057 F: Fn(Option<i32>) -> T,
3064 101..105 'self': &Self
3065 107..111 'args': Args
3066 220..224 'self': &Self
3067 226..230 'args': Args
3069 359..389 '{ ...f(s) }': T
3070 369..370 's': Option<i32>
3071 373..377 'None': Option<i32>
3074 385..386 's': Option<i32>
3080 fn infer_box_fn_arg() {
3081 // The type mismatch is because we don't define Unsize and CoerceUnsized
3082 check_infer_with_mismatches(
3084 //- /lib.rs deps:std
3087 pub trait FnOnce<Args> {
3090 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3095 type Target: ?Sized;
3097 fn deref(&self) -> &Self::Target;
3100 #[lang = "owned_box"]
3101 pub struct Box<T: ?Sized> {
3105 impl<T: ?Sized> Deref for Box<T> {
3108 fn deref(&self) -> &T {
3119 let s = Option::None;
3120 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3124 100..104 'self': Self
3125 106..110 'args': Args
3126 214..218 'self': &Self
3127 384..388 'self': &Box<T>
3128 396..423 '{ ... }': &T
3129 406..417 '&self.inner': &*mut T
3130 407..411 'self': &Box<T>
3131 407..417 'self.inner': *mut T
3132 478..576 '{ ...&s); }': ()
3133 488..489 's': Option<i32>
3134 492..504 'Option::None': Option<i32>
3135 514..515 'f': Box<dyn FnOnce(&Option<i32>)>
3136 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3137 554..561 '|ps| {}': |{unknown}| -> ()
3138 555..557 'ps': {unknown}
3140 568..569 'f': Box<dyn FnOnce(&Option<i32>)>
3141 568..573 'f(&s)': ()
3142 570..572 '&s': &Option<i32>
3143 571..572 's': Option<i32>
3144 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
3150 fn infer_dyn_fn_output() {
3154 pub trait FnOnce<Args> {
3156 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3160 pub trait Fn<Args>: FnOnce<Args> {
3161 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3165 let f: &dyn Fn() -> i32;
3173 fn infer_dyn_fn_once_output() {
3177 pub trait FnOnce<Args> {
3179 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3183 let f: dyn FnOnce() -> i32;
3191 fn variable_kinds_1() {
3194 trait Trait<T> { fn get(self, t: T) -> T; }
3196 impl Trait<u128> for S {}
3197 impl Trait<f32> for S {}
3209 fn variable_kinds_2() {
3212 trait Trait { fn get(self) -> Self; }
3213 impl Trait for u128 {}
3214 impl Trait for f32 {}
3226 fn underscore_import() {
3231 fn method(&self) -> u8 { 0 }
3236 impl crate::tr::Tr for Tr {}
3238 use crate::tr::Tr as _;
3253 fn method(&self) -> u8 { 0 }
3270 fn trait_in_scope_with_inner_item() {
3275 fn method(&self) -> u8 { 0 }
3290 46..50 'self': &Self
3293 115..185 '{ ... } }': ()
3294 132..183 '{ ... }': ()
3296 142..153 '().method()': u8
3302 fn inner_use_in_block() {
3307 fn method(&self) -> u8 { 0 }
3323 //^^^^^^^^^^^ {unknown}
3327 //^^^^^^^^^^^ {unknown}
3334 fn nested_inner_function_calling_self() {
3344 17..73 '{ ... } }': ()
3345 39..71 '{ ... }': ()
3347 57..62 'inner': fn inner() -> S
3354 fn infer_default_trait_type_parameter() {
3359 trait Op<RHS=Self> {
3362 fn do_op(self, rhs: RHS) -> Self::Output;
3368 fn do_op(self, rhs: Self) -> Self::Output {
3383 186..206 '{ ... }': bool
3384 196..200 'true': bool
3385 220..277 '{ ...(y); }': ()
3392 264..274 'x.do_op(y)': bool
3399 fn qualified_path_as_qualified_trait() {
3409 fn boo() -> Self::Output {
3416 impl foo::Foo for F {
3419 impl foo::Bar for F {
3420 type Output = <F as foo::Foo>::Target;
3425 let x = <F as Bar>::boo();
3428 132..163 '{ ... }': Bar::Output<Self>
3429 146..153 'loop {}': !
3431 306..358 '{ ...o(); }': ()
3433 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3434 338..355 '<F as ...:boo()': ()
3440 fn renamed_extern_crate_in_block() {
3443 //- /lib.rs crate:lib deps:serde
3444 use serde::Deserialize;
3449 extern crate serde as _serde;
3450 impl _serde::Deserialize for Foo {
3451 fn deserialize() -> u8 { 0 }
3457 //^^^^^^^^^^^^^^^^^^ u8
3460 //- /serde.rs crate:serde
3462 pub trait Deserialize {
3463 fn deserialize() -> u8;
3469 fn bin_op_adt_with_rhs_primitive() {
3470 check_infer_with_mismatches(
3473 pub trait Add<Rhs = Self> {
3475 fn add(self, rhs: Rhs) -> Self::Output;
3478 struct Wrapper(u32);
3479 impl Add<u32> for Wrapper {
3481 fn add(self, rhs: u32) -> Wrapper {
3486 let wrapped = Wrapper(10);
3488 let res = wrapped + num;
3494 192..196 'self': Wrapper
3496 219..247 '{ ... }': Wrapper
3497 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3498 229..241 'Wrapper(rhs)': Wrapper
3500 259..345 '{ ...um; }': ()
3501 269..276 'wrapped': Wrapper
3502 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3503 279..290 'Wrapper(10)': Wrapper
3507 322..325 'res': Wrapper
3508 328..335 'wrapped': Wrapper
3509 328..341 'wrapped + num': Wrapper
3521 fn do_thing(&self) -> Self::Output;
3524 impl T for [u8; 4] {
3525 type Output = usize;
3526 fn do_thing(&self) -> Self::Output {
3531 impl T for [u8; 2] {
3533 fn do_thing(&self) -> Self::Output {
3540 let v2 = v.do_thing();
3542 let v4 = v3.do_thing();
3546 44..48 'self': &Self
3547 133..137 'self': &[u8; 4]
3548 155..172 '{ ... }': usize
3550 236..240 'self': &[u8; 2]
3551 258..275 '{ ... }': u8
3553 289..392 '{ ...g(); }': ()
3554 299..300 'v': [u8; 2]
3555 303..311 '[0u8; 2]': [u8; 2]
3559 326..327 'v': [u8; 2]
3560 326..338 'v.do_thing()': u8
3561 348..350 'v3': [u8; 4]
3562 353..361 '[0u8; 4]': [u8; 4]
3565 371..373 'v4': usize
3566 376..378 'v3': [u8; 4]
3567 376..389 'v3.do_thing()': usize
3572 // FIXME: We should infer the length of the returned array :)
3574 fn const_generics() {
3579 fn do_thing(&self) -> Self::Output;
3582 impl<const L: usize> T for [u8; L] {
3583 type Output = [u8; L];
3584 fn do_thing(&self) -> Self::Output {
3591 let v2 = v.do_thing();
3595 44..48 'self': &Self
3596 151..155 'self': &[u8; _]
3597 173..194 '{ ... }': [u8; _]
3598 183..188 '*self': [u8; _]
3599 184..188 'self': &[u8; _]
3600 208..260 '{ ...g(); }': ()
3601 218..219 'v': [u8; 2]
3602 222..230 '[0u8; 2]': [u8; 2]
3605 240..242 'v2': [u8; _]
3606 245..246 'v': [u8; 2]
3607 245..257 'v.do_thing()': [u8; _]
3613 fn fn_returning_unit() {
3614 check_infer_with_mismatches(
3617 trait FnOnce<Args> {
3621 fn test<F: FnOnce()>(f: F) {
3626 88..112 '{ ...f(); }': ()
3635 fn trait_in_scope_of_trait_impl() {
3641 fn bar(self) -> usize { 0 }
3644 impl foo::Foo for u32 {
3646 let _x = self.bar();
3653 82..87 '{ 0 }': usize
3655 131..135 'self': u32
3656 137..173 '{ ... }': ()
3657 151..153 '_x': usize
3658 156..160 'self': u32
3659 156..166 'self.bar()': usize