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
25 #[lang = "future_trait"]
39 //- /main.rs crate:main deps:core
40 async fn foo() -> u64 {
50 //- /core.rs crate:core
51 #[prelude_import] use future::*;
53 #[lang = "future_trait"]
63 fn infer_desugar_async() {
66 //- /main.rs crate:main deps:core
67 async fn foo() -> u64 {
74 } //^ impl Future<Output = u64>
76 //- /core.rs crate:core
77 #[prelude_import] use future::*;
89 fn infer_async_block() {
92 //- /main.rs crate:main deps:core
96 // ^ impl Future<Output = i32>
100 let b = async {}.await;
104 let y = Option::None;
108 let _: Option<u64> = c.await;
110 // ^ impl Future<Output = Option<u64>>
113 enum Option<T> { None, Some(T) }
115 //- /core.rs crate:core
116 #[prelude_import] use future::*;
118 #[lang = "future_trait"]
132 //- /main.rs crate:main deps:core
134 let r: Result<i32, u64> = Result::Ok(1);
139 //- /core.rs crate:core
148 pub enum Result<O, E> {
153 impl<O, E> crate::ops::Try for Result<O, E> {
161 pub use crate::{result::*, ops::*};
169 fn infer_try_trait_v2() {
172 //- /main.rs crate:main deps:core
174 let r: Result<i32, u64> = Result::Ok(1);
179 //- /core.rs crate:core
182 pub trait Try: FromResidual {
186 pub trait FromResidual<R = <Self as Try>::Residual> {}
189 pub use self::try_trait::FromResidual;
190 pub use self::try_trait::Try;
195 impl<T> From<T> for T {}
199 use crate::convert::From;
200 use crate::ops::{Try, FromResidual};
202 pub enum Infallible {}
203 pub enum Result<O, E> {
208 impl<O, E> Try for Result<O, E> {
210 type Error = Result<Infallible, E>;
213 impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
218 pub use crate::result::*;
226 fn infer_for_loop() {
229 //- /main.rs crate:main deps:core,alloc
231 use alloc::collections::Vec;
241 //- /core.rs crate:core
243 pub trait IntoIterator {
249 pub use crate::iter::*;
253 //- /alloc.rs crate:alloc deps:core
258 pub fn new() -> Self { Vec {} }
259 pub fn push(&mut self, t: T) { }
262 impl<T> IntoIterator for Vec<T> {
274 //- /main.rs crate:main deps:std
278 impl std::ops::Neg for Bar {
288 //- /std.rs crate:std
289 #[prelude_import] use ops::*;
304 //- /main.rs crate:main deps:std
308 impl std::ops::Not for Bar {
318 //- /std.rs crate:std
319 #[prelude_import] use ops::*;
331 fn infer_from_bound_1() {
336 impl<U> Trait<U> for S<U> {}
337 fn foo<T: Trait<u32>>(t: T) {}
345 104..143 '{ ...(s); }': ()
347 118..119 'S': S<u32>(u32) -> S<u32>
348 118..128 'S(unknown)': S<u32>
349 120..127 'unknown': u32
350 134..137 'foo': fn foo<S<u32>>(S<u32>)
351 134..140 'foo(s)': ()
358 fn infer_from_bound_2() {
363 impl<U> Trait<U> for S<U> {}
364 fn foo<U, T: Trait<U>>(t: T) -> U {}
372 110..162 '{ ...(s); }': ()
374 124..125 'S': S<u32>(u32) -> S<u32>
375 124..134 'S(unknown)': S<u32>
376 126..133 'unknown': u32
378 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32
379 153..159 'foo(s)': u32
386 fn trait_default_method_self_bound_implements_trait() {
387 cov_mark::check!(trait_self_implements_self);
391 fn foo(&self) -> i64;
402 79..89 'self.foo()': i64
408 fn trait_default_method_self_bound_implements_super_trait() {
412 fn foo(&self) -> i64;
414 trait Trait: SuperTrait {
422 94..129 '{ ... }': ()
424 112..116 'self': &Self
425 112..122 'self.foo()': i64
431 fn infer_project_associated_type() {
438 impl Iterable for S { type Item = u32; }
439 fn test<T: Iterable>() {
440 let x: <S as Iterable>::Item = 1;
441 let y: <T as Iterable>::Item = no_matter;
442 let z: T::Item = no_matter;
443 let a: <T>::Item = no_matter;
446 108..261 '{ ...ter; }': ()
449 156..157 'y': Iterable::Item<T>
450 183..192 'no_matter': Iterable::Item<T>
451 202..203 'z': Iterable::Item<T>
452 215..224 'no_matter': Iterable::Item<T>
453 234..235 'a': Iterable::Item<T>
454 249..258 'no_matter': Iterable::Item<T>
460 fn infer_return_associated_type() {
467 impl Iterable for S { type Item = u32; }
468 fn foo1<T: Iterable>(t: T) -> T::Item {}
469 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {}
470 fn foo3<T: Iterable>(t: T) -> <T>::Item {}
483 234..300 '{ ...(S); }': ()
485 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item
486 248..255 'foo1(S)': u32
489 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item
490 269..276 'foo2(S)': u32
493 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item
494 290..297 'foo3(S)': u32
501 fn infer_associated_type_bound() {
507 fn test<T: Iterable<Item=u32>>() {
508 let y: T::Item = unknown;
511 67..100 '{ ...own; }': ()
513 90..97 'unknown': u32
519 fn infer_const_body() {
522 const A: u32 = 1 + 1;
523 static B: u64 = { let x = 1; x };"#,
528 38..54 '{ let ...1; x }': u64
537 fn tuple_struct_fields() {
547 37..86 '{ ... a.1 }': u64
549 51..52 'S': S(i32, u64) -> S
563 fn tuple_struct_with_fn() {
566 struct S(fn(u32) -> u64);
573 43..101 '{ ...0(2) }': u64
575 57..58 'S': S(fn(u32) -> u64) -> S
576 57..67 'S(|i| 2*i)': S
577 59..66 '|i| 2*i': |u32| -> u64
584 81..84 'a.0': fn(u32) -> u64
588 93..96 'a.0': fn(u32) -> u64
596 fn indexing_arrays() {
598 "fn main() { &mut [9][2]; }",
600 10..26 '{ &mut...[2]; }': ()
601 12..23 '&mut [9][2]': &mut {unknown}
602 17..20 '[9]': [i32; 1]
603 17..23 '[9][2]': {unknown}
611 fn infer_ops_index() {
614 //- /main.rs crate:main deps:std
618 impl std::ops::Index<u32> for Bar {
628 //- /std.rs crate:std
629 #[prelude_import] use ops::*;
632 pub trait Index<Idx> {
641 fn infer_ops_index_int() {
644 //- /main.rs crate:main deps:std
648 impl std::ops::Index<u32> for Bar {
653 impl std::ops::Index<Range> for Bar {
664 //- /std.rs crate:std
665 #[prelude_import] use ops::*;
668 pub trait Index<Idx> {
677 fn infer_ops_index_autoderef() {
680 //- /main.rs crate:main deps:std
682 let a = &[1u32, 2, 3];
687 //- /std.rs crate:std
688 impl<T> ops::Index<u32> for [T] {
692 #[prelude_import] use ops::*;
695 pub trait Index<Idx> {
710 fn deref(&self) -> &Self::Target;
714 impl<T> Deref for Arc<T> {
720 fn foo(&self) -> u128 {}
731 fn deref_trait_with_inference_var() {
738 fn deref(&self) -> &Self::Target;
742 fn new_arc<T>() -> Arc<T> {}
743 impl<T> Deref for Arc<T> {
761 fn deref_trait_infinite_recursion() {
767 fn deref(&self) -> &Self::Target;
784 fn deref_trait_with_question_mark_size() {
790 fn deref(&self) -> &Self::Target;
794 impl<T> Deref for Arc<T> {
800 fn foo(&self) -> u128 {}
811 fn obligation_from_function_clause() {
817 impl Trait<u32> for S {}
819 fn foo<T: Trait<U>, U>(t: T) -> U {}
829 fn obligation_from_method_clause() {
836 impl Trait<isize> for S {}
840 fn foo<T: Trait<U>, U>(&self, t: T) -> U {}
851 fn obligation_from_self_method_clause() {
857 impl Trait<i64> for S {}
860 fn foo<U>(&self) -> U where Self: Trait<U> {}
871 fn obligation_from_impl_clause() {
877 impl Trait<&str> for S {}
880 impl<U, T: Trait<U>> O<T> {
881 fn foo(&self) -> U {}
892 fn generic_param_env_1() {
896 trait Trait { fn foo(self) -> u128; }
899 impl<T> Trait for T where T: Clone {}
900 fn test<T: Clone>(t: T) { t.foo(); }
907 fn generic_param_env_1_not_met() {
912 trait Trait { fn foo(self) -> u128; }
915 impl<T> Trait for T where T: Clone {}
916 fn test<T>(t: T) { t.foo(); }
923 fn generic_param_env_2() {
926 trait Trait { fn foo(self) -> u128; }
929 fn test<T: Trait>(t: T) { t.foo(); }
936 fn generic_param_env_2_not_met() {
939 trait Trait { fn foo(self) -> u128; }
942 fn test<T>(t: T) { t.foo(); }
949 fn generic_param_env_deref() {
957 impl<T> Deref for T where T: Trait {
960 fn test<T: Trait>(t: T) { (*t); }
967 fn associated_type_placeholder() {
968 // 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].
975 pub struct RefMutL<T>;
977 impl<T> ApplyL for RefMutL<T> {
978 type Out = <T as ApplyL>::Out;
981 fn test<T: ApplyL>() {
982 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
990 fn associated_type_placeholder_2() {
996 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
998 fn test<T: ApplyL>(t: T) {
1001 } //^ ApplyL::Out<T>
1007 fn argument_impl_trait() {
1008 check_infer_with_mismatches(
1012 fn foo2(&self) -> i64;
1014 fn bar(x: impl Trait<u16>) {}
1016 impl<T> Trait<T> for S<T> {}
1018 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
1031 29..33 'self': &Self
1032 54..58 'self': &Self
1033 77..78 'x': impl Trait<u16>
1035 154..155 'x': impl Trait<u64>
1036 174..175 'y': &impl Trait<u32>
1037 195..323 '{ ...2(); }': ()
1038 201..202 'x': impl Trait<u64>
1039 208..209 'y': &impl Trait<u32>
1040 219..220 'z': S<u16>
1041 223..224 'S': S<u16>(u16) -> S<u16>
1042 223..227 'S(1)': S<u16>
1044 233..236 'bar': fn bar(S<u16>)
1045 233..239 'bar(z)': ()
1046 237..238 'z': S<u16>
1047 245..246 'x': impl Trait<u64>
1048 245..252 'x.foo()': u64
1049 258..259 'y': &impl Trait<u32>
1050 258..265 'y.foo()': u32
1051 271..272 'z': S<u16>
1052 271..278 'z.foo()': u16
1053 284..285 'x': impl Trait<u64>
1054 284..292 'x.foo2()': i64
1055 298..299 'y': &impl Trait<u32>
1056 298..306 'y.foo2()': i64
1057 312..313 'z': S<u16>
1058 312..320 'z.foo2()': i64
1064 fn argument_impl_trait_type_args_1() {
1065 check_infer_with_mismatches(
1069 // this function has an implicit Self param, an explicit type param,
1070 // and an implicit impl Trait param!
1071 fn bar<T>(x: impl Trait) -> T { loop {} }
1073 fn foo<T>(x: impl Trait) -> T { loop {} }
1084 <F as Foo>::bar::<u32>(S);
1088 foo::<u32, i32>(S); // we should ignore the extraneous i32
1091 155..156 'x': impl Trait
1092 175..186 '{ loop {} }': T
1093 177..184 'loop {}': !
1095 199..200 'x': impl Trait
1096 219..230 '{ loop {} }': T
1097 221..228 'loop {}': !
1099 300..509 '{ ... i32 }': ()
1100 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1101 306..317 'Foo::bar(S)': {unknown}
1103 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1104 323..341 '<F as ...bar(S)': {unknown}
1106 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1107 347..356 'F::bar(S)': {unknown}
1109 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1110 362..380 'Foo::b...32>(S)': u32
1112 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1113 386..411 '<F as ...32>(S)': u32
1115 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1116 418..424 'foo(S)': {unknown}
1118 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1119 430..443 'foo::<u32>(S)': u32
1121 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1122 449..467 'foo::<...32>(S)': u32
1129 fn argument_impl_trait_type_args_2() {
1130 check_infer_with_mismatches(
1137 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1143 F::<u32>.foo::<i32>(S);
1144 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1148 93..94 'x': impl Trait
1149 118..129 '{ loop {} }': (T, U)
1150 120..127 'loop {}': !
1152 143..283 '{ ...ored }': ()
1153 149..150 'F': F<{unknown}>
1154 149..157 'F.foo(S)': ({unknown}, {unknown})
1156 163..171 'F::<u32>': F<u32>
1157 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1159 184..192 'F::<u32>': F<u32>
1160 184..206 'F::<u3...32>(S)': (u32, i32)
1162 212..220 'F::<u32>': F<u32>
1163 212..239 'F::<u3...32>(S)': (u32, i32)
1170 fn argument_impl_trait_to_fn_pointer() {
1171 check_infer_with_mismatches(
1174 fn foo(x: impl Trait) { loop {} }
1179 let f: fn(S) -> () = foo;
1182 22..23 'x': impl Trait
1183 37..48 '{ loop {} }': ()
1186 90..123 '{ ...foo; }': ()
1188 117..120 'foo': fn foo(S)
1199 fn foo2(&self) -> i64;
1201 fn bar() -> impl Trait<u64> {}
1203 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1215 29..33 'self': &Self
1216 54..58 'self': &Self
1218 110..111 'x': impl Trait<u64>
1219 130..131 'y': &impl Trait<u64>
1220 151..268 '{ ...2(); }': ()
1221 157..158 'x': impl Trait<u64>
1222 164..165 'y': &impl Trait<u64>
1223 175..176 'z': impl Trait<u64>
1224 179..182 'bar': fn bar() -> impl Trait<u64>
1225 179..184 'bar()': impl Trait<u64>
1226 190..191 'x': impl Trait<u64>
1227 190..197 'x.foo()': u64
1228 203..204 'y': &impl Trait<u64>
1229 203..210 'y.foo()': u64
1230 216..217 'z': impl Trait<u64>
1231 216..223 'z.foo()': u64
1232 229..230 'x': impl Trait<u64>
1233 229..237 'x.foo2()': i64
1234 243..244 'y': &impl Trait<u64>
1235 243..251 'y.foo2()': i64
1236 257..258 'z': impl Trait<u64>
1237 257..265 'z.foo2()': i64
1243 fn simple_return_pos_impl_trait() {
1244 cov_mark::check!(lower_rpit);
1250 fn bar() -> impl Trait<u64> { loop {} }
1257 29..33 'self': &Self
1258 71..82 '{ loop {} }': !
1261 94..129 '{ ...o(); }': ()
1262 104..105 'a': impl Trait<u64>
1263 108..111 'bar': fn bar() -> impl Trait<u64>
1264 108..113 'bar()': impl Trait<u64>
1265 119..120 'a': impl Trait<u64>
1266 119..126 'a.foo()': u64
1272 fn more_return_pos_impl_trait() {
1277 fn next(&mut self) -> Self::Item;
1282 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1283 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1289 let (c, d) = baz(1u128);
1294 49..53 'self': &mut Self
1295 101..105 'self': &Self
1296 184..195 '{ loop {} }': ({unknown}, {unknown})
1297 186..193 'loop {}': !
1300 268..279 '{ loop {} }': ({unknown}, {unknown})
1301 270..277 'loop {}': !
1303 291..413 '{ ...o(); }': ()
1304 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1305 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1306 305..306 'b': impl Trait<u64>
1307 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1308 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1309 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1310 321..329 'a.next()': impl Trait<u32>
1311 321..335 'a.next().foo()': u32
1312 341..342 'b': impl Trait<u64>
1313 341..348 'b.foo()': u64
1314 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1315 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1316 362..363 'd': impl Trait<u128>
1317 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1318 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1319 371..376 '1u128': u128
1320 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1321 383..391 'c.next()': impl Trait<u128>
1322 383..397 'c.next().foo()': u128
1323 403..404 'd': impl Trait<u128>
1324 403..410 'd.foo()': u128
1335 fn foo2(&self) -> i64;
1337 fn bar() -> dyn Trait<u64> {}
1339 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1351 29..33 'self': &Self
1352 54..58 'self': &Self
1354 109..110 'x': dyn Trait<u64>
1355 128..129 'y': &dyn Trait<u64>
1356 148..265 '{ ...2(); }': ()
1357 154..155 'x': dyn Trait<u64>
1358 161..162 'y': &dyn Trait<u64>
1359 172..173 'z': dyn Trait<u64>
1360 176..179 'bar': fn bar() -> dyn Trait<u64>
1361 176..181 'bar()': dyn Trait<u64>
1362 187..188 'x': dyn Trait<u64>
1363 187..194 'x.foo()': u64
1364 200..201 'y': &dyn Trait<u64>
1365 200..207 'y.foo()': u64
1366 213..214 'z': dyn Trait<u64>
1367 213..220 'z.foo()': u64
1368 226..227 'x': dyn Trait<u64>
1369 226..234 'x.foo2()': i64
1370 240..241 'y': &dyn Trait<u64>
1371 240..248 'y.foo2()': i64
1372 254..255 'z': dyn Trait<u64>
1373 254..262 'z.foo2()': i64
1379 fn dyn_trait_in_impl() {
1383 fn foo(&self) -> (T, U);
1386 impl<T, U> S<T, U> {
1387 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1389 trait Trait2<T, U> {
1390 fn baz(&self) -> (T, U);
1392 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1394 fn test(s: S<u32, i32>) {
1398 32..36 'self': &Self
1399 102..106 'self': &S<T, U>
1400 128..139 '{ loop {} }': &dyn Trait<T, U>
1401 130..137 'loop {}': !
1403 175..179 'self': &Self
1404 251..252 's': S<u32, i32>
1405 267..289 '{ ...z(); }': ()
1406 273..274 's': S<u32, i32>
1407 273..280 's.bar()': &dyn Trait<u32, i32>
1408 273..286 's.bar().baz()': (u32, i32)
1414 fn dyn_trait_bare() {
1418 fn foo(&self) -> u64;
1420 fn bar() -> Trait {}
1422 fn test(x: Trait, y: &Trait) -> u64 {
1431 26..30 'self': &Self
1433 72..73 'x': dyn Trait
1434 82..83 'y': &dyn Trait
1435 100..175 '{ ...o(); }': ()
1436 106..107 'x': dyn Trait
1437 113..114 'y': &dyn Trait
1438 124..125 'z': dyn Trait
1439 128..131 'bar': fn bar() -> dyn Trait
1440 128..133 'bar()': dyn Trait
1441 139..140 'x': dyn Trait
1442 139..146 'x.foo()': u64
1443 152..153 'y': &dyn Trait
1444 152..159 'y.foo()': u64
1445 165..166 'z': dyn Trait
1446 165..172 'z.foo()': u64
1457 a: impl Trait + 'lifetime,
1460 d: impl ('lifetime),
1462 f: impl Trait + ?Sized
1466 28..29 'a': impl Trait
1468 82..83 'c': impl Trait
1471 148..149 'f': impl Trait
1478 fn error_bound_chalk() {
1482 fn foo(&self) -> u32 {}
1485 fn test(x: (impl Trait + UnknownTrait)) {
1493 fn assoc_type_bindings() {
1500 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1501 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1502 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1505 impl<T> Trait for S<T> { type Type = T; }
1507 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1525 262..263 'y': impl Trait<Type = i64>
1526 289..397 '{ ...r>); }': ()
1527 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1528 295..301 'get(x)': u32
1530 307..311 'get2': fn get2<u32, T>(T) -> u32
1531 307..314 'get2(x)': u32
1533 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1534 320..326 'get(y)': i64
1535 324..325 'y': impl Trait<Type = i64>
1536 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1537 332..339 'get2(y)': i64
1538 337..338 'y': impl Trait<Type = i64>
1539 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1540 345..356 'get(set(S))': u64
1541 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1542 349..355 'set(S)': S<u64>
1543 353..354 'S': S<u64>
1544 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1545 362..374 'get2(set(S))': u64
1546 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1547 367..373 'set(S)': S<u64>
1548 371..372 'S': S<u64>
1549 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1550 380..394 'get2(S::<str>)': str
1551 385..393 'S::<str>': S<str>
1557 fn impl_trait_assoc_binding_projection_bug() {
1560 //- /main.rs crate:main deps:std
1561 pub trait Language {
1564 pub enum RustLanguage {}
1565 impl Language for RustLanguage {
1566 type Kind = SyntaxKind;
1568 struct SyntaxNode<L> {}
1569 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1572 fn clone(&self) -> Self;
1575 fn api_walkthrough() {
1581 //- /std.rs crate:std
1582 #[prelude_import] use iter::*;
1584 trait IntoIterator {
1590 impl<T: Iterator> IntoIterator for T {
1591 type Item = <T as Iterator>::Item;
1599 fn projection_eq_within_chalk() {
1608 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1610 fn test<T: Trait1<Type = u32>>(x: T) {
1616 169..185 '{ ...o(); }': ()
1618 175..182 'x.foo()': u32
1624 fn where_clause_trait_in_scope_for_method_resolution() {
1629 fn foo(&self) -> u32 {}
1633 fn test<T: foo::Trait>(x: T) {
1641 fn super_trait_method_resolution() {
1646 fn foo(&self) -> u32 {}
1649 trait Trait1: foo::SuperTrait {}
1650 trait Trait2 where Self: foo::SuperTrait {}
1652 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1657 49..53 'self': &Self
1661 193..222 '{ ...o(); }': ()
1663 199..206 'x.foo()': u32
1665 212..219 'y.foo()': u32
1671 fn super_trait_impl_trait_method_resolution() {
1676 fn foo(&self) -> u32 {}
1679 trait Trait1: foo::SuperTrait {}
1681 fn test(x: &impl Trait1) {
1685 49..53 'self': &Self
1687 115..116 'x': &impl Trait1
1688 132..148 '{ ...o(); }': ()
1689 138..139 'x': &impl Trait1
1690 138..145 'x.foo()': u32
1696 fn super_trait_cycle() {
1697 // This just needs to not crash
1703 fn test<T: A>(x: T) {
1709 49..65 '{ ...o(); }': ()
1711 55..62 'x.foo()': {unknown}
1717 fn super_trait_assoc_type_bounds() {
1720 trait SuperTrait { type Type; }
1721 trait Trait where Self: SuperTrait {}
1723 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1724 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1727 impl<T> SuperTrait for S<T> { type Type = T; }
1728 impl<T> Trait for S<T> {}
1739 258..279 '{ ...S)); }': ()
1740 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1741 264..276 'get2(set(S))': u64
1742 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1743 269..275 'set(S)': S<u64>
1744 273..274 'S': S<u64>
1751 check_infer_with_mismatches(
1753 trait FnOnce<Args> {
1756 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1759 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1760 f.call_once((1, 2));
1766 155..183 '{ ...2)); }': ()
1768 161..180 'f.call...1, 2))': u128
1769 173..179 '(1, 2)': (u32, u64)
1777 fn fn_ptr_and_item() {
1778 check_infer_with_mismatches(
1781 trait FnOnce<Args> {
1784 fn call_once(self, args: Args) -> Self::Output;
1793 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1794 fn foo(&self) -> (A1, R) { loop {} }
1797 enum Opt<T> { None, Some(T) }
1799 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1803 let bar: Bar<fn(u8) -> u32>;
1807 let f: fn(u8) -> u32;
1813 139..143 'self': &Self
1814 243..247 'self': &Bar<F>
1815 260..271 '{ loop {} }': (A1, R)
1816 262..269 'loop {}': !
1818 355..359 'self': Opt<T>
1820 377..388 '{ loop {} }': Opt<U>
1821 379..386 'loop {}': !
1823 402..518 '{ ...(f); }': ()
1824 412..415 'bar': Bar<fn(u8) -> u32>
1825 441..444 'bar': Bar<fn(u8) -> u32>
1826 441..450 'bar.foo()': (u8, u32)
1827 461..464 'opt': Opt<u8>
1828 483..484 'f': fn(u8) -> u32
1829 505..508 'opt': Opt<u8>
1830 505..515 'opt.map(f)': Opt<u32>
1831 513..514 'f': fn(u8) -> u32
1837 fn fn_trait_deref_with_ty_default() {
1844 fn deref(&self) -> &Self::Target;
1848 trait FnOnce<Args> {
1851 fn call_once(self, args: Args) -> Self::Output;
1857 fn foo(&self) -> usize {}
1860 struct Lazy<T, F = fn() -> T>(F);
1862 impl<T, F> Lazy<T, F> {
1863 pub fn new(f: F) -> Lazy<T, F> {}
1866 impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
1871 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1872 let r1 = lazy1.foo();
1874 fn make_foo_fn() -> Foo {}
1875 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1876 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1877 let r2 = lazy2.foo();
1880 64..68 'self': &Self
1881 165..169 'self': Self
1882 171..175 'args': Args
1883 239..243 'self': &Foo
1887 443..689 '{ ...o(); }': ()
1888 453..458 'lazy1': Lazy<Foo, || -> Foo>
1889 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1890 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1891 485..491 '|| Foo': || -> Foo
1893 502..504 'r1': usize
1894 507..512 'lazy1': Lazy<Foo, || -> Foo>
1895 507..518 'lazy1.foo()': usize
1896 560..575 'make_foo_fn_ptr': fn() -> Foo
1897 591..602 'make_foo_fn': fn make_foo_fn() -> Foo
1898 612..617 'lazy2': Lazy<Foo, fn() -> Foo>
1899 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1900 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1901 644..659 'make_foo_fn_ptr': fn() -> Foo
1902 670..672 'r2': usize
1903 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1904 675..686 'lazy2.foo()': usize
1912 check_infer_with_mismatches(
1915 trait FnOnce<Args> {
1919 enum Option<T> { Some(T), None }
1921 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1925 let x = Option::Some(1u32);
1928 let y: Option<i64> = x.map(|_v| 1);
1931 147..151 'self': Option<T>
1933 172..183 '{ loop {} }': Option<U>
1934 174..181 'loop {}': !
1936 197..316 '{ ... 1); }': ()
1937 207..208 'x': Option<u32>
1938 211..223 'Option::Some': Some<u32>(u32) -> Option<u32>
1939 211..229 'Option...(1u32)': Option<u32>
1940 224..228 '1u32': u32
1941 235..236 'x': Option<u32>
1942 235..251 'x.map(...v + 1)': Option<u32>
1943 241..250 '|v| v + 1': |u32| -> u32
1946 245..250 'v + 1': u32
1948 257..258 'x': Option<u32>
1949 257..273 'x.map(... 1u64)': Option<u64>
1950 263..272 '|_v| 1u64': |u32| -> u64
1952 268..272 '1u64': u64
1953 283..284 'y': Option<i64>
1954 300..301 'x': Option<u32>
1955 300..313 'x.map(|_v| 1)': Option<i64>
1956 306..312 '|_v| 1': |u32| -> i64
1965 check_infer_with_mismatches(
1968 pub trait Add<Rhs = Self> {
1970 fn add(self, rhs: Rhs) -> Self::Output;
1973 trait FnOnce<Args> {
1979 fn add(self, rhs: u64) -> Self::Output {0}
1984 fn add(self, rhs: u128) -> Self::Output {0}
1987 fn test<F: FnOnce(u32) -> u64>(f: F) {
1991 let h = |v| 1u128 + v;
1996 203..207 'self': u64
2000 297..301 'self': u128
2001 303..306 'rhs': u128
2002 330..333 '{0}': u128
2005 374..450 '{ ...+ v; }': ()
2007 380..384 'f(1)': {unknown}
2009 394..395 'g': |u64| -> u64
2010 398..407 '|v| v + 1': |u64| -> u64
2013 402..407 'v + 1': u64
2015 413..414 'g': |u64| -> u64
2016 413..420 'g(1u64)': u64
2017 415..419 '1u64': u64
2018 430..431 'h': |u128| -> u128
2019 434..447 '|v| 1u128 + v': |u128| -> u128
2021 438..443 '1u128': u128
2022 438..447 '1u128 + v': u128
2029 fn closure_as_argument_inference_order() {
2030 check_infer_with_mismatches(
2033 trait FnOnce<Args> {
2037 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
2038 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
2042 fn method(self) -> u64;
2044 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
2045 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
2049 let x1 = foo1(S, |s| s.method());
2050 let x2 = foo2(|s| s.method(), S);
2051 let x3 = S.foo1(S, |s| s.method());
2052 let x4 = S.foo2(|s| s.method(), S);
2057 111..122 '{ loop {} }': U
2058 113..120 'loop {}': !
2062 173..184 '{ loop {} }': U
2063 175..182 'loop {}': !
2069 294..305 '{ loop {} }': U
2070 296..303 'loop {}': !
2075 366..377 '{ loop {} }': U
2076 368..375 'loop {}': !
2078 391..550 '{ ... S); }': ()
2080 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2081 406..429 'foo1(S...hod())': u64
2083 414..428 '|s| s.method()': |S| -> u64
2086 418..428 's.method()': u64
2088 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2089 444..467 'foo2(|...(), S)': u64
2090 449..463 '|s| s.method()': |S| -> u64
2093 453..463 's.method()': u64
2097 482..507 'S.foo1...hod())': u64
2099 492..506 '|s| s.method()': |S| -> u64
2102 496..506 's.method()': u64
2105 522..547 'S.foo2...(), S)': u64
2106 529..543 '|s| s.method()': |S| -> u64
2109 533..543 's.method()': u64
2116 fn fn_item_fn_trait() {
2120 trait FnOnce<Args> {
2128 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2132 } //^^^^^^^^^^^^^^^^^^ S
2138 fn unselected_projection_in_trait_env_1() {
2147 fn foo(&self) -> u32;
2150 fn test<T: Trait>() where T::Item: Trait2 {
2151 let x: T::Item = no_matter;
2159 fn unselected_projection_in_trait_env_2() {
2167 fn foo(&self) -> u32;
2170 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2171 let x: T::Item = no_matter;
2179 fn unselected_projection_on_impl_self() {
2186 fn f(&self, x: Self::Item);
2193 fn f(&self, x: Self::Item) { let y = x; }
2200 fn f(&self, x: <Self>::Item) { let y = x; }
2203 40..44 'self': &Self
2204 46..47 'x': Trait::Item<Self>
2207 147..161 '{ let y = x; }': ()
2210 228..232 'self': &S2
2212 251..265 '{ let y = x; }': ()
2220 fn unselected_projection_on_trait_self() {
2226 fn f(&self) -> Self::Item { loop {} }
2242 fn unselected_projection_chalk_fold() {
2246 trait Fold<I: Interner, TI = I> {
2250 struct Ty<I: Interner> {}
2251 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2252 type Result = Ty<TI>;
2255 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2262 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2270 fn trait_impl_self_ty() {
2279 impl Trait<Self> for S {}
2289 fn trait_impl_self_ty_cycle() {
2298 impl Trait for S<Self> {}
2308 fn unselected_projection_in_trait_env_cycle_1() {
2309 // this is a legitimate cycle
2318 fn test<T: Trait>() where T: Trait2<T::Item> {
2319 let x: T::Item = no_matter;
2326 fn unselected_projection_in_trait_env_cycle_2() {
2327 // this is a legitimate cycle
2335 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2336 let x: T::Item = no_matter;
2343 fn unselected_projection_in_trait_env_cycle_3() {
2344 // this is a cycle for rustc; we currently accept it
2353 fn test<T>() where T: Trait<OtherItem = T::Item> {
2354 let x: T::Item = no_matter;
2355 } //^ Trait::Item<T>
2361 fn unselected_projection_in_trait_env_no_cycle() {
2362 // this is not a cycle
2370 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2372 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2375 fn len(&self) -> usize;
2378 pub trait UnificationStoreMut: UnificationStoreBase {
2379 fn push(&mut self, value: Self::Key);
2382 fn test<T>(t: T) where T: UnificationStoreMut {
2387 } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2393 fn inline_assoc_type_bounds_1() {
2399 trait OtherTrait<T> {
2403 // workaround for Chalk assoc type normalization problems
2405 impl<T: Iterator> Iterator for S<T> {
2406 type Item = <T as Iterator>::Item;
2409 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2410 let x: <S<I> as Iterator>::Item;
2418 fn inline_assoc_type_bounds_2() {
2425 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2426 let x: <<I as Iterator>::Item as Iterator>::Item;
2434 fn proc_macro_server_types() {
2437 macro_rules! with_api {
2438 ($S:ident, $self:ident, $m:ident) => {
2441 fn new() -> $S::TokenStream;
2448 macro_rules! associated_item {
2449 (type TokenStream) =>
2450 (type TokenStream: 'static;);
2452 (type Group: 'static;);
2453 ($($item:tt)*) => ($($item)*;)
2455 macro_rules! declare_server_traits {
2457 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2460 $(associated_item!(type $name);)*
2463 $(pub trait $name: Types {
2464 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2467 pub trait Server: Types $(+ $name)* {}
2468 impl<S: Types $(+ $name)*> Server for S {}
2472 with_api!(Self, self_, declare_server_traits);
2476 impl Types for Rustc {
2477 type TokenStream = T;
2481 fn make<T>() -> T { loop {} }
2482 impl TokenStream for Rustc {
2483 fn new() -> Self::TokenStream {
2484 let group: Self::Group = make();
2489 1061..1072 '{ loop {} }': T
2490 1063..1070 'loop {}': !
2492 1136..1199 '{ ... }': T
2493 1150..1155 'group': G
2494 1171..1175 'make': fn make<G>() -> G
2495 1171..1177 'make()': G
2496 1187..1191 'make': fn make<T>() -> T
2497 1187..1193 'make()': T
2503 fn unify_impl_trait() {
2504 check_infer_with_mismatches(
2508 fn foo(x: impl Trait<u32>) { loop {} }
2509 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2512 impl<T> Trait<T> for S<T> {}
2514 fn default<T>() -> T { loop {} }
2516 fn test() -> impl Trait<i32> {
2517 let s1 = S(default());
2519 let x: i32 = bar(S(default()));
2523 26..27 'x': impl Trait<u32>
2524 46..57 '{ loop {} }': ()
2527 68..69 'x': impl Trait<T>
2528 91..102 '{ loop {} }': T
2529 93..100 'loop {}': !
2531 171..182 '{ loop {} }': T
2532 173..180 'loop {}': !
2534 213..309 '{ ...t()) }': S<{unknown}>
2535 223..225 's1': S<u32>
2536 228..229 'S': S<u32>(u32) -> S<u32>
2537 228..240 'S(default())': S<u32>
2538 230..237 'default': fn default<u32>() -> u32
2539 230..239 'default()': u32
2540 246..249 'foo': fn foo(S<u32>)
2541 246..253 'foo(s1)': ()
2542 250..252 's1': S<u32>
2544 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2545 272..289 'bar(S(...lt()))': i32
2546 276..277 'S': S<i32>(i32) -> S<i32>
2547 276..288 'S(default())': S<i32>
2548 278..285 'default': fn default<i32>() -> i32
2549 278..287 'default()': i32
2550 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2551 295..307 'S(default())': S<{unknown}>
2552 297..304 'default': fn default<{unknown}>() -> {unknown}
2553 297..306 'default()': {unknown}
2559 fn assoc_types_from_bounds() {
2564 trait FnOnce<Args> {
2583 f::<(), _>(|z| { z; });
2588 193..224 '{ ... }); }': ()
2589 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2590 199..221 'f::<()... z; })': ()
2591 210..220 '|z| { z; }': |&()| -> ()
2593 214..220 '{ z; }': ()
2600 fn associated_type_bound() {
2604 type Item: OtherTrait<u32>;
2606 pub trait OtherTrait<T> {
2610 // this is just a workaround for chalk#234
2612 impl<T: Trait> Trait for S<T> {
2613 type Item = <T as Trait>::Item;
2616 fn test<T: Trait>() {
2617 let y: <S<T> as Trait>::Item = no_matter;
2625 fn dyn_trait_through_chalk() {
2633 impl<T> Deref for Box<T> {
2640 fn test(x: Box<dyn Trait>) {
2648 fn string_to_owned() {
2654 fn to_owned(&self) -> Self::Owned;
2656 impl ToOwned for str {
2657 type Owned = String;
2667 fn iterator_chain() {
2668 check_infer_with_mismatches(
2672 trait FnOnce<Args> {
2676 trait FnMut<Args>: FnOnce<Args> { }
2678 enum Option<T> { Some(T), None }
2681 pub trait Iterator {
2684 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2686 F: FnMut(Self::Item) -> Option<B>,
2689 fn for_each<F>(self, f: F)
2691 F: FnMut(Self::Item),
2695 pub trait IntoIterator {
2697 type IntoIter: Iterator<Item = Self::Item>;
2698 fn into_iter(self) -> Self::IntoIter;
2701 pub struct FilterMap<I, F> { }
2702 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2704 F: FnMut(I::Item) -> Option<B>,
2709 #[stable(feature = "rust1", since = "1.0.0")]
2710 impl<I: Iterator> IntoIterator for I {
2711 type Item = I::Item;
2714 fn into_iter(self) -> I {
2721 fn new() -> Self { loop {} }
2724 impl<T> IntoIterator for Vec<T> {
2726 type IntoIter = IntoIter<T>;
2729 pub struct IntoIter<T> { }
2730 impl<T> Iterator for IntoIter<T> {
2735 Vec::<i32>::new().into_iter()
2736 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2737 .for_each(|y| { y; });
2740 226..230 'self': Self
2742 317..328 '{ loop {} }': FilterMap<Self, F>
2743 319..326 'loop {}': !
2745 349..353 'self': Self
2747 405..416 '{ loop {} }': ()
2748 407..414 'loop {}': !
2750 525..529 'self': Self
2752 865..885 '{ ... }': I
2754 944..955 '{ loop {} }': Vec<T>
2755 946..953 'loop {}': !
2757 1142..1269 '{ ... }); }': ()
2758 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2759 1148..1165 'Vec::<...:new()': Vec<i32>
2760 1148..1177 'Vec::<...iter()': IntoIter<i32>
2761 1148..1240 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2762 1148..1266 'Vec::<... y; })': ()
2763 1194..1239 '|x| if...None }': |i32| -> Option<u32>
2765 1198..1239 'if x >...None }': Option<u32>
2767 1201..1206 'x > 0': bool
2769 1207..1225 '{ Some...u32) }': Option<u32>
2770 1209..1213 'Some': Some<u32>(u32) -> Option<u32>
2771 1209..1223 'Some(x as u32)': Option<u32>
2773 1214..1222 'x as u32': u32
2774 1231..1239 '{ None }': Option<u32>
2775 1233..1237 'None': Option<u32>
2776 1255..1265 '|y| { y; }': |u32| -> ()
2778 1259..1265 '{ y; }': ()
2801 fn foo() -> Self::Output;
2805 type Output = T::OutputA;
2806 fn foo() -> Self::Output { loop {} }
2817 fn trait_object_no_coercion() {
2818 check_infer_with_mismatches(
2822 fn foo(x: &dyn Foo) {}
2824 fn test(x: &dyn Foo) {
2828 21..22 'x': &dyn Foo
2830 46..47 'x': &dyn Foo
2831 59..74 '{ foo(x); }': ()
2832 65..68 'foo': fn foo(&dyn Foo)
2834 69..70 'x': &dyn Foo
2841 check_infer_with_mismatches(
2847 impl Copy for IsCopy {}
2850 trait Test { fn test(&self) -> bool; }
2851 impl<T: Copy> Test for T {}
2856 (IsCopy, IsCopy).test();
2857 (IsCopy, NotCopy).test();
2860 110..114 'self': &Self
2861 166..267 '{ ...t(); }': ()
2862 172..178 'IsCopy': IsCopy
2863 172..185 'IsCopy.test()': bool
2864 191..198 'NotCopy': NotCopy
2865 191..205 'NotCopy.test()': {unknown}
2866 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy)
2867 211..234 '(IsCop...test()': bool
2868 212..218 'IsCopy': IsCopy
2869 220..226 'IsCopy': IsCopy
2870 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy)
2871 240..264 '(IsCop...test()': {unknown}
2872 241..247 'IsCopy': IsCopy
2873 249..256 'NotCopy': NotCopy
2879 fn builtin_fn_def_copy() {
2880 check_infer_with_mismatches(
2886 fn bar<T: Copy>(T) -> T {}
2887 struct Struct(usize);
2888 enum Enum { Variant(usize) }
2890 trait Test { fn test(&self) -> bool; }
2891 impl<T: Copy> Test for T {}
2897 Enum::Variant.test();
2901 60..61 'T': {unknown}
2903 68..70: expected T, got ()
2904 145..149 'self': &Self
2905 201..281 '{ ...t(); }': ()
2906 207..210 'foo': fn foo()
2907 207..217 'foo.test()': bool
2908 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2909 223..233 'bar.test()': bool
2910 239..245 'Struct': Struct(usize) -> Struct
2911 239..252 'Struct.test()': bool
2912 258..271 'Enum::Variant': Variant(usize) -> Enum
2913 258..278 'Enum::...test()': bool
2919 fn builtin_fn_ptr_copy() {
2920 check_infer_with_mismatches(
2925 trait Test { fn test(&self) -> bool; }
2926 impl<T: Copy> Test for T {}
2928 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2934 54..58 'self': &Self
2936 118..120 'f2': fn(usize) -> u8
2937 139..141 'f3': fn(u8, u8) -> &u8
2938 162..210 '{ ...t(); }': ()
2940 168..177 'f1.test()': bool
2941 183..185 'f2': fn(usize) -> u8
2942 183..192 'f2.test()': bool
2943 198..200 'f3': fn(u8, u8) -> &u8
2944 198..207 'f3.test()': bool
2950 fn builtin_sized() {
2951 check_infer_with_mismatches(
2956 trait Test { fn test(&self) -> bool; }
2957 impl<T: Sized> Test for T {}
2961 (*"foo").test(); // not Sized
2963 (1u8, *"foo").test(); // not Sized
2966 56..60 'self': &Self
2967 113..228 '{ ...ized }': ()
2969 119..129 '1u8.test()': bool
2970 135..150 '(*"foo").test()': {unknown}
2971 136..142 '*"foo"': str
2972 137..142 '"foo"': &str
2973 169..179 '(1u8, 1u8)': (u8, u8)
2974 169..186 '(1u8, ...test()': bool
2977 192..205 '(1u8, *"foo")': (u8, str)
2978 192..212 '(1u8, ...test()': {unknown}
2980 198..204 '*"foo"': str
2981 199..204 '"foo"': &str
2987 fn integer_range_iterate() {
2990 //- /main.rs crate:main deps:core
2992 for x in 0..100 { x; }
2995 //- /core.rs crate:core
2997 pub struct Range<Idx> {
3004 pub trait Iterator {
3008 pub trait IntoIterator {
3010 type IntoIter: Iterator<Item = Self::Item>;
3013 impl<T> IntoIterator for T where T: Iterator {
3014 type Item = <T as Iterator>::Item;
3015 type IntoIter = Self;
3020 impl Step for i32 {}
3021 impl Step for i64 {}
3023 impl<A: Step> iter::Iterator for ops::Range<A> {
3031 fn infer_closure_arg() {
3042 let s = Option::None;
3043 let f = |x: Option<i32>| {};
3047 52..126 '{ ...)(s) }': ()
3048 62..63 's': Option<i32>
3049 66..78 'Option::None': Option<i32>
3050 88..89 'f': |Option<i32>| -> ()
3051 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
3052 93..94 'x': Option<i32>
3054 117..124 '(&f)(s)': ()
3055 118..120 '&f': &|Option<i32>| -> ()
3056 119..120 'f': |Option<i32>| -> ()
3057 122..123 's': Option<i32>
3063 fn infer_fn_trait_arg() {
3064 check_infer_with_mismatches(
3066 //- /lib.rs deps:std
3069 pub trait FnOnce<Args> {
3072 extern "rust-call" fn call_once(&self, args: Args) -> Self::Output;
3076 pub trait Fn<Args>:FnOnce<Args> {
3077 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3085 fn foo<F, T>(f: F) -> T
3087 F: Fn(Option<i32>) -> T,
3094 101..105 'self': &Self
3095 107..111 'args': Args
3096 220..224 'self': &Self
3097 226..230 'args': Args
3099 359..389 '{ ...f(s) }': T
3100 369..370 's': Option<i32>
3101 373..377 'None': Option<i32>
3104 385..386 's': Option<i32>
3110 fn infer_box_fn_arg() {
3111 // The type mismatch is because we don't define Unsize and CoerceUnsized
3112 check_infer_with_mismatches(
3114 //- /lib.rs deps:std
3117 pub trait FnOnce<Args> {
3120 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3125 type Target: ?Sized;
3127 fn deref(&self) -> &Self::Target;
3130 #[lang = "owned_box"]
3131 pub struct Box<T: ?Sized> {
3135 impl<T: ?Sized> Deref for Box<T> {
3138 fn deref(&self) -> &T {
3149 let s = Option::None;
3150 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3154 100..104 'self': Self
3155 106..110 'args': Args
3156 214..218 'self': &Self
3157 384..388 'self': &Box<T>
3158 396..423 '{ ... }': &T
3159 406..417 '&self.inner': &*mut T
3160 407..411 'self': &Box<T>
3161 407..417 'self.inner': *mut T
3162 478..576 '{ ...&s); }': ()
3163 488..489 's': Option<i32>
3164 492..504 'Option::None': Option<i32>
3165 514..515 'f': Box<dyn FnOnce(&Option<i32>)>
3166 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3167 554..561 '|ps| {}': |{unknown}| -> ()
3168 555..557 'ps': {unknown}
3170 568..569 'f': Box<dyn FnOnce(&Option<i32>)>
3171 568..573 'f(&s)': ()
3172 570..572 '&s': &Option<i32>
3173 571..572 's': Option<i32>
3174 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
3180 fn infer_dyn_fn_output() {
3184 pub trait FnOnce<Args> {
3186 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3190 pub trait Fn<Args>: FnOnce<Args> {
3191 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3195 let f: &dyn Fn() -> i32;
3203 fn infer_dyn_fn_once_output() {
3207 pub trait FnOnce<Args> {
3209 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3213 let f: dyn FnOnce() -> i32;
3221 fn variable_kinds_1() {
3224 trait Trait<T> { fn get(self, t: T) -> T; }
3226 impl Trait<u128> for S {}
3227 impl Trait<f32> for S {}
3239 fn variable_kinds_2() {
3242 trait Trait { fn get(self) -> Self; }
3243 impl Trait for u128 {}
3244 impl Trait for f32 {}
3256 fn underscore_import() {
3261 fn method(&self) -> u8 { 0 }
3266 impl crate::tr::Tr for Tr {}
3268 use crate::tr::Tr as _;
3283 fn method(&self) -> u8 { 0 }
3300 fn trait_in_scope_with_inner_item() {
3305 fn method(&self) -> u8 { 0 }
3320 46..50 'self': &Self
3323 115..185 '{ ... } }': ()
3324 132..183 '{ ... }': ()
3326 142..153 '().method()': u8
3332 fn inner_use_in_block() {
3337 fn method(&self) -> u8 { 0 }
3353 //^^^^^^^^^^^ {unknown}
3357 //^^^^^^^^^^^ {unknown}
3364 fn nested_inner_function_calling_self() {
3374 17..73 '{ ... } }': ()
3375 39..71 '{ ... }': ()
3377 57..62 'inner': fn inner() -> S
3384 fn infer_default_trait_type_parameter() {
3389 trait Op<RHS=Self> {
3392 fn do_op(self, rhs: RHS) -> Self::Output;
3398 fn do_op(self, rhs: Self) -> Self::Output {
3413 186..206 '{ ... }': bool
3414 196..200 'true': bool
3415 220..277 '{ ...(y); }': ()
3422 264..274 'x.do_op(y)': bool
3429 fn qualified_path_as_qualified_trait() {
3439 fn boo() -> Self::Output {
3446 impl foo::Foo for F {
3449 impl foo::Bar for F {
3450 type Output = <F as foo::Foo>::Target;
3455 let x = <F as Bar>::boo();
3458 132..163 '{ ... }': Bar::Output<Self>
3459 146..153 'loop {}': !
3461 306..358 '{ ...o(); }': ()
3463 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3464 338..355 '<F as ...:boo()': ()
3470 fn renamed_extern_crate_in_block() {
3473 //- /lib.rs crate:lib deps:serde
3474 use serde::Deserialize;
3479 extern crate serde as _serde;
3480 impl _serde::Deserialize for Foo {
3481 fn deserialize() -> u8 { 0 }
3487 //^^^^^^^^^^^^^^^^^^ u8
3490 //- /serde.rs crate:serde
3492 pub trait Deserialize {
3493 fn deserialize() -> u8;
3499 fn bin_op_adt_with_rhs_primitive() {
3500 check_infer_with_mismatches(
3503 pub trait Add<Rhs = Self> {
3505 fn add(self, rhs: Rhs) -> Self::Output;
3508 struct Wrapper(u32);
3509 impl Add<u32> for Wrapper {
3511 fn add(self, rhs: u32) -> Wrapper {
3516 let wrapped = Wrapper(10);
3518 let res = wrapped + num;
3524 192..196 'self': Wrapper
3526 219..247 '{ ... }': Wrapper
3527 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3528 229..241 'Wrapper(rhs)': Wrapper
3530 259..345 '{ ...um; }': ()
3531 269..276 'wrapped': Wrapper
3532 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3533 279..290 'Wrapper(10)': Wrapper
3537 322..325 'res': Wrapper
3538 328..335 'wrapped': Wrapper
3539 328..341 'wrapped + num': Wrapper
3551 fn do_thing(&self) -> Self::Output;
3554 impl T for [u8; 4] {
3555 type Output = usize;
3556 fn do_thing(&self) -> Self::Output {
3561 impl T for [u8; 2] {
3563 fn do_thing(&self) -> Self::Output {
3570 let v2 = v.do_thing();
3572 let v4 = v3.do_thing();
3576 44..48 'self': &Self
3577 133..137 'self': &[u8; 4]
3578 155..172 '{ ... }': usize
3580 236..240 'self': &[u8; 2]
3581 258..275 '{ ... }': u8
3583 289..392 '{ ...g(); }': ()
3584 299..300 'v': [u8; 2]
3585 303..311 '[0u8; 2]': [u8; 2]
3589 326..327 'v': [u8; 2]
3590 326..338 'v.do_thing()': u8
3591 348..350 'v3': [u8; 4]
3592 353..361 '[0u8; 4]': [u8; 4]
3595 371..373 'v4': usize
3596 376..378 'v3': [u8; 4]
3597 376..389 'v3.do_thing()': usize
3602 // FIXME: We should infer the length of the returned array :)
3604 fn const_generics() {
3609 fn do_thing(&self) -> Self::Output;
3612 impl<const L: usize> T for [u8; L] {
3613 type Output = [u8; L];
3614 fn do_thing(&self) -> Self::Output {
3621 let v2 = v.do_thing();
3625 44..48 'self': &Self
3626 151..155 'self': &[u8; _]
3627 173..194 '{ ... }': [u8; _]
3628 183..188 '*self': [u8; _]
3629 184..188 'self': &[u8; _]
3630 208..260 '{ ...g(); }': ()
3631 218..219 'v': [u8; 2]
3632 222..230 '[0u8; 2]': [u8; 2]
3635 240..242 'v2': [u8; _]
3636 245..246 'v': [u8; 2]
3637 245..257 'v.do_thing()': [u8; _]
3643 fn fn_returning_unit() {
3644 check_infer_with_mismatches(
3647 trait FnOnce<Args> {
3651 fn test<F: FnOnce()>(f: F) {
3656 88..112 '{ ...f(); }': ()
3665 fn trait_in_scope_of_trait_impl() {
3671 fn bar(self) -> usize { 0 }
3674 impl foo::Foo for u32 {
3676 let _x = self.bar();
3683 82..87 '{ 0 }': usize
3685 131..135 'self': u32
3686 137..173 '{ ... }': ()
3687 151..153 '_x': usize
3688 156..160 'self': u32
3689 156..166 'self.bar()': usize
3695 fn infer_async_ret_type() {
3698 //- /main.rs crate:main deps:core
3711 fn collect<B: Convert>(self) -> B {
3719 impl Convert for u32 {
3725 async fn get_accounts() -> Result<u32, ()> {
3726 let ret = Fooey.collect();
3731 //- /core.rs crate:core
3732 #[prelude_import] use future::*;
3734 #[lang = "future_trait"]
3753 impl Trait<u32> for S {
3774 impl Trait<u32> for S {
3798 impl Trait<S1> for S2 {
3799 fn foo(&self) { S1 }