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
1479 fn error_bound_chalk() {
1483 fn foo(&self) -> u32 {}
1486 fn test(x: (impl Trait + UnknownTrait)) {
1494 fn assoc_type_bindings() {
1501 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1502 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1503 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1506 impl<T> Trait for S<T> { type Type = T; }
1508 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1526 262..263 'y': impl Trait<Type = i64>
1527 289..397 '{ ...r>); }': ()
1528 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1529 295..301 'get(x)': u32
1531 307..311 'get2': fn get2<u32, T>(T) -> u32
1532 307..314 'get2(x)': u32
1534 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1535 320..326 'get(y)': i64
1536 324..325 'y': impl Trait<Type = i64>
1537 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1538 332..339 'get2(y)': i64
1539 337..338 'y': impl Trait<Type = i64>
1540 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1541 345..356 'get(set(S))': u64
1542 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1543 349..355 'set(S)': S<u64>
1544 353..354 'S': S<u64>
1545 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1546 362..374 'get2(set(S))': u64
1547 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1548 367..373 'set(S)': S<u64>
1549 371..372 'S': S<u64>
1550 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1551 380..394 'get2(S::<str>)': str
1552 385..393 'S::<str>': S<str>
1558 fn impl_trait_assoc_binding_projection_bug() {
1561 //- /main.rs crate:main deps:std
1562 pub trait Language {
1565 pub enum RustLanguage {}
1566 impl Language for RustLanguage {
1567 type Kind = SyntaxKind;
1569 struct SyntaxNode<L> {}
1570 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1573 fn clone(&self) -> Self;
1576 fn api_walkthrough() {
1582 //- /std.rs crate:std
1583 #[prelude_import] use iter::*;
1585 trait IntoIterator {
1591 impl<T: Iterator> IntoIterator for T {
1592 type Item = <T as Iterator>::Item;
1600 fn projection_eq_within_chalk() {
1609 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1611 fn test<T: Trait1<Type = u32>>(x: T) {
1617 169..185 '{ ...o(); }': ()
1619 175..182 'x.foo()': u32
1625 fn where_clause_trait_in_scope_for_method_resolution() {
1630 fn foo(&self) -> u32 {}
1634 fn test<T: foo::Trait>(x: T) {
1642 fn super_trait_method_resolution() {
1647 fn foo(&self) -> u32 {}
1650 trait Trait1: foo::SuperTrait {}
1651 trait Trait2 where Self: foo::SuperTrait {}
1653 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1658 49..53 'self': &Self
1662 193..222 '{ ...o(); }': ()
1664 199..206 'x.foo()': u32
1666 212..219 'y.foo()': u32
1672 fn super_trait_impl_trait_method_resolution() {
1677 fn foo(&self) -> u32 {}
1680 trait Trait1: foo::SuperTrait {}
1682 fn test(x: &impl Trait1) {
1686 49..53 'self': &Self
1688 115..116 'x': &impl Trait1
1689 132..148 '{ ...o(); }': ()
1690 138..139 'x': &impl Trait1
1691 138..145 'x.foo()': u32
1697 fn super_trait_cycle() {
1698 // This just needs to not crash
1704 fn test<T: A>(x: T) {
1710 49..65 '{ ...o(); }': ()
1712 55..62 'x.foo()': {unknown}
1718 fn super_trait_assoc_type_bounds() {
1721 trait SuperTrait { type Type; }
1722 trait Trait where Self: SuperTrait {}
1724 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1725 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1728 impl<T> SuperTrait for S<T> { type Type = T; }
1729 impl<T> Trait for S<T> {}
1740 258..279 '{ ...S)); }': ()
1741 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1742 264..276 'get2(set(S))': u64
1743 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1744 269..275 'set(S)': S<u64>
1745 273..274 'S': S<u64>
1752 check_infer_with_mismatches(
1754 trait FnOnce<Args> {
1757 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1760 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1761 f.call_once((1, 2));
1767 155..183 '{ ...2)); }': ()
1769 161..180 'f.call...1, 2))': u128
1770 173..179 '(1, 2)': (u32, u64)
1778 fn fn_ptr_and_item() {
1779 check_infer_with_mismatches(
1782 trait FnOnce<Args> {
1785 fn call_once(self, args: Args) -> Self::Output;
1794 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1795 fn foo(&self) -> (A1, R) { loop {} }
1798 enum Opt<T> { None, Some(T) }
1800 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1804 let bar: Bar<fn(u8) -> u32>;
1808 let f: fn(u8) -> u32;
1814 139..143 'self': &Self
1815 243..247 'self': &Bar<F>
1816 260..271 '{ loop {} }': (A1, R)
1817 262..269 'loop {}': !
1819 355..359 'self': Opt<T>
1821 377..388 '{ loop {} }': Opt<U>
1822 379..386 'loop {}': !
1824 402..518 '{ ...(f); }': ()
1825 412..415 'bar': Bar<fn(u8) -> u32>
1826 441..444 'bar': Bar<fn(u8) -> u32>
1827 441..450 'bar.foo()': (u8, u32)
1828 461..464 'opt': Opt<u8>
1829 483..484 'f': fn(u8) -> u32
1830 505..508 'opt': Opt<u8>
1831 505..515 'opt.map(f)': Opt<u32>
1832 513..514 'f': fn(u8) -> u32
1838 fn fn_trait_deref_with_ty_default() {
1845 fn deref(&self) -> &Self::Target;
1849 trait FnOnce<Args> {
1852 fn call_once(self, args: Args) -> Self::Output;
1858 fn foo(&self) -> usize {}
1861 struct Lazy<T, F = fn() -> T>(F);
1863 impl<T, F> Lazy<T, F> {
1864 pub fn new(f: F) -> Lazy<T, F> {}
1867 impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
1872 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1873 let r1 = lazy1.foo();
1875 fn make_foo_fn() -> Foo {}
1876 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1877 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1878 let r2 = lazy2.foo();
1881 64..68 'self': &Self
1882 165..169 'self': Self
1883 171..175 'args': Args
1884 239..243 'self': &Foo
1888 443..689 '{ ...o(); }': ()
1889 453..458 'lazy1': Lazy<Foo, || -> Foo>
1890 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1891 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1892 485..491 '|| Foo': || -> Foo
1894 502..504 'r1': usize
1895 507..512 'lazy1': Lazy<Foo, || -> Foo>
1896 507..518 'lazy1.foo()': usize
1897 560..575 'make_foo_fn_ptr': fn() -> Foo
1898 591..602 'make_foo_fn': fn make_foo_fn() -> Foo
1899 612..617 'lazy2': Lazy<Foo, fn() -> Foo>
1900 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1901 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1902 644..659 'make_foo_fn_ptr': fn() -> Foo
1903 670..672 'r2': usize
1904 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1905 675..686 'lazy2.foo()': usize
1913 check_infer_with_mismatches(
1916 trait FnOnce<Args> {
1920 enum Option<T> { Some(T), None }
1922 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1926 let x = Option::Some(1u32);
1929 let y: Option<i64> = x.map(|_v| 1);
1932 147..151 'self': Option<T>
1934 172..183 '{ loop {} }': Option<U>
1935 174..181 'loop {}': !
1937 197..316 '{ ... 1); }': ()
1938 207..208 'x': Option<u32>
1939 211..223 'Option::Some': Some<u32>(u32) -> Option<u32>
1940 211..229 'Option...(1u32)': Option<u32>
1941 224..228 '1u32': u32
1942 235..236 'x': Option<u32>
1943 235..251 'x.map(...v + 1)': Option<u32>
1944 241..250 '|v| v + 1': |u32| -> u32
1947 245..250 'v + 1': u32
1949 257..258 'x': Option<u32>
1950 257..273 'x.map(... 1u64)': Option<u64>
1951 263..272 '|_v| 1u64': |u32| -> u64
1953 268..272 '1u64': u64
1954 283..284 'y': Option<i64>
1955 300..301 'x': Option<u32>
1956 300..313 'x.map(|_v| 1)': Option<i64>
1957 306..312 '|_v| 1': |u32| -> i64
1966 check_infer_with_mismatches(
1969 pub trait Add<Rhs = Self> {
1971 fn add(self, rhs: Rhs) -> Self::Output;
1974 trait FnOnce<Args> {
1980 fn add(self, rhs: u64) -> Self::Output {0}
1985 fn add(self, rhs: u128) -> Self::Output {0}
1988 fn test<F: FnOnce(u32) -> u64>(f: F) {
1992 let h = |v| 1u128 + v;
1997 203..207 'self': u64
2001 297..301 'self': u128
2002 303..306 'rhs': u128
2003 330..333 '{0}': u128
2006 374..450 '{ ...+ v; }': ()
2008 380..384 'f(1)': {unknown}
2010 394..395 'g': |u64| -> u64
2011 398..407 '|v| v + 1': |u64| -> u64
2014 402..407 'v + 1': u64
2016 413..414 'g': |u64| -> u64
2017 413..420 'g(1u64)': u64
2018 415..419 '1u64': u64
2019 430..431 'h': |u128| -> u128
2020 434..447 '|v| 1u128 + v': |u128| -> u128
2022 438..443 '1u128': u128
2023 438..447 '1u128 + v': u128
2030 fn closure_as_argument_inference_order() {
2031 check_infer_with_mismatches(
2034 trait FnOnce<Args> {
2038 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
2039 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
2043 fn method(self) -> u64;
2045 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
2046 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
2050 let x1 = foo1(S, |s| s.method());
2051 let x2 = foo2(|s| s.method(), S);
2052 let x3 = S.foo1(S, |s| s.method());
2053 let x4 = S.foo2(|s| s.method(), S);
2058 111..122 '{ loop {} }': U
2059 113..120 'loop {}': !
2063 173..184 '{ loop {} }': U
2064 175..182 'loop {}': !
2070 294..305 '{ loop {} }': U
2071 296..303 'loop {}': !
2076 366..377 '{ loop {} }': U
2077 368..375 'loop {}': !
2079 391..550 '{ ... S); }': ()
2081 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2082 406..429 'foo1(S...hod())': u64
2084 414..428 '|s| s.method()': |S| -> u64
2087 418..428 's.method()': u64
2089 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2090 444..467 'foo2(|...(), S)': u64
2091 449..463 '|s| s.method()': |S| -> u64
2094 453..463 's.method()': u64
2098 482..507 'S.foo1...hod())': u64
2100 492..506 '|s| s.method()': |S| -> u64
2103 496..506 's.method()': u64
2106 522..547 'S.foo2...(), S)': u64
2107 529..543 '|s| s.method()': |S| -> u64
2110 533..543 's.method()': u64
2117 fn fn_item_fn_trait() {
2121 trait FnOnce<Args> {
2129 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2133 } //^^^^^^^^^^^^^^^^^^ S
2139 fn unselected_projection_in_trait_env_1() {
2148 fn foo(&self) -> u32;
2151 fn test<T: Trait>() where T::Item: Trait2 {
2152 let x: T::Item = no_matter;
2160 fn unselected_projection_in_trait_env_2() {
2168 fn foo(&self) -> u32;
2171 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2172 let x: T::Item = no_matter;
2180 fn unselected_projection_on_impl_self() {
2187 fn f(&self, x: Self::Item);
2194 fn f(&self, x: Self::Item) { let y = x; }
2201 fn f(&self, x: <Self>::Item) { let y = x; }
2204 40..44 'self': &Self
2205 46..47 'x': Trait::Item<Self>
2208 147..161 '{ let y = x; }': ()
2211 228..232 'self': &S2
2213 251..265 '{ let y = x; }': ()
2221 fn unselected_projection_on_trait_self() {
2227 fn f(&self) -> Self::Item { loop {} }
2243 fn unselected_projection_chalk_fold() {
2247 trait Fold<I: Interner, TI = I> {
2251 struct Ty<I: Interner> {}
2252 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2253 type Result = Ty<TI>;
2256 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2263 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2271 fn trait_impl_self_ty() {
2280 impl Trait<Self> for S {}
2290 fn trait_impl_self_ty_cycle() {
2299 impl Trait for S<Self> {}
2309 fn unselected_projection_in_trait_env_cycle_1() {
2310 // this is a legitimate cycle
2319 fn test<T: Trait>() where T: Trait2<T::Item> {
2320 let x: T::Item = no_matter;
2327 fn unselected_projection_in_trait_env_cycle_2() {
2328 // this is a legitimate cycle
2336 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2337 let x: T::Item = no_matter;
2344 fn unselected_projection_in_trait_env_cycle_3() {
2345 // this is a cycle for rustc; we currently accept it
2354 fn test<T>() where T: Trait<OtherItem = T::Item> {
2355 let x: T::Item = no_matter;
2356 } //^ Trait::Item<T>
2362 fn unselected_projection_in_trait_env_no_cycle() {
2363 // this is not a cycle
2371 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2373 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2376 fn len(&self) -> usize;
2379 pub trait UnificationStoreMut: UnificationStoreBase {
2380 fn push(&mut self, value: Self::Key);
2383 fn test<T>(t: T) where T: UnificationStoreMut {
2388 } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2394 fn inline_assoc_type_bounds_1() {
2400 trait OtherTrait<T> {
2404 // workaround for Chalk assoc type normalization problems
2406 impl<T: Iterator> Iterator for S<T> {
2407 type Item = <T as Iterator>::Item;
2410 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2411 let x: <S<I> as Iterator>::Item;
2419 fn inline_assoc_type_bounds_2() {
2426 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2427 let x: <<I as Iterator>::Item as Iterator>::Item;
2435 fn proc_macro_server_types() {
2438 macro_rules! with_api {
2439 ($S:ident, $self:ident, $m:ident) => {
2442 fn new() -> $S::TokenStream;
2449 macro_rules! associated_item {
2450 (type TokenStream) =>
2451 (type TokenStream: 'static;);
2453 (type Group: 'static;);
2454 ($($item:tt)*) => ($($item)*;)
2456 macro_rules! declare_server_traits {
2458 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2461 $(associated_item!(type $name);)*
2464 $(pub trait $name: Types {
2465 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2468 pub trait Server: Types $(+ $name)* {}
2469 impl<S: Types $(+ $name)*> Server for S {}
2473 with_api!(Self, self_, declare_server_traits);
2477 impl Types for Rustc {
2478 type TokenStream = T;
2482 fn make<T>() -> T { loop {} }
2483 impl TokenStream for Rustc {
2484 fn new() -> Self::TokenStream {
2485 let group: Self::Group = make();
2490 1061..1072 '{ loop {} }': T
2491 1063..1070 'loop {}': !
2493 1136..1199 '{ ... }': T
2494 1150..1155 'group': G
2495 1171..1175 'make': fn make<G>() -> G
2496 1171..1177 'make()': G
2497 1187..1191 'make': fn make<T>() -> T
2498 1187..1193 'make()': T
2504 fn unify_impl_trait() {
2505 check_infer_with_mismatches(
2509 fn foo(x: impl Trait<u32>) { loop {} }
2510 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2513 impl<T> Trait<T> for S<T> {}
2515 fn default<T>() -> T { loop {} }
2517 fn test() -> impl Trait<i32> {
2518 let s1 = S(default());
2520 let x: i32 = bar(S(default()));
2524 26..27 'x': impl Trait<u32>
2525 46..57 '{ loop {} }': ()
2528 68..69 'x': impl Trait<T>
2529 91..102 '{ loop {} }': T
2530 93..100 'loop {}': !
2532 171..182 '{ loop {} }': T
2533 173..180 'loop {}': !
2535 213..309 '{ ...t()) }': S<{unknown}>
2536 223..225 's1': S<u32>
2537 228..229 'S': S<u32>(u32) -> S<u32>
2538 228..240 'S(default())': S<u32>
2539 230..237 'default': fn default<u32>() -> u32
2540 230..239 'default()': u32
2541 246..249 'foo': fn foo(S<u32>)
2542 246..253 'foo(s1)': ()
2543 250..252 's1': S<u32>
2545 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2546 272..289 'bar(S(...lt()))': i32
2547 276..277 'S': S<i32>(i32) -> S<i32>
2548 276..288 'S(default())': S<i32>
2549 278..285 'default': fn default<i32>() -> i32
2550 278..287 'default()': i32
2551 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2552 295..307 'S(default())': S<{unknown}>
2553 297..304 'default': fn default<{unknown}>() -> {unknown}
2554 297..306 'default()': {unknown}
2560 fn assoc_types_from_bounds() {
2565 trait FnOnce<Args> {
2584 f::<(), _>(|z| { z; });
2589 193..224 '{ ... }); }': ()
2590 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2591 199..221 'f::<()... z; })': ()
2592 210..220 '|z| { z; }': |&()| -> ()
2594 214..220 '{ z; }': ()
2601 fn associated_type_bound() {
2605 type Item: OtherTrait<u32>;
2607 pub trait OtherTrait<T> {
2611 // this is just a workaround for chalk#234
2613 impl<T: Trait> Trait for S<T> {
2614 type Item = <T as Trait>::Item;
2617 fn test<T: Trait>() {
2618 let y: <S<T> as Trait>::Item = no_matter;
2626 fn dyn_trait_through_chalk() {
2634 impl<T> Deref for Box<T> {
2641 fn test(x: Box<dyn Trait>) {
2649 fn string_to_owned() {
2655 fn to_owned(&self) -> Self::Owned;
2657 impl ToOwned for str {
2658 type Owned = String;
2668 fn iterator_chain() {
2669 check_infer_with_mismatches(
2673 trait FnOnce<Args> {
2677 trait FnMut<Args>: FnOnce<Args> { }
2679 enum Option<T> { Some(T), None }
2682 pub trait Iterator {
2685 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2687 F: FnMut(Self::Item) -> Option<B>,
2690 fn for_each<F>(self, f: F)
2692 F: FnMut(Self::Item),
2696 pub trait IntoIterator {
2698 type IntoIter: Iterator<Item = Self::Item>;
2699 fn into_iter(self) -> Self::IntoIter;
2702 pub struct FilterMap<I, F> { }
2703 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2705 F: FnMut(I::Item) -> Option<B>,
2710 #[stable(feature = "rust1", since = "1.0.0")]
2711 impl<I: Iterator> IntoIterator for I {
2712 type Item = I::Item;
2715 fn into_iter(self) -> I {
2722 fn new() -> Self { loop {} }
2725 impl<T> IntoIterator for Vec<T> {
2727 type IntoIter = IntoIter<T>;
2730 pub struct IntoIter<T> { }
2731 impl<T> Iterator for IntoIter<T> {
2736 Vec::<i32>::new().into_iter()
2737 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2738 .for_each(|y| { y; });
2741 226..230 'self': Self
2743 317..328 '{ loop {} }': FilterMap<Self, F>
2744 319..326 'loop {}': !
2746 349..353 'self': Self
2748 405..416 '{ loop {} }': ()
2749 407..414 'loop {}': !
2751 525..529 'self': Self
2753 865..885 '{ ... }': I
2755 944..955 '{ loop {} }': Vec<T>
2756 946..953 'loop {}': !
2758 1142..1269 '{ ... }); }': ()
2759 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2760 1148..1165 'Vec::<...:new()': Vec<i32>
2761 1148..1177 'Vec::<...iter()': IntoIter<i32>
2762 1148..1240 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2763 1148..1266 'Vec::<... y; })': ()
2764 1194..1239 '|x| if...None }': |i32| -> Option<u32>
2766 1198..1239 'if x >...None }': Option<u32>
2768 1201..1206 'x > 0': bool
2770 1207..1225 '{ Some...u32) }': Option<u32>
2771 1209..1213 'Some': Some<u32>(u32) -> Option<u32>
2772 1209..1223 'Some(x as u32)': Option<u32>
2774 1214..1222 'x as u32': u32
2775 1231..1239 '{ None }': Option<u32>
2776 1233..1237 'None': Option<u32>
2777 1255..1265 '|y| { y; }': |u32| -> ()
2779 1259..1265 '{ y; }': ()
2802 fn foo() -> Self::Output;
2806 type Output = T::OutputA;
2807 fn foo() -> Self::Output { loop {} }
2818 fn trait_object_no_coercion() {
2819 check_infer_with_mismatches(
2823 fn foo(x: &dyn Foo) {}
2825 fn test(x: &dyn Foo) {
2829 21..22 'x': &dyn Foo
2831 46..47 'x': &dyn Foo
2832 59..74 '{ foo(x); }': ()
2833 65..68 'foo': fn foo(&dyn Foo)
2835 69..70 'x': &dyn Foo
2842 check_infer_with_mismatches(
2848 impl Copy for IsCopy {}
2851 trait Test { fn test(&self) -> bool; }
2852 impl<T: Copy> Test for T {}
2857 (IsCopy, IsCopy).test();
2858 (IsCopy, NotCopy).test();
2861 110..114 'self': &Self
2862 166..267 '{ ...t(); }': ()
2863 172..178 'IsCopy': IsCopy
2864 172..185 'IsCopy.test()': bool
2865 191..198 'NotCopy': NotCopy
2866 191..205 'NotCopy.test()': {unknown}
2867 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy)
2868 211..234 '(IsCop...test()': bool
2869 212..218 'IsCopy': IsCopy
2870 220..226 'IsCopy': IsCopy
2871 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy)
2872 240..264 '(IsCop...test()': {unknown}
2873 241..247 'IsCopy': IsCopy
2874 249..256 'NotCopy': NotCopy
2880 fn builtin_fn_def_copy() {
2881 check_infer_with_mismatches(
2887 fn bar<T: Copy>(T) -> T {}
2888 struct Struct(usize);
2889 enum Enum { Variant(usize) }
2891 trait Test { fn test(&self) -> bool; }
2892 impl<T: Copy> Test for T {}
2898 Enum::Variant.test();
2902 60..61 'T': {unknown}
2904 68..70: expected T, got ()
2905 145..149 'self': &Self
2906 201..281 '{ ...t(); }': ()
2907 207..210 'foo': fn foo()
2908 207..217 'foo.test()': bool
2909 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2910 223..233 'bar.test()': bool
2911 239..245 'Struct': Struct(usize) -> Struct
2912 239..252 'Struct.test()': bool
2913 258..271 'Enum::Variant': Variant(usize) -> Enum
2914 258..278 'Enum::...test()': bool
2920 fn builtin_fn_ptr_copy() {
2921 check_infer_with_mismatches(
2926 trait Test { fn test(&self) -> bool; }
2927 impl<T: Copy> Test for T {}
2929 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2935 54..58 'self': &Self
2937 118..120 'f2': fn(usize) -> u8
2938 139..141 'f3': fn(u8, u8) -> &u8
2939 162..210 '{ ...t(); }': ()
2941 168..177 'f1.test()': bool
2942 183..185 'f2': fn(usize) -> u8
2943 183..192 'f2.test()': bool
2944 198..200 'f3': fn(u8, u8) -> &u8
2945 198..207 'f3.test()': bool
2951 fn builtin_sized() {
2952 check_infer_with_mismatches(
2957 trait Test { fn test(&self) -> bool; }
2958 impl<T: Sized> Test for T {}
2962 (*"foo").test(); // not Sized
2964 (1u8, *"foo").test(); // not Sized
2967 56..60 'self': &Self
2968 113..228 '{ ...ized }': ()
2970 119..129 '1u8.test()': bool
2971 135..150 '(*"foo").test()': {unknown}
2972 136..142 '*"foo"': str
2973 137..142 '"foo"': &str
2974 169..179 '(1u8, 1u8)': (u8, u8)
2975 169..186 '(1u8, ...test()': bool
2978 192..205 '(1u8, *"foo")': (u8, str)
2979 192..212 '(1u8, ...test()': {unknown}
2981 198..204 '*"foo"': str
2982 199..204 '"foo"': &str
2988 fn integer_range_iterate() {
2991 //- /main.rs crate:main deps:core
2993 for x in 0..100 { x; }
2996 //- /core.rs crate:core
2998 pub struct Range<Idx> {
3005 pub trait Iterator {
3009 pub trait IntoIterator {
3011 type IntoIter: Iterator<Item = Self::Item>;
3014 impl<T> IntoIterator for T where T: Iterator {
3015 type Item = <T as Iterator>::Item;
3016 type IntoIter = Self;
3021 impl Step for i32 {}
3022 impl Step for i64 {}
3024 impl<A: Step> iter::Iterator for ops::Range<A> {
3032 fn infer_closure_arg() {
3043 let s = Option::None;
3044 let f = |x: Option<i32>| {};
3048 52..126 '{ ...)(s) }': ()
3049 62..63 's': Option<i32>
3050 66..78 'Option::None': Option<i32>
3051 88..89 'f': |Option<i32>| -> ()
3052 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
3053 93..94 'x': Option<i32>
3055 117..124 '(&f)(s)': ()
3056 118..120 '&f': &|Option<i32>| -> ()
3057 119..120 'f': |Option<i32>| -> ()
3058 122..123 's': Option<i32>
3064 fn infer_fn_trait_arg() {
3065 check_infer_with_mismatches(
3067 //- /lib.rs deps:std
3070 pub trait FnOnce<Args> {
3073 extern "rust-call" fn call_once(&self, args: Args) -> Self::Output;
3077 pub trait Fn<Args>:FnOnce<Args> {
3078 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3086 fn foo<F, T>(f: F) -> T
3088 F: Fn(Option<i32>) -> T,
3095 101..105 'self': &Self
3096 107..111 'args': Args
3097 220..224 'self': &Self
3098 226..230 'args': Args
3100 359..389 '{ ...f(s) }': T
3101 369..370 's': Option<i32>
3102 373..377 'None': Option<i32>
3105 385..386 's': Option<i32>
3111 fn infer_box_fn_arg() {
3112 // The type mismatch is because we don't define Unsize and CoerceUnsized
3113 check_infer_with_mismatches(
3115 //- /lib.rs deps:std
3118 pub trait FnOnce<Args> {
3121 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3126 type Target: ?Sized;
3128 fn deref(&self) -> &Self::Target;
3131 #[lang = "owned_box"]
3132 pub struct Box<T: ?Sized> {
3136 impl<T: ?Sized> Deref for Box<T> {
3139 fn deref(&self) -> &T {
3150 let s = Option::None;
3151 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3155 100..104 'self': Self
3156 106..110 'args': Args
3157 214..218 'self': &Self
3158 384..388 'self': &Box<T>
3159 396..423 '{ ... }': &T
3160 406..417 '&self.inner': &*mut T
3161 407..411 'self': &Box<T>
3162 407..417 'self.inner': *mut T
3163 478..576 '{ ...&s); }': ()
3164 488..489 's': Option<i32>
3165 492..504 'Option::None': Option<i32>
3166 514..515 'f': Box<dyn FnOnce(&Option<i32>)>
3167 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3168 554..561 '|ps| {}': |{unknown}| -> ()
3169 555..557 'ps': {unknown}
3171 568..569 'f': Box<dyn FnOnce(&Option<i32>)>
3172 568..573 'f(&s)': ()
3173 570..572 '&s': &Option<i32>
3174 571..572 's': Option<i32>
3175 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
3181 fn infer_dyn_fn_output() {
3185 pub trait FnOnce<Args> {
3187 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3191 pub trait Fn<Args>: FnOnce<Args> {
3192 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3196 let f: &dyn Fn() -> i32;
3204 fn infer_dyn_fn_once_output() {
3208 pub trait FnOnce<Args> {
3210 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3214 let f: dyn FnOnce() -> i32;
3222 fn variable_kinds_1() {
3225 trait Trait<T> { fn get(self, t: T) -> T; }
3227 impl Trait<u128> for S {}
3228 impl Trait<f32> for S {}
3240 fn variable_kinds_2() {
3243 trait Trait { fn get(self) -> Self; }
3244 impl Trait for u128 {}
3245 impl Trait for f32 {}
3257 fn underscore_import() {
3262 fn method(&self) -> u8 { 0 }
3267 impl crate::tr::Tr for Tr {}
3269 use crate::tr::Tr as _;
3284 fn method(&self) -> u8 { 0 }
3301 fn trait_in_scope_with_inner_item() {
3306 fn method(&self) -> u8 { 0 }
3321 46..50 'self': &Self
3324 115..185 '{ ... } }': ()
3325 132..183 '{ ... }': ()
3327 142..153 '().method()': u8
3333 fn inner_use_in_block() {
3338 fn method(&self) -> u8 { 0 }
3354 //^^^^^^^^^^^ {unknown}
3358 //^^^^^^^^^^^ {unknown}
3365 fn nested_inner_function_calling_self() {
3375 17..73 '{ ... } }': ()
3376 39..71 '{ ... }': ()
3378 57..62 'inner': fn inner() -> S
3385 fn infer_default_trait_type_parameter() {
3390 trait Op<RHS=Self> {
3393 fn do_op(self, rhs: RHS) -> Self::Output;
3399 fn do_op(self, rhs: Self) -> Self::Output {
3414 186..206 '{ ... }': bool
3415 196..200 'true': bool
3416 220..277 '{ ...(y); }': ()
3423 264..274 'x.do_op(y)': bool
3430 fn qualified_path_as_qualified_trait() {
3440 fn boo() -> Self::Output {
3447 impl foo::Foo for F {
3450 impl foo::Bar for F {
3451 type Output = <F as foo::Foo>::Target;
3456 let x = <F as Bar>::boo();
3459 132..163 '{ ... }': Bar::Output<Self>
3460 146..153 'loop {}': !
3462 306..358 '{ ...o(); }': ()
3464 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3465 338..355 '<F as ...:boo()': ()
3471 fn renamed_extern_crate_in_block() {
3474 //- /lib.rs crate:lib deps:serde
3475 use serde::Deserialize;
3480 extern crate serde as _serde;
3481 impl _serde::Deserialize for Foo {
3482 fn deserialize() -> u8 { 0 }
3488 //^^^^^^^^^^^^^^^^^^ u8
3491 //- /serde.rs crate:serde
3493 pub trait Deserialize {
3494 fn deserialize() -> u8;
3500 fn bin_op_adt_with_rhs_primitive() {
3501 check_infer_with_mismatches(
3504 pub trait Add<Rhs = Self> {
3506 fn add(self, rhs: Rhs) -> Self::Output;
3509 struct Wrapper(u32);
3510 impl Add<u32> for Wrapper {
3512 fn add(self, rhs: u32) -> Wrapper {
3517 let wrapped = Wrapper(10);
3519 let res = wrapped + num;
3525 192..196 'self': Wrapper
3527 219..247 '{ ... }': Wrapper
3528 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3529 229..241 'Wrapper(rhs)': Wrapper
3531 259..345 '{ ...um; }': ()
3532 269..276 'wrapped': Wrapper
3533 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3534 279..290 'Wrapper(10)': Wrapper
3538 322..325 'res': Wrapper
3539 328..335 'wrapped': Wrapper
3540 328..341 'wrapped + num': Wrapper
3552 fn do_thing(&self) -> Self::Output;
3555 impl T for [u8; 4] {
3556 type Output = usize;
3557 fn do_thing(&self) -> Self::Output {
3562 impl T for [u8; 2] {
3564 fn do_thing(&self) -> Self::Output {
3571 let v2 = v.do_thing();
3573 let v4 = v3.do_thing();
3577 44..48 'self': &Self
3578 133..137 'self': &[u8; 4]
3579 155..172 '{ ... }': usize
3581 236..240 'self': &[u8; 2]
3582 258..275 '{ ... }': u8
3584 289..392 '{ ...g(); }': ()
3585 299..300 'v': [u8; 2]
3586 303..311 '[0u8; 2]': [u8; 2]
3590 326..327 'v': [u8; 2]
3591 326..338 'v.do_thing()': u8
3592 348..350 'v3': [u8; 4]
3593 353..361 '[0u8; 4]': [u8; 4]
3596 371..373 'v4': usize
3597 376..378 'v3': [u8; 4]
3598 376..389 'v3.do_thing()': usize
3603 // FIXME: We should infer the length of the returned array :)
3605 fn const_generics() {
3610 fn do_thing(&self) -> Self::Output;
3613 impl<const L: usize> T for [u8; L] {
3614 type Output = [u8; L];
3615 fn do_thing(&self) -> Self::Output {
3622 let v2 = v.do_thing();
3626 44..48 'self': &Self
3627 151..155 'self': &[u8; _]
3628 173..194 '{ ... }': [u8; _]
3629 183..188 '*self': [u8; _]
3630 184..188 'self': &[u8; _]
3631 208..260 '{ ...g(); }': ()
3632 218..219 'v': [u8; 2]
3633 222..230 '[0u8; 2]': [u8; 2]
3636 240..242 'v2': [u8; _]
3637 245..246 'v': [u8; 2]
3638 245..257 'v.do_thing()': [u8; _]
3644 fn fn_returning_unit() {
3645 check_infer_with_mismatches(
3648 trait FnOnce<Args> {
3652 fn test<F: FnOnce()>(f: F) {
3657 88..112 '{ ...f(); }': ()
3666 fn trait_in_scope_of_trait_impl() {
3672 fn bar(self) -> usize { 0 }
3675 impl foo::Foo for u32 {
3677 let _x = self.bar();
3684 82..87 '{ 0 }': usize
3686 131..135 'self': u32
3687 137..173 '{ ... }': ()
3688 151..153 '_x': usize
3689 156..160 'self': u32
3690 156..166 'self.bar()': usize
3696 fn infer_async_ret_type() {
3699 //- /main.rs crate:main deps:core
3712 fn collect<B: Convert>(self) -> B {
3720 impl Convert for u32 {
3726 async fn get_accounts() -> Result<u32, ()> {
3727 let ret = Fooey.collect();
3732 //- /core.rs crate:core
3733 #[prelude_import] use future::*;
3735 #[lang = "future_trait"]
3754 impl Trait<u32> for S {
3775 impl Trait<u32> for S {
3799 impl Trait<S1> for S2 {
3800 fn foo(&self) { S1 }