1 use expect_test::expect;
3 use super::{check_infer, check_infer_with_mismatches, check_types};
9 //- /main.rs crate:main deps:core
12 impl Future for IntFuture {
22 //- /core.rs crate:core
23 #[prelude_import] use future::*;
25 #[lang = "future_trait"]
38 //- /main.rs crate:main deps:core
39 async fn foo() -> u64 {
49 //- /core.rs crate:core
50 #[prelude_import] use future::*;
52 #[lang = "future_trait"]
62 fn infer_desugar_async() {
65 //- /main.rs crate:main deps:core
66 async fn foo() -> u64 {
73 } //^ impl Future<Output = u64>
75 //- /core.rs crate:core
76 #[prelude_import] use future::*;
88 fn infer_async_block() {
91 //- /main.rs crate:main deps:core
95 // ^ impl Future<Output = i32>
99 let b = async {}.await;
103 let y = Option::None;
107 let _: Option<u64> = c.await;
109 // ^ impl Future<Output = Option<u64>>
112 enum Option<T> { None, Some(T) }
114 //- /core.rs crate:core
115 #[prelude_import] use future::*;
117 #[lang = "future_trait"]
131 //- /main.rs crate:main deps:core
133 let r: Result<i32, u64> = Result::Ok(1);
138 //- /core.rs crate:core
139 #[prelude_import] use ops::*;
147 #[prelude_import] use result::*;
154 impl<O, E> crate::ops::Try for Result<O, E> {
164 fn infer_try_trait_v2() {
167 //- /main.rs crate:main deps:core
169 let r: Result<i32, u64> = Result::Ok(1);
174 //- /core.rs crate:core
177 pub trait Try: FromResidual {
181 pub trait FromResidual<R = <Self as Try>::Residual> {}
184 pub use self::try_trait::FromResidual;
185 pub use self::try_trait::Try;
190 impl<T> From<T> for T {}
193 #[prelude_import] use result::*;
195 use crate::convert::From;
196 use crate::ops::{Try, FromResidual};
198 pub enum Infallible {}
199 pub enum Result<O, E> {
204 impl<O, E> Try for Result<O, E> {
206 type Error = Result<Infallible, E>;
209 impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
216 fn infer_for_loop() {
219 //- /main.rs crate:main deps:core,alloc
220 use alloc::collections::Vec;
230 //- /core.rs crate:core
231 #[prelude_import] use iter::*;
238 //- /alloc.rs crate:alloc deps:core
242 pub fn new() -> Self { Vec {} }
243 pub fn push(&mut self, t: T) { }
246 impl<T> IntoIterator for Vec<T> {
258 //- /main.rs crate:main deps:std
262 impl std::ops::Neg for Bar {
272 //- /std.rs crate:std
273 #[prelude_import] use ops::*;
288 //- /main.rs crate:main deps:std
292 impl std::ops::Not for Bar {
302 //- /std.rs crate:std
303 #[prelude_import] use ops::*;
315 fn infer_from_bound_1() {
320 impl<U> Trait<U> for S<U> {}
321 fn foo<T: Trait<u32>>(t: T) {}
329 104..143 '{ ...(s); }': ()
331 118..119 'S': S<u32>(u32) -> S<u32>
332 118..128 'S(unknown)': S<u32>
333 120..127 'unknown': u32
334 134..137 'foo': fn foo<S<u32>>(S<u32>)
335 134..140 'foo(s)': ()
342 fn infer_from_bound_2() {
347 impl<U> Trait<U> for S<U> {}
348 fn foo<U, T: Trait<U>>(t: T) -> U {}
356 110..162 '{ ...(s); }': ()
358 124..125 'S': S<u32>(u32) -> S<u32>
359 124..134 'S(unknown)': S<u32>
360 126..133 'unknown': u32
362 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32
363 153..159 'foo(s)': u32
370 fn trait_default_method_self_bound_implements_trait() {
371 cov_mark::check!(trait_self_implements_self);
375 fn foo(&self) -> i64;
386 79..89 'self.foo()': i64
392 fn trait_default_method_self_bound_implements_super_trait() {
396 fn foo(&self) -> i64;
398 trait Trait: SuperTrait {
406 94..129 '{ ... }': ()
408 112..116 'self': &Self
409 112..122 'self.foo()': i64
415 fn infer_project_associated_type() {
422 impl Iterable for S { type Item = u32; }
423 fn test<T: Iterable>() {
424 let x: <S as Iterable>::Item = 1;
425 let y: <T as Iterable>::Item = no_matter;
426 let z: T::Item = no_matter;
427 let a: <T>::Item = no_matter;
430 108..261 '{ ...ter; }': ()
433 156..157 'y': Iterable::Item<T>
434 183..192 'no_matter': Iterable::Item<T>
435 202..203 'z': Iterable::Item<T>
436 215..224 'no_matter': Iterable::Item<T>
437 234..235 'a': Iterable::Item<T>
438 249..258 'no_matter': Iterable::Item<T>
444 fn infer_return_associated_type() {
451 impl Iterable for S { type Item = u32; }
452 fn foo1<T: Iterable>(t: T) -> T::Item {}
453 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {}
454 fn foo3<T: Iterable>(t: T) -> <T>::Item {}
467 234..300 '{ ...(S); }': ()
469 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item
470 248..255 'foo1(S)': u32
473 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item
474 269..276 'foo2(S)': u32
477 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item
478 290..297 'foo3(S)': u32
485 fn infer_associated_type_bound() {
491 fn test<T: Iterable<Item=u32>>() {
492 let y: T::Item = unknown;
495 67..100 '{ ...own; }': ()
497 90..97 'unknown': u32
503 fn infer_const_body() {
506 const A: u32 = 1 + 1;
507 static B: u64 = { let x = 1; x };"#,
512 38..54 '{ let ...1; x }': u64
521 fn tuple_struct_fields() {
531 37..86 '{ ... a.1 }': u64
533 51..52 'S': S(i32, u64) -> S
547 fn tuple_struct_with_fn() {
550 struct S(fn(u32) -> u64);
557 43..101 '{ ...0(2) }': u64
559 57..58 'S': S(fn(u32) -> u64) -> S
560 57..67 'S(|i| 2*i)': S
561 59..66 '|i| 2*i': |u32| -> u64
568 81..84 'a.0': fn(u32) -> u64
572 93..96 'a.0': fn(u32) -> u64
580 fn indexing_arrays() {
582 "fn main() { &mut [9][2]; }",
584 10..26 '{ &mut...[2]; }': ()
585 12..23 '&mut [9][2]': &mut {unknown}
586 17..20 '[9]': [i32; 1]
587 17..23 '[9][2]': {unknown}
595 fn infer_ops_index() {
598 //- /main.rs crate:main deps:std
602 impl std::ops::Index<u32> for Bar {
612 //- /std.rs crate:std
613 #[prelude_import] use ops::*;
616 pub trait Index<Idx> {
625 fn infer_ops_index_int() {
628 //- /main.rs crate:main deps:std
632 impl std::ops::Index<u32> for Bar {
637 impl std::ops::Index<Range> for Bar {
648 //- /std.rs crate:std
649 #[prelude_import] use ops::*;
652 pub trait Index<Idx> {
661 fn infer_ops_index_autoderef() {
664 //- /main.rs crate:main deps:std
666 let a = &[1u32, 2, 3];
671 //- /std.rs crate:std
672 impl<T> ops::Index<u32> for [T] {
676 #[prelude_import] use ops::*;
679 pub trait Index<Idx> {
694 fn deref(&self) -> &Self::Target;
698 impl<T> Deref for Arc<T> {
704 fn foo(&self) -> u128 {}
715 fn deref_trait_with_inference_var() {
722 fn deref(&self) -> &Self::Target;
726 fn new_arc<T>() -> Arc<T> {}
727 impl<T> Deref for Arc<T> {
745 fn deref_trait_infinite_recursion() {
751 fn deref(&self) -> &Self::Target;
768 fn deref_trait_with_question_mark_size() {
774 fn deref(&self) -> &Self::Target;
778 impl<T> Deref for Arc<T> {
784 fn foo(&self) -> u128 {}
795 fn obligation_from_function_clause() {
801 impl Trait<u32> for S {}
803 fn foo<T: Trait<U>, U>(t: T) -> U {}
813 fn obligation_from_method_clause() {
820 impl Trait<isize> for S {}
824 fn foo<T: Trait<U>, U>(&self, t: T) -> U {}
835 fn obligation_from_self_method_clause() {
841 impl Trait<i64> for S {}
844 fn foo<U>(&self) -> U where Self: Trait<U> {}
855 fn obligation_from_impl_clause() {
861 impl Trait<&str> for S {}
864 impl<U, T: Trait<U>> O<T> {
865 fn foo(&self) -> U {}
876 fn generic_param_env_1() {
880 trait Trait { fn foo(self) -> u128; }
883 impl<T> Trait for T where T: Clone {}
884 fn test<T: Clone>(t: T) { t.foo(); }
891 fn generic_param_env_1_not_met() {
896 trait Trait { fn foo(self) -> u128; }
899 impl<T> Trait for T where T: Clone {}
900 fn test<T>(t: T) { t.foo(); }
907 fn generic_param_env_2() {
910 trait Trait { fn foo(self) -> u128; }
913 fn test<T: Trait>(t: T) { t.foo(); }
920 fn generic_param_env_2_not_met() {
923 trait Trait { fn foo(self) -> u128; }
926 fn test<T>(t: T) { t.foo(); }
933 fn generic_param_env_deref() {
941 impl<T> Deref for T where T: Trait {
944 fn test<T: Trait>(t: T) { (*t); }
951 fn associated_type_placeholder() {
952 // 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].
959 pub struct RefMutL<T>;
961 impl<T> ApplyL for RefMutL<T> {
962 type Out = <T as ApplyL>::Out;
965 fn test<T: ApplyL>() {
966 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
974 fn associated_type_placeholder_2() {
980 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
982 fn test<T: ApplyL>(t: T) {
991 fn argument_impl_trait() {
992 check_infer_with_mismatches(
996 fn foo2(&self) -> i64;
998 fn bar(x: impl Trait<u16>) {}
1000 impl<T> Trait<T> for S<T> {}
1002 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
1015 29..33 'self': &Self
1016 54..58 'self': &Self
1017 77..78 'x': impl Trait<u16>
1019 154..155 'x': impl Trait<u64>
1020 174..175 'y': &impl Trait<u32>
1021 195..323 '{ ...2(); }': ()
1022 201..202 'x': impl Trait<u64>
1023 208..209 'y': &impl Trait<u32>
1024 219..220 'z': S<u16>
1025 223..224 'S': S<u16>(u16) -> S<u16>
1026 223..227 'S(1)': S<u16>
1028 233..236 'bar': fn bar(S<u16>)
1029 233..239 'bar(z)': ()
1030 237..238 'z': S<u16>
1031 245..246 'x': impl Trait<u64>
1032 245..252 'x.foo()': u64
1033 258..259 'y': &impl Trait<u32>
1034 258..265 'y.foo()': u32
1035 271..272 'z': S<u16>
1036 271..278 'z.foo()': u16
1037 284..285 'x': impl Trait<u64>
1038 284..292 'x.foo2()': i64
1039 298..299 'y': &impl Trait<u32>
1040 298..306 'y.foo2()': i64
1041 312..313 'z': S<u16>
1042 312..320 'z.foo2()': i64
1048 fn argument_impl_trait_type_args_1() {
1049 check_infer_with_mismatches(
1053 // this function has an implicit Self param, an explicit type param,
1054 // and an implicit impl Trait param!
1055 fn bar<T>(x: impl Trait) -> T { loop {} }
1057 fn foo<T>(x: impl Trait) -> T { loop {} }
1068 <F as Foo>::bar::<u32>(S);
1072 foo::<u32, i32>(S); // we should ignore the extraneous i32
1075 155..156 'x': impl Trait
1076 175..186 '{ loop {} }': T
1077 177..184 'loop {}': !
1079 199..200 'x': impl Trait
1080 219..230 '{ loop {} }': T
1081 221..228 'loop {}': !
1083 300..509 '{ ... i32 }': ()
1084 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1085 306..317 'Foo::bar(S)': {unknown}
1087 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1088 323..341 '<F as ...bar(S)': {unknown}
1090 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1091 347..356 'F::bar(S)': {unknown}
1093 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1094 362..380 'Foo::b...32>(S)': u32
1096 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1097 386..411 '<F as ...32>(S)': u32
1099 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1100 418..424 'foo(S)': {unknown}
1102 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1103 430..443 'foo::<u32>(S)': u32
1105 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1106 449..467 'foo::<...32>(S)': u32
1113 fn argument_impl_trait_type_args_2() {
1114 check_infer_with_mismatches(
1121 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1127 F::<u32>.foo::<i32>(S);
1128 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1132 93..94 'x': impl Trait
1133 118..129 '{ loop {} }': (T, U)
1134 120..127 'loop {}': !
1136 143..283 '{ ...ored }': ()
1137 149..150 'F': F<{unknown}>
1138 149..157 'F.foo(S)': ({unknown}, {unknown})
1140 163..171 'F::<u32>': F<u32>
1141 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1143 184..192 'F::<u32>': F<u32>
1144 184..206 'F::<u3...32>(S)': (u32, i32)
1146 212..220 'F::<u32>': F<u32>
1147 212..239 'F::<u3...32>(S)': (u32, i32)
1154 fn argument_impl_trait_to_fn_pointer() {
1155 check_infer_with_mismatches(
1158 fn foo(x: impl Trait) { loop {} }
1163 let f: fn(S) -> () = foo;
1166 22..23 'x': impl Trait
1167 37..48 '{ loop {} }': ()
1170 90..123 '{ ...foo; }': ()
1172 117..120 'foo': fn foo(S)
1183 fn foo2(&self) -> i64;
1185 fn bar() -> impl Trait<u64> {}
1187 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1199 29..33 'self': &Self
1200 54..58 'self': &Self
1202 110..111 'x': impl Trait<u64>
1203 130..131 'y': &impl Trait<u64>
1204 151..268 '{ ...2(); }': ()
1205 157..158 'x': impl Trait<u64>
1206 164..165 'y': &impl Trait<u64>
1207 175..176 'z': impl Trait<u64>
1208 179..182 'bar': fn bar() -> impl Trait<u64>
1209 179..184 'bar()': impl Trait<u64>
1210 190..191 'x': impl Trait<u64>
1211 190..197 'x.foo()': u64
1212 203..204 'y': &impl Trait<u64>
1213 203..210 'y.foo()': u64
1214 216..217 'z': impl Trait<u64>
1215 216..223 'z.foo()': u64
1216 229..230 'x': impl Trait<u64>
1217 229..237 'x.foo2()': i64
1218 243..244 'y': &impl Trait<u64>
1219 243..251 'y.foo2()': i64
1220 257..258 'z': impl Trait<u64>
1221 257..265 'z.foo2()': i64
1227 fn simple_return_pos_impl_trait() {
1228 cov_mark::check!(lower_rpit);
1234 fn bar() -> impl Trait<u64> { loop {} }
1241 29..33 'self': &Self
1242 71..82 '{ loop {} }': !
1245 94..129 '{ ...o(); }': ()
1246 104..105 'a': impl Trait<u64>
1247 108..111 'bar': fn bar() -> impl Trait<u64>
1248 108..113 'bar()': impl Trait<u64>
1249 119..120 'a': impl Trait<u64>
1250 119..126 'a.foo()': u64
1256 fn more_return_pos_impl_trait() {
1261 fn next(&mut self) -> Self::Item;
1266 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1267 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1273 let (c, d) = baz(1u128);
1278 49..53 'self': &mut Self
1279 101..105 'self': &Self
1280 184..195 '{ loop {} }': ({unknown}, {unknown})
1281 186..193 'loop {}': !
1284 268..279 '{ loop {} }': ({unknown}, {unknown})
1285 270..277 'loop {}': !
1287 291..413 '{ ...o(); }': ()
1288 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1289 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1290 305..306 'b': impl Trait<u64>
1291 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1292 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1293 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1294 321..329 'a.next()': impl Trait<u32>
1295 321..335 'a.next().foo()': u32
1296 341..342 'b': impl Trait<u64>
1297 341..348 'b.foo()': u64
1298 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1299 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1300 362..363 'd': impl Trait<u128>
1301 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1302 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1303 371..376 '1u128': u128
1304 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1305 383..391 'c.next()': impl Trait<u128>
1306 383..397 'c.next().foo()': u128
1307 403..404 'd': impl Trait<u128>
1308 403..410 'd.foo()': u128
1319 fn foo2(&self) -> i64;
1321 fn bar() -> dyn Trait<u64> {}
1323 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1335 29..33 'self': &Self
1336 54..58 'self': &Self
1338 109..110 'x': dyn Trait<u64>
1339 128..129 'y': &dyn Trait<u64>
1340 148..265 '{ ...2(); }': ()
1341 154..155 'x': dyn Trait<u64>
1342 161..162 'y': &dyn Trait<u64>
1343 172..173 'z': dyn Trait<u64>
1344 176..179 'bar': fn bar() -> dyn Trait<u64>
1345 176..181 'bar()': dyn Trait<u64>
1346 187..188 'x': dyn Trait<u64>
1347 187..194 'x.foo()': u64
1348 200..201 'y': &dyn Trait<u64>
1349 200..207 'y.foo()': u64
1350 213..214 'z': dyn Trait<u64>
1351 213..220 'z.foo()': u64
1352 226..227 'x': dyn Trait<u64>
1353 226..234 'x.foo2()': i64
1354 240..241 'y': &dyn Trait<u64>
1355 240..248 'y.foo2()': i64
1356 254..255 'z': dyn Trait<u64>
1357 254..262 'z.foo2()': i64
1363 fn dyn_trait_in_impl() {
1367 fn foo(&self) -> (T, U);
1370 impl<T, U> S<T, U> {
1371 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1373 trait Trait2<T, U> {
1374 fn baz(&self) -> (T, U);
1376 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1378 fn test(s: S<u32, i32>) {
1382 32..36 'self': &Self
1383 102..106 'self': &S<T, U>
1384 128..139 '{ loop {} }': &dyn Trait<T, U>
1385 130..137 'loop {}': !
1387 175..179 'self': &Self
1388 251..252 's': S<u32, i32>
1389 267..289 '{ ...z(); }': ()
1390 273..274 's': S<u32, i32>
1391 273..280 's.bar()': &dyn Trait<u32, i32>
1392 273..286 's.bar().baz()': (u32, i32)
1398 fn dyn_trait_bare() {
1402 fn foo(&self) -> u64;
1404 fn bar() -> Trait {}
1406 fn test(x: Trait, y: &Trait) -> u64 {
1415 26..30 'self': &Self
1417 72..73 'x': dyn Trait
1418 82..83 'y': &dyn Trait
1419 100..175 '{ ...o(); }': ()
1420 106..107 'x': dyn Trait
1421 113..114 'y': &dyn Trait
1422 124..125 'z': dyn Trait
1423 128..131 'bar': fn bar() -> dyn Trait
1424 128..133 'bar()': dyn Trait
1425 139..140 'x': dyn Trait
1426 139..146 'x.foo()': u64
1427 152..153 'y': &dyn Trait
1428 152..159 'y.foo()': u64
1429 165..166 'z': dyn Trait
1430 165..172 'z.foo()': u64
1441 a: impl Trait + 'lifetime,
1444 d: impl ('lifetime),
1446 f: impl Trait + ?Sized
1450 28..29 'a': impl Trait
1452 82..83 'c': impl Trait
1455 148..149 'f': impl Trait
1463 fn error_bound_chalk() {
1467 fn foo(&self) -> u32 {}
1470 fn test(x: (impl Trait + UnknownTrait)) {
1478 fn assoc_type_bindings() {
1485 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1486 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1487 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1490 impl<T> Trait for S<T> { type Type = T; }
1492 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1510 262..263 'y': impl Trait<Type = i64>
1511 289..397 '{ ...r>); }': ()
1512 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1513 295..301 'get(x)': u32
1515 307..311 'get2': fn get2<u32, T>(T) -> u32
1516 307..314 'get2(x)': u32
1518 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1519 320..326 'get(y)': i64
1520 324..325 'y': impl Trait<Type = i64>
1521 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1522 332..339 'get2(y)': i64
1523 337..338 'y': impl Trait<Type = i64>
1524 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1525 345..356 'get(set(S))': u64
1526 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1527 349..355 'set(S)': S<u64>
1528 353..354 'S': S<u64>
1529 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1530 362..374 'get2(set(S))': u64
1531 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1532 367..373 'set(S)': S<u64>
1533 371..372 'S': S<u64>
1534 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1535 380..394 'get2(S::<str>)': str
1536 385..393 'S::<str>': S<str>
1542 fn impl_trait_assoc_binding_projection_bug() {
1545 //- /main.rs crate:main deps:std
1546 pub trait Language {
1549 pub enum RustLanguage {}
1550 impl Language for RustLanguage {
1551 type Kind = SyntaxKind;
1553 struct SyntaxNode<L> {}
1554 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1557 fn clone(&self) -> Self;
1560 fn api_walkthrough() {
1566 //- /std.rs crate:std
1567 #[prelude_import] use iter::*;
1569 trait IntoIterator {
1575 impl<T: Iterator> IntoIterator for T {
1576 type Item = <T as Iterator>::Item;
1584 fn projection_eq_within_chalk() {
1593 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1595 fn test<T: Trait1<Type = u32>>(x: T) {
1601 169..185 '{ ...o(); }': ()
1603 175..182 'x.foo()': u32
1609 fn where_clause_trait_in_scope_for_method_resolution() {
1614 fn foo(&self) -> u32 {}
1618 fn test<T: foo::Trait>(x: T) {
1626 fn super_trait_method_resolution() {
1631 fn foo(&self) -> u32 {}
1634 trait Trait1: foo::SuperTrait {}
1635 trait Trait2 where Self: foo::SuperTrait {}
1637 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1642 49..53 'self': &Self
1646 193..222 '{ ...o(); }': ()
1648 199..206 'x.foo()': u32
1650 212..219 'y.foo()': u32
1656 fn super_trait_impl_trait_method_resolution() {
1661 fn foo(&self) -> u32 {}
1664 trait Trait1: foo::SuperTrait {}
1666 fn test(x: &impl Trait1) {
1670 49..53 'self': &Self
1672 115..116 'x': &impl Trait1
1673 132..148 '{ ...o(); }': ()
1674 138..139 'x': &impl Trait1
1675 138..145 'x.foo()': u32
1681 fn super_trait_cycle() {
1682 // This just needs to not crash
1688 fn test<T: A>(x: T) {
1694 49..65 '{ ...o(); }': ()
1696 55..62 'x.foo()': {unknown}
1702 fn super_trait_assoc_type_bounds() {
1705 trait SuperTrait { type Type; }
1706 trait Trait where Self: SuperTrait {}
1708 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1709 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1712 impl<T> SuperTrait for S<T> { type Type = T; }
1713 impl<T> Trait for S<T> {}
1724 258..279 '{ ...S)); }': ()
1725 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1726 264..276 'get2(set(S))': u64
1727 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1728 269..275 'set(S)': S<u64>
1729 273..274 'S': S<u64>
1736 check_infer_with_mismatches(
1738 trait FnOnce<Args> {
1741 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1744 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1745 f.call_once((1, 2));
1751 155..183 '{ ...2)); }': ()
1753 161..180 'f.call...1, 2))': u128
1754 173..179 '(1, 2)': (u32, u64)
1762 fn fn_ptr_and_item() {
1763 check_infer_with_mismatches(
1766 trait FnOnce<Args> {
1769 fn call_once(self, args: Args) -> Self::Output;
1778 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1779 fn foo(&self) -> (A1, R) { loop {} }
1782 enum Opt<T> { None, Some(T) }
1784 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1788 let bar: Bar<fn(u8) -> u32>;
1792 let f: fn(u8) -> u32;
1798 139..143 'self': &Self
1799 243..247 'self': &Bar<F>
1800 260..271 '{ loop {} }': (A1, R)
1801 262..269 'loop {}': !
1803 355..359 'self': Opt<T>
1805 377..388 '{ loop {} }': Opt<U>
1806 379..386 'loop {}': !
1808 402..518 '{ ...(f); }': ()
1809 412..415 'bar': Bar<fn(u8) -> u32>
1810 441..444 'bar': Bar<fn(u8) -> u32>
1811 441..450 'bar.foo()': (u8, u32)
1812 461..464 'opt': Opt<u8>
1813 483..484 'f': fn(u8) -> u32
1814 505..508 'opt': Opt<u8>
1815 505..515 'opt.map(f)': Opt<u32>
1816 513..514 'f': fn(u8) -> u32
1822 fn fn_trait_deref_with_ty_default() {
1829 fn deref(&self) -> &Self::Target;
1833 trait FnOnce<Args> {
1836 fn call_once(self, args: Args) -> Self::Output;
1842 fn foo(&self) -> usize {}
1845 struct Lazy<T, F = fn() -> T>(F);
1847 impl<T, F> Lazy<T, F> {
1848 pub fn new(f: F) -> Lazy<T, F> {}
1851 impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
1856 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1857 let r1 = lazy1.foo();
1859 fn make_foo_fn() -> Foo {}
1860 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1861 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1862 let r2 = lazy2.foo();
1865 64..68 'self': &Self
1866 165..169 'self': Self
1867 171..175 'args': Args
1868 239..243 'self': &Foo
1872 443..689 '{ ...o(); }': ()
1873 453..458 'lazy1': Lazy<Foo, || -> Foo>
1874 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1875 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1876 485..491 '|| Foo': || -> Foo
1878 502..504 'r1': usize
1879 507..512 'lazy1': Lazy<Foo, || -> Foo>
1880 507..518 'lazy1.foo()': usize
1881 560..575 'make_foo_fn_ptr': fn() -> Foo
1882 591..602 'make_foo_fn': fn make_foo_fn() -> Foo
1883 612..617 'lazy2': Lazy<Foo, fn() -> Foo>
1884 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1885 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1886 644..659 'make_foo_fn_ptr': fn() -> Foo
1887 670..672 'r2': usize
1888 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1889 675..686 'lazy2.foo()': usize
1897 check_infer_with_mismatches(
1900 trait FnOnce<Args> {
1904 enum Option<T> { Some(T), None }
1906 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1910 let x = Option::Some(1u32);
1913 let y: Option<i64> = x.map(|_v| 1);
1916 147..151 'self': Option<T>
1918 172..183 '{ loop {} }': Option<U>
1919 174..181 'loop {}': !
1921 197..316 '{ ... 1); }': ()
1922 207..208 'x': Option<u32>
1923 211..223 'Option::Some': Some<u32>(u32) -> Option<u32>
1924 211..229 'Option...(1u32)': Option<u32>
1925 224..228 '1u32': u32
1926 235..236 'x': Option<u32>
1927 235..251 'x.map(...v + 1)': Option<u32>
1928 241..250 '|v| v + 1': |u32| -> u32
1931 245..250 'v + 1': u32
1933 257..258 'x': Option<u32>
1934 257..273 'x.map(... 1u64)': Option<u64>
1935 263..272 '|_v| 1u64': |u32| -> u64
1937 268..272 '1u64': u64
1938 283..284 'y': Option<i64>
1939 300..301 'x': Option<u32>
1940 300..313 'x.map(|_v| 1)': Option<i64>
1941 306..312 '|_v| 1': |u32| -> i64
1950 check_infer_with_mismatches(
1953 pub trait Add<Rhs = Self> {
1955 fn add(self, rhs: Rhs) -> Self::Output;
1958 trait FnOnce<Args> {
1964 fn add(self, rhs: u64) -> Self::Output {0}
1969 fn add(self, rhs: u128) -> Self::Output {0}
1972 fn test<F: FnOnce(u32) -> u64>(f: F) {
1976 let h = |v| 1u128 + v;
1981 203..207 'self': u64
1985 297..301 'self': u128
1986 303..306 'rhs': u128
1987 330..333 '{0}': u128
1990 374..450 '{ ...+ v; }': ()
1992 380..384 'f(1)': {unknown}
1994 394..395 'g': |u64| -> u64
1995 398..407 '|v| v + 1': |u64| -> u64
1998 402..407 'v + 1': u64
2000 413..414 'g': |u64| -> u64
2001 413..420 'g(1u64)': u64
2002 415..419 '1u64': u64
2003 430..431 'h': |u128| -> u128
2004 434..447 '|v| 1u128 + v': |u128| -> u128
2006 438..443 '1u128': u128
2007 438..447 '1u128 + v': u128
2014 fn closure_as_argument_inference_order() {
2015 check_infer_with_mismatches(
2018 trait FnOnce<Args> {
2022 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
2023 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
2027 fn method(self) -> u64;
2029 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
2030 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
2034 let x1 = foo1(S, |s| s.method());
2035 let x2 = foo2(|s| s.method(), S);
2036 let x3 = S.foo1(S, |s| s.method());
2037 let x4 = S.foo2(|s| s.method(), S);
2042 111..122 '{ loop {} }': U
2043 113..120 'loop {}': !
2047 173..184 '{ loop {} }': U
2048 175..182 'loop {}': !
2054 294..305 '{ loop {} }': U
2055 296..303 'loop {}': !
2060 366..377 '{ loop {} }': U
2061 368..375 'loop {}': !
2063 391..550 '{ ... S); }': ()
2065 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2066 406..429 'foo1(S...hod())': u64
2068 414..428 '|s| s.method()': |S| -> u64
2071 418..428 's.method()': u64
2073 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2074 444..467 'foo2(|...(), S)': u64
2075 449..463 '|s| s.method()': |S| -> u64
2078 453..463 's.method()': u64
2082 482..507 'S.foo1...hod())': u64
2084 492..506 '|s| s.method()': |S| -> u64
2087 496..506 's.method()': u64
2090 522..547 'S.foo2...(), S)': u64
2091 529..543 '|s| s.method()': |S| -> u64
2094 533..543 's.method()': u64
2101 fn fn_item_fn_trait() {
2105 trait FnOnce<Args> {
2113 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2117 } //^^^^^^^^^^^^^^^^^^ S
2123 fn unselected_projection_in_trait_env_1() {
2132 fn foo(&self) -> u32;
2135 fn test<T: Trait>() where T::Item: Trait2 {
2136 let x: T::Item = no_matter;
2144 fn unselected_projection_in_trait_env_2() {
2152 fn foo(&self) -> u32;
2155 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2156 let x: T::Item = no_matter;
2164 fn unselected_projection_on_impl_self() {
2171 fn f(&self, x: Self::Item);
2178 fn f(&self, x: Self::Item) { let y = x; }
2185 fn f(&self, x: <Self>::Item) { let y = x; }
2188 40..44 'self': &Self
2189 46..47 'x': Trait::Item<Self>
2192 147..161 '{ let y = x; }': ()
2195 228..232 'self': &S2
2197 251..265 '{ let y = x; }': ()
2205 fn unselected_projection_on_trait_self() {
2211 fn f(&self) -> Self::Item { loop {} }
2227 fn unselected_projection_chalk_fold() {
2231 trait Fold<I: Interner, TI = I> {
2235 struct Ty<I: Interner> {}
2236 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2237 type Result = Ty<TI>;
2240 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2247 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2255 fn trait_impl_self_ty() {
2264 impl Trait<Self> for S {}
2274 fn trait_impl_self_ty_cycle() {
2283 impl Trait for S<Self> {}
2293 fn unselected_projection_in_trait_env_cycle_1() {
2294 // this is a legitimate cycle
2303 fn test<T: Trait>() where T: Trait2<T::Item> {
2304 let x: T::Item = no_matter;
2311 fn unselected_projection_in_trait_env_cycle_2() {
2312 // this is a legitimate cycle
2320 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2321 let x: T::Item = no_matter;
2328 fn unselected_projection_in_trait_env_cycle_3() {
2329 // this is a cycle for rustc; we currently accept it
2338 fn test<T>() where T: Trait<OtherItem = T::Item> {
2339 let x: T::Item = no_matter;
2340 } //^ Trait::Item<T>
2346 fn unselected_projection_in_trait_env_no_cycle() {
2347 // this is not a cycle
2355 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2357 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2360 fn len(&self) -> usize;
2363 pub trait UnificationStoreMut: UnificationStoreBase {
2364 fn push(&mut self, value: Self::Key);
2367 fn test<T>(t: T) where T: UnificationStoreMut {
2372 } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2378 fn inline_assoc_type_bounds_1() {
2384 trait OtherTrait<T> {
2388 // workaround for Chalk assoc type normalization problems
2390 impl<T: Iterator> Iterator for S<T> {
2391 type Item = <T as Iterator>::Item;
2394 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2395 let x: <S<I> as Iterator>::Item;
2403 fn inline_assoc_type_bounds_2() {
2410 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2411 let x: <<I as Iterator>::Item as Iterator>::Item;
2419 fn proc_macro_server_types() {
2422 macro_rules! with_api {
2423 ($S:ident, $self:ident, $m:ident) => {
2426 fn new() -> $S::TokenStream;
2433 macro_rules! associated_item {
2434 (type TokenStream) =>
2435 (type TokenStream: 'static;);
2437 (type Group: 'static;);
2438 ($($item:tt)*) => ($($item)*;)
2440 macro_rules! declare_server_traits {
2442 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2445 $(associated_item!(type $name);)*
2448 $(pub trait $name: Types {
2449 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2452 pub trait Server: Types $(+ $name)* {}
2453 impl<S: Types $(+ $name)*> Server for S {}
2457 with_api!(Self, self_, declare_server_traits);
2461 impl Types for Rustc {
2462 type TokenStream = T;
2466 fn make<T>() -> T { loop {} }
2467 impl TokenStream for Rustc {
2468 fn new() -> Self::TokenStream {
2469 let group: Self::Group = make();
2474 1061..1072 '{ loop {} }': T
2475 1063..1070 'loop {}': !
2477 1136..1199 '{ ... }': T
2478 1150..1155 'group': G
2479 1171..1175 'make': fn make<G>() -> G
2480 1171..1177 'make()': G
2481 1187..1191 'make': fn make<T>() -> T
2482 1187..1193 'make()': T
2488 fn unify_impl_trait() {
2489 check_infer_with_mismatches(
2493 fn foo(x: impl Trait<u32>) { loop {} }
2494 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2497 impl<T> Trait<T> for S<T> {}
2499 fn default<T>() -> T { loop {} }
2501 fn test() -> impl Trait<i32> {
2502 let s1 = S(default());
2504 let x: i32 = bar(S(default()));
2508 26..27 'x': impl Trait<u32>
2509 46..57 '{ loop {} }': ()
2512 68..69 'x': impl Trait<T>
2513 91..102 '{ loop {} }': T
2514 93..100 'loop {}': !
2516 171..182 '{ loop {} }': T
2517 173..180 'loop {}': !
2519 213..309 '{ ...t()) }': S<{unknown}>
2520 223..225 's1': S<u32>
2521 228..229 'S': S<u32>(u32) -> S<u32>
2522 228..240 'S(default())': S<u32>
2523 230..237 'default': fn default<u32>() -> u32
2524 230..239 'default()': u32
2525 246..249 'foo': fn foo(S<u32>)
2526 246..253 'foo(s1)': ()
2527 250..252 's1': S<u32>
2529 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2530 272..289 'bar(S(...lt()))': i32
2531 276..277 'S': S<i32>(i32) -> S<i32>
2532 276..288 'S(default())': S<i32>
2533 278..285 'default': fn default<i32>() -> i32
2534 278..287 'default()': i32
2535 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2536 295..307 'S(default())': S<{unknown}>
2537 297..304 'default': fn default<{unknown}>() -> {unknown}
2538 297..306 'default()': {unknown}
2544 fn assoc_types_from_bounds() {
2549 trait FnOnce<Args> {
2568 f::<(), _>(|z| { z; });
2573 193..224 '{ ... }); }': ()
2574 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2575 199..221 'f::<()... z; })': ()
2576 210..220 '|z| { z; }': |&()| -> ()
2578 214..220 '{ z; }': ()
2585 fn associated_type_bound() {
2589 type Item: OtherTrait<u32>;
2591 pub trait OtherTrait<T> {
2595 // this is just a workaround for chalk#234
2597 impl<T: Trait> Trait for S<T> {
2598 type Item = <T as Trait>::Item;
2601 fn test<T: Trait>() {
2602 let y: <S<T> as Trait>::Item = no_matter;
2610 fn dyn_trait_through_chalk() {
2618 impl<T> Deref for Box<T> {
2625 fn test(x: Box<dyn Trait>) {
2633 fn string_to_owned() {
2639 fn to_owned(&self) -> Self::Owned;
2641 impl ToOwned for str {
2642 type Owned = String;
2652 fn iterator_chain() {
2653 check_infer_with_mismatches(
2657 trait FnOnce<Args> {
2661 trait FnMut<Args>: FnOnce<Args> { }
2663 enum Option<T> { Some(T), None }
2666 pub trait Iterator {
2669 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2671 F: FnMut(Self::Item) -> Option<B>,
2674 fn for_each<F>(self, f: F)
2676 F: FnMut(Self::Item),
2680 pub trait IntoIterator {
2682 type IntoIter: Iterator<Item = Self::Item>;
2683 fn into_iter(self) -> Self::IntoIter;
2686 pub struct FilterMap<I, F> { }
2687 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2689 F: FnMut(I::Item) -> Option<B>,
2694 #[stable(feature = "rust1", since = "1.0.0")]
2695 impl<I: Iterator> IntoIterator for I {
2696 type Item = I::Item;
2699 fn into_iter(self) -> I {
2706 fn new() -> Self { loop {} }
2709 impl<T> IntoIterator for Vec<T> {
2711 type IntoIter = IntoIter<T>;
2714 pub struct IntoIter<T> { }
2715 impl<T> Iterator for IntoIter<T> {
2720 Vec::<i32>::new().into_iter()
2721 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2722 .for_each(|y| { y; });
2725 226..230 'self': Self
2727 317..328 '{ loop {} }': FilterMap<Self, F>
2728 319..326 'loop {}': !
2730 349..353 'self': Self
2732 405..416 '{ loop {} }': ()
2733 407..414 'loop {}': !
2735 525..529 'self': Self
2737 865..885 '{ ... }': I
2739 944..955 '{ loop {} }': Vec<T>
2740 946..953 'loop {}': !
2742 1142..1269 '{ ... }); }': ()
2743 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2744 1148..1165 'Vec::<...:new()': Vec<i32>
2745 1148..1177 'Vec::<...iter()': IntoIter<i32>
2746 1148..1240 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2747 1148..1266 'Vec::<... y; })': ()
2748 1194..1239 '|x| if...None }': |i32| -> Option<u32>
2750 1198..1239 'if x >...None }': Option<u32>
2752 1201..1206 'x > 0': bool
2754 1207..1225 '{ Some...u32) }': Option<u32>
2755 1209..1213 'Some': Some<u32>(u32) -> Option<u32>
2756 1209..1223 'Some(x as u32)': Option<u32>
2758 1214..1222 'x as u32': u32
2759 1231..1239 '{ None }': Option<u32>
2760 1233..1237 'None': Option<u32>
2761 1255..1265 '|y| { y; }': |u32| -> ()
2763 1259..1265 '{ y; }': ()
2786 fn foo() -> Self::Output;
2790 type Output = T::OutputA;
2791 fn foo() -> Self::Output { loop {} }
2802 fn trait_object_no_coercion() {
2803 check_infer_with_mismatches(
2807 fn foo(x: &dyn Foo) {}
2809 fn test(x: &dyn Foo) {
2813 21..22 'x': &dyn Foo
2815 46..47 'x': &dyn Foo
2816 59..74 '{ foo(x); }': ()
2817 65..68 'foo': fn foo(&dyn Foo)
2819 69..70 'x': &dyn Foo
2826 check_infer_with_mismatches(
2832 impl Copy for IsCopy {}
2835 trait Test { fn test(&self) -> bool; }
2836 impl<T: Copy> Test for T {}
2841 (IsCopy, IsCopy).test();
2842 (IsCopy, NotCopy).test();
2845 110..114 'self': &Self
2846 166..267 '{ ...t(); }': ()
2847 172..178 'IsCopy': IsCopy
2848 172..185 'IsCopy.test()': bool
2849 191..198 'NotCopy': NotCopy
2850 191..205 'NotCopy.test()': {unknown}
2851 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy)
2852 211..234 '(IsCop...test()': bool
2853 212..218 'IsCopy': IsCopy
2854 220..226 'IsCopy': IsCopy
2855 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy)
2856 240..264 '(IsCop...test()': {unknown}
2857 241..247 'IsCopy': IsCopy
2858 249..256 'NotCopy': NotCopy
2864 fn builtin_fn_def_copy() {
2865 check_infer_with_mismatches(
2871 fn bar<T: Copy>(T) -> T {}
2872 struct Struct(usize);
2873 enum Enum { Variant(usize) }
2875 trait Test { fn test(&self) -> bool; }
2876 impl<T: Copy> Test for T {}
2882 Enum::Variant.test();
2886 60..61 'T': {unknown}
2888 68..70: expected T, got ()
2889 145..149 'self': &Self
2890 201..281 '{ ...t(); }': ()
2891 207..210 'foo': fn foo()
2892 207..217 'foo.test()': bool
2893 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2894 223..233 'bar.test()': bool
2895 239..245 'Struct': Struct(usize) -> Struct
2896 239..252 'Struct.test()': bool
2897 258..271 'Enum::Variant': Variant(usize) -> Enum
2898 258..278 'Enum::...test()': bool
2904 fn builtin_fn_ptr_copy() {
2905 check_infer_with_mismatches(
2910 trait Test { fn test(&self) -> bool; }
2911 impl<T: Copy> Test for T {}
2913 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2919 54..58 'self': &Self
2921 118..120 'f2': fn(usize) -> u8
2922 139..141 'f3': fn(u8, u8) -> &u8
2923 162..210 '{ ...t(); }': ()
2925 168..177 'f1.test()': bool
2926 183..185 'f2': fn(usize) -> u8
2927 183..192 'f2.test()': bool
2928 198..200 'f3': fn(u8, u8) -> &u8
2929 198..207 'f3.test()': bool
2935 fn builtin_sized() {
2936 check_infer_with_mismatches(
2941 trait Test { fn test(&self) -> bool; }
2942 impl<T: Sized> Test for T {}
2946 (*"foo").test(); // not Sized
2948 (1u8, *"foo").test(); // not Sized
2951 56..60 'self': &Self
2952 113..228 '{ ...ized }': ()
2954 119..129 '1u8.test()': bool
2955 135..150 '(*"foo").test()': {unknown}
2956 136..142 '*"foo"': str
2957 137..142 '"foo"': &str
2958 169..179 '(1u8, 1u8)': (u8, u8)
2959 169..186 '(1u8, ...test()': bool
2962 192..205 '(1u8, *"foo")': (u8, str)
2963 192..212 '(1u8, ...test()': {unknown}
2965 198..204 '*"foo"': str
2966 199..204 '"foo"': &str
2972 fn integer_range_iterate() {
2975 //- /main.rs crate:main deps:core
2977 for x in 0..100 { x; }
2980 //- /core.rs crate:core
2982 pub struct Range<Idx> {
2989 pub trait Iterator {
2993 pub trait IntoIterator {
2995 type IntoIter: Iterator<Item = Self::Item>;
2998 impl<T> IntoIterator for T where T: Iterator {
2999 type Item = <T as Iterator>::Item;
3000 type IntoIter = Self;
3005 impl Step for i32 {}
3006 impl Step for i64 {}
3008 impl<A: Step> iter::Iterator for ops::Range<A> {
3016 fn infer_closure_arg() {
3027 let s = Option::None;
3028 let f = |x: Option<i32>| {};
3032 52..126 '{ ...)(s) }': ()
3033 62..63 's': Option<i32>
3034 66..78 'Option::None': Option<i32>
3035 88..89 'f': |Option<i32>| -> ()
3036 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
3037 93..94 'x': Option<i32>
3039 117..124 '(&f)(s)': ()
3040 118..120 '&f': &|Option<i32>| -> ()
3041 119..120 'f': |Option<i32>| -> ()
3042 122..123 's': Option<i32>
3048 fn infer_fn_trait_arg() {
3049 check_infer_with_mismatches(
3051 //- /lib.rs deps:std
3054 pub trait FnOnce<Args> {
3057 extern "rust-call" fn call_once(&self, args: Args) -> Self::Output;
3061 pub trait Fn<Args>:FnOnce<Args> {
3062 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3070 fn foo<F, T>(f: F) -> T
3072 F: Fn(Option<i32>) -> T,
3079 101..105 'self': &Self
3080 107..111 'args': Args
3081 220..224 'self': &Self
3082 226..230 'args': Args
3084 359..389 '{ ...f(s) }': T
3085 369..370 's': Option<i32>
3086 373..377 'None': Option<i32>
3089 385..386 's': Option<i32>
3095 fn infer_box_fn_arg() {
3096 // The type mismatch is because we don't define Unsize and CoerceUnsized
3097 check_infer_with_mismatches(
3099 //- /lib.rs deps:std
3102 pub trait FnOnce<Args> {
3105 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3110 type Target: ?Sized;
3112 fn deref(&self) -> &Self::Target;
3115 #[lang = "owned_box"]
3116 pub struct Box<T: ?Sized> {
3120 impl<T: ?Sized> Deref for Box<T> {
3123 fn deref(&self) -> &T {
3134 let s = Option::None;
3135 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3139 100..104 'self': Self
3140 106..110 'args': Args
3141 214..218 'self': &Self
3142 384..388 'self': &Box<T>
3143 396..423 '{ ... }': &T
3144 406..417 '&self.inner': &*mut T
3145 407..411 'self': &Box<T>
3146 407..417 'self.inner': *mut T
3147 478..576 '{ ...&s); }': ()
3148 488..489 's': Option<i32>
3149 492..504 'Option::None': Option<i32>
3150 514..515 'f': Box<dyn FnOnce(&Option<i32>)>
3151 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3152 554..561 '|ps| {}': |{unknown}| -> ()
3153 555..557 'ps': {unknown}
3155 568..569 'f': Box<dyn FnOnce(&Option<i32>)>
3156 568..573 'f(&s)': ()
3157 570..572 '&s': &Option<i32>
3158 571..572 's': Option<i32>
3159 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
3165 fn infer_dyn_fn_output() {
3169 pub trait FnOnce<Args> {
3171 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3175 pub trait Fn<Args>: FnOnce<Args> {
3176 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3180 let f: &dyn Fn() -> i32;
3188 fn infer_dyn_fn_once_output() {
3192 pub trait FnOnce<Args> {
3194 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3198 let f: dyn FnOnce() -> i32;
3206 fn variable_kinds_1() {
3209 trait Trait<T> { fn get(self, t: T) -> T; }
3211 impl Trait<u128> for S {}
3212 impl Trait<f32> for S {}
3224 fn variable_kinds_2() {
3227 trait Trait { fn get(self) -> Self; }
3228 impl Trait for u128 {}
3229 impl Trait for f32 {}
3241 fn underscore_import() {
3246 fn method(&self) -> u8 { 0 }
3251 impl crate::tr::Tr for Tr {}
3253 use crate::tr::Tr as _;
3268 fn method(&self) -> u8 { 0 }
3285 fn trait_in_scope_with_inner_item() {
3290 fn method(&self) -> u8 { 0 }
3305 46..50 'self': &Self
3308 115..185 '{ ... } }': ()
3309 132..183 '{ ... }': ()
3311 142..153 '().method()': u8
3317 fn inner_use_in_block() {
3322 fn method(&self) -> u8 { 0 }
3338 //^^^^^^^^^^^ {unknown}
3342 //^^^^^^^^^^^ {unknown}
3349 fn nested_inner_function_calling_self() {
3359 17..73 '{ ... } }': ()
3360 39..71 '{ ... }': ()
3362 57..62 'inner': fn inner() -> S
3369 fn infer_default_trait_type_parameter() {
3374 trait Op<RHS=Self> {
3377 fn do_op(self, rhs: RHS) -> Self::Output;
3383 fn do_op(self, rhs: Self) -> Self::Output {
3398 186..206 '{ ... }': bool
3399 196..200 'true': bool
3400 220..277 '{ ...(y); }': ()
3407 264..274 'x.do_op(y)': bool
3414 fn qualified_path_as_qualified_trait() {
3424 fn boo() -> Self::Output {
3431 impl foo::Foo for F {
3434 impl foo::Bar for F {
3435 type Output = <F as foo::Foo>::Target;
3440 let x = <F as Bar>::boo();
3443 132..163 '{ ... }': Bar::Output<Self>
3444 146..153 'loop {}': !
3446 306..358 '{ ...o(); }': ()
3448 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3449 338..355 '<F as ...:boo()': ()
3455 fn renamed_extern_crate_in_block() {
3458 //- /lib.rs crate:lib deps:serde
3459 use serde::Deserialize;
3464 extern crate serde as _serde;
3465 impl _serde::Deserialize for Foo {
3466 fn deserialize() -> u8 { 0 }
3472 //^^^^^^^^^^^^^^^^^^ u8
3475 //- /serde.rs crate:serde
3477 pub trait Deserialize {
3478 fn deserialize() -> u8;
3484 fn bin_op_adt_with_rhs_primitive() {
3485 check_infer_with_mismatches(
3488 pub trait Add<Rhs = Self> {
3490 fn add(self, rhs: Rhs) -> Self::Output;
3493 struct Wrapper(u32);
3494 impl Add<u32> for Wrapper {
3496 fn add(self, rhs: u32) -> Wrapper {
3501 let wrapped = Wrapper(10);
3503 let res = wrapped + num;
3509 192..196 'self': Wrapper
3511 219..247 '{ ... }': Wrapper
3512 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3513 229..241 'Wrapper(rhs)': Wrapper
3515 259..345 '{ ...um; }': ()
3516 269..276 'wrapped': Wrapper
3517 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3518 279..290 'Wrapper(10)': Wrapper
3522 322..325 'res': Wrapper
3523 328..335 'wrapped': Wrapper
3524 328..341 'wrapped + num': Wrapper
3536 fn do_thing(&self) -> Self::Output;
3539 impl T for [u8; 4] {
3540 type Output = usize;
3541 fn do_thing(&self) -> Self::Output {
3546 impl T for [u8; 2] {
3548 fn do_thing(&self) -> Self::Output {
3555 let v2 = v.do_thing();
3557 let v4 = v3.do_thing();
3561 44..48 'self': &Self
3562 133..137 'self': &[u8; 4]
3563 155..172 '{ ... }': usize
3565 236..240 'self': &[u8; 2]
3566 258..275 '{ ... }': u8
3568 289..392 '{ ...g(); }': ()
3569 299..300 'v': [u8; 2]
3570 303..311 '[0u8; 2]': [u8; 2]
3574 326..327 'v': [u8; 2]
3575 326..338 'v.do_thing()': u8
3576 348..350 'v3': [u8; 4]
3577 353..361 '[0u8; 4]': [u8; 4]
3580 371..373 'v4': usize
3581 376..378 'v3': [u8; 4]
3582 376..389 'v3.do_thing()': usize
3587 // FIXME: We should infer the length of the returned array :)
3589 fn const_generics() {
3594 fn do_thing(&self) -> Self::Output;
3597 impl<const L: usize> T for [u8; L] {
3598 type Output = [u8; L];
3599 fn do_thing(&self) -> Self::Output {
3606 let v2 = v.do_thing();
3610 44..48 'self': &Self
3611 151..155 'self': &[u8; _]
3612 173..194 '{ ... }': [u8; _]
3613 183..188 '*self': [u8; _]
3614 184..188 'self': &[u8; _]
3615 208..260 '{ ...g(); }': ()
3616 218..219 'v': [u8; 2]
3617 222..230 '[0u8; 2]': [u8; 2]
3620 240..242 'v2': [u8; _]
3621 245..246 'v': [u8; 2]
3622 245..257 'v.do_thing()': [u8; _]
3628 fn fn_returning_unit() {
3629 check_infer_with_mismatches(
3632 trait FnOnce<Args> {
3636 fn test<F: FnOnce()>(f: F) {
3641 88..112 '{ ...f(); }': ()
3650 fn trait_in_scope_of_trait_impl() {
3656 fn bar(self) -> usize { 0 }
3659 impl foo::Foo for u32 {
3661 let _x = self.bar();
3668 82..87 '{ 0 }': usize
3670 131..135 'self': u32
3671 137..173 '{ ... }': ()
3672 151..153 '_x': usize
3673 156..160 'self': u32
3674 156..166 'self.bar()': usize
3680 fn infer_async_ret_type() {
3683 //- /main.rs crate:main deps:core
3696 fn collect<B: Convert>(self) -> B {
3704 impl Convert for u32 {
3710 async fn get_accounts() -> Result<u32, ()> {
3711 let ret = Fooey.collect();
3716 //- /core.rs crate:core
3717 #[prelude_import] use future::*;
3719 #[lang = "future_trait"]