2 use expect_test::expect;
4 use super::{check, check_infer, check_infer_with_mismatches, check_types};
13 impl core::future::Future for IntFuture {
31 async fn foo() -> u64 { 128 }
43 fn infer_desugar_async() {
46 //- minicore: future, sized
47 async fn foo() -> u64 { 128 }
52 } //^ impl Future<Output = u64>
58 fn infer_async_block() {
61 //- minicore: future, option
65 // ^ impl Future<Output = i32>
69 let b = async {}.await;
77 let _: Option<u64> = c.await;
79 // ^ impl Future<Output = Option<u64>>
89 //- /main.rs crate:main deps:core
91 let r: Result<i32, u64> = Result::Ok(1);
96 //- /core.rs crate:core
105 pub enum Result<O, E> {
110 impl<O, E> crate::ops::Try for Result<O, E> {
118 pub use crate::{result::*, ops::*};
126 fn infer_try_trait_v2() {
129 //- /main.rs crate:main deps:core
131 let r: Result<i32, u64> = Result::Ok(1);
136 //- /core.rs crate:core
139 pub trait Try: FromResidual {
143 pub trait FromResidual<R = <Self as Try>::Residual> {}
146 pub use self::try_trait::FromResidual;
147 pub use self::try_trait::Try;
152 impl<T> From<T> for T {}
156 use crate::convert::From;
157 use crate::ops::{Try, FromResidual};
159 pub enum Infallible {}
160 pub enum Result<O, E> {
165 impl<O, E> Try for Result<O, E> {
167 type Error = Result<Infallible, E>;
170 impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
175 pub use crate::result::*;
183 fn infer_for_loop() {
186 //- /main.rs crate:main deps:core,alloc
188 use alloc::collections::Vec;
198 //- /core.rs crate:core
200 pub trait IntoIterator {
206 pub use crate::iter::*;
210 //- /alloc.rs crate:alloc deps:core
212 pub mod collections {
215 pub fn new() -> Self { Vec {} }
216 pub fn push(&mut self, t: T) { }
219 impl<T> IntoIterator for Vec<T> {
231 //- /main.rs crate:main deps:std
235 impl std::ops::Neg for Bar {
245 //- /std.rs crate:std
246 #[prelude_import] use ops::*;
261 //- /main.rs crate:main deps:std
265 impl std::ops::Not for Bar {
275 //- /std.rs crate:std
276 #[prelude_import] use ops::*;
288 fn infer_from_bound_1() {
293 impl<U> Trait<U> for S<U> {}
294 fn foo<T: Trait<u32>>(t: T) {}
304 fn infer_from_bound_2() {
309 impl<U> Trait<U> for S<U> {}
310 fn foo<U, T: Trait<U>>(t: T) -> U { loop {} }
320 fn trait_default_method_self_bound_implements_trait() {
321 cov_mark::check!(trait_self_implements_self);
325 fn foo(&self) -> i64;
326 fn bar(&self) -> () {
328 // ^^^^^^^^^^ type: i64
335 fn trait_default_method_self_bound_implements_super_trait() {
339 fn foo(&self) -> i64;
341 trait Trait: SuperTrait {
342 fn bar(&self) -> () {
344 // ^^^^^^^^^^ type: i64
351 fn infer_project_associated_type() {
358 impl Iterable for S { type Item = u32; }
359 fn test<T: Iterable>() {
360 let x: <S as Iterable>::Item = 1;
362 let y: <T as Iterable>::Item = u;
363 // ^ Iterable::Item<T>
365 // ^ Iterable::Item<T>
366 let a: <T>::Item = u;
367 // ^ Iterable::Item<T>
373 fn infer_return_associated_type() {
380 impl Iterable for S { type Item = u32; }
381 fn foo1<T: Iterable>(t: T) -> T::Item { loop {} }
382 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item { loop {} }
383 fn foo3<T: Iterable>(t: T) -> <T>::Item { loop {} }
396 fn infer_associated_type_bound() {
402 fn test<T: Iterable<Item=u32>>() {
403 let y: T::Item = unknown;
410 fn infer_const_body() {
411 // FIXME make check_types work with other bodies
414 const A: u32 = 1 + 1;
415 static B: u64 = { let x = 1; x };
421 38..54 '{ let ...1; x }': u64
430 fn tuple_struct_fields() {
440 37..86 '{ ... a.1 }': u64
442 51..52 'S': S(i32, u64) -> S
456 fn tuple_struct_with_fn() {
459 struct S(fn(u32) -> u64);
466 43..101 '{ ...0(2) }': u64
468 57..58 'S': S(fn(u32) -> u64) -> S
469 57..67 'S(|i| 2*i)': S
470 59..66 '|i| 2*i': |u32| -> u64
477 81..84 'a.0': fn(u32) -> u64
481 93..96 'a.0': fn(u32) -> u64
489 fn indexing_arrays() {
491 "fn main() { &mut [9][2]; }",
493 10..26 '{ &mut...[2]; }': ()
494 12..23 '&mut [9][2]': &mut {unknown}
495 17..20 '[9]': [i32; 1]
496 17..23 '[9][2]': {unknown}
504 fn infer_ops_index() {
511 impl core::ops::Index<u32> for Bar {
525 fn infer_ops_index_int() {
532 impl core::ops::Index<u32> for Bar {
537 impl core::ops::Index<Range> for Bar {
552 fn infer_ops_index_autoderef() {
555 //- minicore: index, slice
557 let a = &[1u32, 2, 3];
570 struct Arc<T: ?Sized>;
571 impl<T: ?Sized> core::ops::Deref for Arc<T> {
577 fn foo(&self) -> u128 { 0 }
582 } //^^^^^^^^^^^^^ (S, u128)
588 fn deref_trait_with_inference_var() {
592 struct Arc<T: ?Sized>;
593 fn new_arc<T: ?Sized>() -> Arc<T> { Arc }
594 impl<T: ?Sized> core::ops::Deref for Arc<T> {
612 fn deref_trait_infinite_recursion() {
618 impl core::ops::Deref for S {
624 } //^^^^^^^ {unknown}
630 fn deref_trait_with_question_mark_size() {
634 struct Arc<T: ?Sized>;
635 impl<T: ?Sized> core::ops::Deref for Arc<T> {
641 fn foo(&self) -> u128 { 0 }
646 } //^^^^^^^^^^^^^ (S, u128)
652 fn deref_trait_with_implicit_sized_requirement_on_inference_var() {
657 impl<T> core::ops::Deref for Foo<T> {
664 let _: Foo<u8> = foo;
671 fn obligation_from_function_clause() {
677 impl Trait<u32> for S {}
679 fn foo<T: Trait<U>, U>(t: T) -> U { loop {} }
689 fn obligation_from_method_clause() {
696 impl Trait<isize> for S {}
700 fn foo<T: Trait<U>, U>(&self, t: T) -> U { loop {} }
711 fn obligation_from_self_method_clause() {
717 impl Trait<i64> for S {}
720 fn foo<U>(&self) -> U where Self: Trait<U> { loop {} }
731 fn obligation_from_impl_clause() {
737 impl Trait<&str> for S {}
740 impl<U, T: Trait<U>> O<T> {
741 fn foo(&self) -> U { loop {} }
752 fn generic_param_env_1() {
756 trait Trait { fn foo(self) -> u128; }
759 impl<T> Trait for T where T: Clone {}
760 fn test<T: Clone>(t: T) { t.foo(); }
767 fn generic_param_env_1_not_met() {
772 trait Trait { fn foo(self) -> u128; }
775 impl<T> Trait for T where T: Clone {}
776 fn test<T>(t: T) { t.foo(); }
783 fn generic_param_env_2() {
786 trait Trait { fn foo(self) -> u128; }
789 fn test<T: Trait>(t: T) { t.foo(); }
796 fn generic_param_env_2_not_met() {
799 trait Trait { fn foo(self) -> u128; }
802 fn test<T>(t: T) { t.foo(); }
809 fn generic_param_env_deref() {
814 impl<T> core::ops::Deref for T where T: Trait {
817 fn test<T: Trait>(t: T) { *t; }
824 fn associated_type_placeholder() {
825 // 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].
832 pub struct RefMutL<T>;
834 impl<T> ApplyL for RefMutL<T> {
835 type Out = <T as ApplyL>::Out;
838 fn test<T: ApplyL>() {
839 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
847 fn associated_type_placeholder_2() {
853 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
855 fn test<T: ApplyL>(t: T) {
864 fn argument_impl_trait() {
865 check_infer_with_mismatches(
870 fn foo2(&self) -> i64;
872 fn bar(x: impl Trait<u16>) {}
874 impl<T> Trait<T> for S<T> {}
876 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
891 77..78 'x': impl Trait<u16>
893 154..155 'x': impl Trait<u64>
894 174..175 'y': &impl Trait<u32>
895 195..323 '{ ...2(); }': ()
896 201..202 'x': impl Trait<u64>
897 208..209 'y': &impl Trait<u32>
899 223..224 'S': S<u16>(u16) -> S<u16>
900 223..227 'S(1)': S<u16>
902 233..236 'bar': fn bar(S<u16>)
903 233..239 'bar(z)': ()
905 245..246 'x': impl Trait<u64>
906 245..252 'x.foo()': u64
907 258..259 'y': &impl Trait<u32>
908 258..265 'y.foo()': u32
910 271..278 'z.foo()': u16
911 284..285 'x': impl Trait<u64>
912 284..292 'x.foo2()': i64
913 298..299 'y': &impl Trait<u32>
914 298..306 'y.foo2()': i64
916 312..320 'z.foo2()': i64
922 fn argument_impl_trait_type_args_1() {
923 check_infer_with_mismatches(
928 // this function has an implicit Self param, an explicit type param,
929 // and an implicit impl Trait param!
930 fn bar<T>(x: impl Trait) -> T { loop {} }
932 fn foo<T>(x: impl Trait) -> T { loop {} }
943 <F as Foo>::bar::<u32>(S);
947 foo::<u32, i32>(S); // we should ignore the extraneous i32
950 155..156 'x': impl Trait
951 175..186 '{ loop {} }': T
952 177..184 'loop {}': !
954 199..200 'x': impl Trait
955 219..230 '{ loop {} }': T
956 221..228 'loop {}': !
958 300..509 '{ ... i32 }': ()
959 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
960 306..317 'Foo::bar(S)': {unknown}
962 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
963 323..341 '<F as ...bar(S)': {unknown}
965 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
966 347..356 'F::bar(S)': {unknown}
968 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
969 362..380 'Foo::b...32>(S)': u32
971 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
972 386..411 '<F as ...32>(S)': u32
974 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
975 418..424 'foo(S)': {unknown}
977 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
978 430..443 'foo::<u32>(S)': u32
980 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
981 449..467 'foo::<...32>(S)': u32
988 fn argument_impl_trait_type_args_2() {
989 check_infer_with_mismatches(
997 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1003 F::<u32>.foo::<i32>(S);
1004 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1008 93..94 'x': impl Trait
1009 118..129 '{ loop {} }': (T, U)
1010 120..127 'loop {}': !
1012 143..283 '{ ...ored }': ()
1013 149..150 'F': F<{unknown}>
1014 149..157 'F.foo(S)': ({unknown}, {unknown})
1016 163..171 'F::<u32>': F<u32>
1017 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1019 184..192 'F::<u32>': F<u32>
1020 184..206 'F::<u3...32>(S)': (u32, i32)
1022 212..220 'F::<u32>': F<u32>
1023 212..239 'F::<u3...32>(S)': (u32, i32)
1030 fn argument_impl_trait_to_fn_pointer() {
1031 check_infer_with_mismatches(
1035 fn foo(x: impl Trait) { loop {} }
1040 let f: fn(S) -> () = foo;
1043 22..23 'x': impl Trait
1044 37..48 '{ loop {} }': ()
1047 90..123 '{ ...foo; }': ()
1049 117..120 'foo': fn foo(S)
1061 fn foo2(&self) -> i64;
1063 fn bar() -> impl Trait<u64> {}
1065 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1077 29..33 'self': &Self
1078 54..58 'self': &Self
1080 110..111 'x': impl Trait<u64>
1081 130..131 'y': &impl Trait<u64>
1082 151..268 '{ ...2(); }': ()
1083 157..158 'x': impl Trait<u64>
1084 164..165 'y': &impl Trait<u64>
1085 175..176 'z': impl Trait<u64>
1086 179..182 'bar': fn bar() -> impl Trait<u64>
1087 179..184 'bar()': impl Trait<u64>
1088 190..191 'x': impl Trait<u64>
1089 190..197 'x.foo()': u64
1090 203..204 'y': &impl Trait<u64>
1091 203..210 'y.foo()': u64
1092 216..217 'z': impl Trait<u64>
1093 216..223 'z.foo()': u64
1094 229..230 'x': impl Trait<u64>
1095 229..237 'x.foo2()': i64
1096 243..244 'y': &impl Trait<u64>
1097 243..251 'y.foo2()': i64
1098 257..258 'z': impl Trait<u64>
1099 257..265 'z.foo2()': i64
1105 fn simple_return_pos_impl_trait() {
1106 cov_mark::check!(lower_rpit);
1113 fn bar() -> impl Trait<u64> { loop {} }
1120 29..33 'self': &Self
1121 71..82 '{ loop {} }': !
1124 94..129 '{ ...o(); }': ()
1125 104..105 'a': impl Trait<u64>
1126 108..111 'bar': fn bar() -> impl Trait<u64>
1127 108..113 'bar()': impl Trait<u64>
1128 119..120 'a': impl Trait<u64>
1129 119..126 'a.foo()': u64
1135 fn more_return_pos_impl_trait() {
1141 fn next(&mut self) -> Self::Item;
1146 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1147 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1153 let (c, d) = baz(1u128);
1158 49..53 'self': &mut Self
1159 101..105 'self': &Self
1160 184..195 '{ loop {} }': ({unknown}, {unknown})
1161 186..193 'loop {}': !
1164 268..279 '{ loop {} }': ({unknown}, {unknown})
1165 270..277 'loop {}': !
1167 291..413 '{ ...o(); }': ()
1168 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1169 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1170 305..306 'b': impl Trait<u64>
1171 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1172 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1173 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1174 321..329 'a.next()': impl Trait<u32>
1175 321..335 'a.next().foo()': u32
1176 341..342 'b': impl Trait<u64>
1177 341..348 'b.foo()': u64
1178 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1179 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1180 362..363 'd': impl Trait<u128>
1181 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1182 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1183 371..376 '1u128': u128
1184 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1185 383..391 'c.next()': impl Trait<u128>
1186 383..397 'c.next().foo()': u128
1187 403..404 'd': impl Trait<u128>
1188 403..410 'd.foo()': u128
1200 fn foo2(&self) -> i64;
1202 fn bar() -> dyn Trait<u64> {}
1204 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1216 29..33 'self': &Self
1217 54..58 'self': &Self
1219 109..110 'x': dyn Trait<u64>
1220 128..129 'y': &dyn Trait<u64>
1221 148..265 '{ ...2(); }': ()
1222 154..155 'x': dyn Trait<u64>
1223 161..162 'y': &dyn Trait<u64>
1224 172..173 'z': dyn Trait<u64>
1225 176..179 'bar': fn bar() -> dyn Trait<u64>
1226 176..181 'bar()': dyn Trait<u64>
1227 187..188 'x': dyn Trait<u64>
1228 187..194 'x.foo()': u64
1229 200..201 'y': &dyn Trait<u64>
1230 200..207 'y.foo()': u64
1231 213..214 'z': dyn Trait<u64>
1232 213..220 'z.foo()': u64
1233 226..227 'x': dyn Trait<u64>
1234 226..234 'x.foo2()': i64
1235 240..241 'y': &dyn Trait<u64>
1236 240..248 'y.foo2()': i64
1237 254..255 'z': dyn Trait<u64>
1238 254..262 'z.foo2()': i64
1244 fn dyn_trait_in_impl() {
1249 fn foo(&self) -> (T, U);
1252 impl<T, U> S<T, U> {
1253 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1255 trait Trait2<T, U> {
1256 fn baz(&self) -> (T, U);
1258 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1260 fn test(s: S<u32, i32>) {
1264 32..36 'self': &Self
1265 102..106 'self': &S<T, U>
1266 128..139 '{ loop {} }': &dyn Trait<T, U>
1267 130..137 'loop {}': !
1269 175..179 'self': &Self
1270 251..252 's': S<u32, i32>
1271 267..289 '{ ...z(); }': ()
1272 273..274 's': S<u32, i32>
1273 273..280 's.bar()': &dyn Trait<u32, i32>
1274 273..286 's.bar().baz()': (u32, i32)
1280 fn dyn_trait_bare() {
1285 fn foo(&self) -> u64;
1287 fn bar() -> Trait {}
1289 fn test(x: Trait, y: &Trait) -> u64 {
1298 26..30 'self': &Self
1300 72..73 'x': dyn Trait
1301 82..83 'y': &dyn Trait
1302 100..175 '{ ...o(); }': ()
1303 106..107 'x': dyn Trait
1304 113..114 'y': &dyn Trait
1305 124..125 'z': dyn Trait
1306 128..131 'bar': fn bar() -> dyn Trait
1307 128..133 'bar()': dyn Trait
1308 139..140 'x': dyn Trait
1309 139..146 'x.foo()': u64
1310 152..153 'y': &dyn Trait
1311 152..159 'y.foo()': u64
1312 165..166 'z': dyn Trait
1313 165..172 'z.foo()': u64
1325 a: impl Trait + 'lifetime,
1328 d: impl ('lifetime),
1330 f: impl Trait + ?Sized
1334 28..29 'a': impl Trait
1335 59..60 'b': impl Sized
1336 82..83 'c': impl Trait
1337 103..104 'd': impl Sized
1338 128..129 'e': impl ?Sized
1339 148..149 'f': impl Trait + ?Sized
1346 fn error_bound_chalk() {
1350 fn foo(&self) -> u32 { 0 }
1353 fn test(x: (impl Trait + UnknownTrait)) {
1361 fn assoc_type_bindings() {
1369 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1370 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1371 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1374 impl<T> Trait for S<T> { type Type = T; }
1376 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1394 262..263 'y': impl Trait<Type = i64>
1395 289..397 '{ ...r>); }': ()
1396 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1397 295..301 'get(x)': u32
1399 307..311 'get2': fn get2<u32, T>(T) -> u32
1400 307..314 'get2(x)': u32
1402 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1403 320..326 'get(y)': i64
1404 324..325 'y': impl Trait<Type = i64>
1405 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1406 332..339 'get2(y)': i64
1407 337..338 'y': impl Trait<Type = i64>
1408 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1409 345..356 'get(set(S))': u64
1410 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1411 349..355 'set(S)': S<u64>
1412 353..354 'S': S<u64>
1413 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1414 362..374 'get2(set(S))': u64
1415 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1416 367..373 'set(S)': S<u64>
1417 371..372 'S': S<u64>
1418 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1419 380..394 'get2(S::<str>)': str
1420 385..393 'S::<str>': S<str>
1426 fn impl_trait_assoc_binding_projection_bug() {
1429 //- minicore: iterator
1430 pub trait Language {
1433 pub enum RustLanguage {}
1434 impl Language for RustLanguage {
1435 type Kind = SyntaxKind;
1437 struct SyntaxNode<L> {}
1438 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1441 fn clone(&self) -> Self;
1444 fn api_walkthrough() {
1447 } //^^^^^^^^^^^^ {unknown}
1454 fn projection_eq_within_chalk() {
1463 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1465 fn test<T: Trait1<Type = u32>>(x: T) {
1471 169..185 '{ ...o(); }': ()
1473 175..182 'x.foo()': u32
1479 fn where_clause_trait_in_scope_for_method_resolution() {
1484 fn foo(&self) -> u32 { 0 }
1488 fn test<T: foo::Trait>(x: T) {
1496 fn super_trait_method_resolution() {
1501 fn foo(&self) -> u32 {}
1504 trait Trait1: foo::SuperTrait {}
1505 trait Trait2 where Self: foo::SuperTrait {}
1507 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1512 49..53 'self': &Self
1516 193..222 '{ ...o(); }': ()
1518 199..206 'x.foo()': u32
1520 212..219 'y.foo()': u32
1526 fn super_trait_impl_trait_method_resolution() {
1532 fn foo(&self) -> u32 {}
1535 trait Trait1: foo::SuperTrait {}
1537 fn test(x: &impl Trait1) {
1541 49..53 'self': &Self
1543 115..116 'x': &impl Trait1
1544 132..148 '{ ...o(); }': ()
1545 138..139 'x': &impl Trait1
1546 138..145 'x.foo()': u32
1552 fn super_trait_cycle() {
1553 // This just needs to not crash
1559 fn test<T: A>(x: T) {
1565 49..65 '{ ...o(); }': ()
1567 55..62 'x.foo()': {unknown}
1573 fn super_trait_assoc_type_bounds() {
1576 trait SuperTrait { type Type; }
1577 trait Trait where Self: SuperTrait {}
1579 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1580 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1583 impl<T> SuperTrait for S<T> { type Type = T; }
1584 impl<T> Trait for S<T> {}
1595 258..279 '{ ...S)); }': ()
1596 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1597 264..276 'get2(set(S))': u64
1598 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1599 269..275 'set(S)': S<u64>
1600 273..274 'S': S<u64>
1607 check_infer_with_mismatches(
1609 trait FnOnce<Args> {
1612 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1615 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1616 f.call_once((1, 2));
1622 155..183 '{ ...2)); }': ()
1624 161..180 'f.call...1, 2))': u128
1625 173..179 '(1, 2)': (u32, u64)
1633 fn fn_ptr_and_item() {
1634 check_infer_with_mismatches(
1637 trait FnOnce<Args> {
1640 fn call_once(self, args: Args) -> Self::Output;
1649 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1650 fn foo(&self) -> (A1, R) { loop {} }
1653 enum Opt<T> { None, Some(T) }
1655 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1659 let bar: Bar<fn(u8) -> u32>;
1663 let f: fn(u8) -> u32;
1669 139..143 'self': &Self
1670 243..247 'self': &Bar<F>
1671 260..271 '{ loop {} }': (A1, R)
1672 262..269 'loop {}': !
1674 355..359 'self': Opt<T>
1676 377..388 '{ loop {} }': Opt<U>
1677 379..386 'loop {}': !
1679 402..518 '{ ...(f); }': ()
1680 412..415 'bar': Bar<fn(u8) -> u32>
1681 441..444 'bar': Bar<fn(u8) -> u32>
1682 441..450 'bar.foo()': (u8, u32)
1683 461..464 'opt': Opt<u8>
1684 483..484 'f': fn(u8) -> u32
1685 505..508 'opt': Opt<u8>
1686 505..515 'opt.map(f)': Opt<u32>
1687 513..514 'f': fn(u8) -> u32
1693 fn fn_trait_deref_with_ty_default() {
1696 //- minicore: deref, fn
1700 fn foo(&self) -> usize {}
1703 struct Lazy<T, F = fn() -> T>(F);
1705 impl<T, F> Lazy<T, F> {
1706 pub fn new(f: F) -> Lazy<T, F> {}
1709 impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> {
1714 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1715 let r1 = lazy1.foo();
1717 fn make_foo_fn() -> Foo {}
1718 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1719 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1720 let r2 = lazy2.foo();
1727 251..497 '{ ...o(); }': ()
1728 261..266 'lazy1': Lazy<Foo, || -> Foo>
1729 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1730 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1731 293..299 '|| Foo': || -> Foo
1733 310..312 'r1': usize
1734 315..320 'lazy1': Lazy<Foo, || -> Foo>
1735 315..326 'lazy1.foo()': usize
1736 368..383 'make_foo_fn_ptr': fn() -> Foo
1737 399..410 'make_foo_fn': fn make_foo_fn() -> Foo
1738 420..425 'lazy2': Lazy<Foo, fn() -> Foo>
1739 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1740 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1741 452..467 'make_foo_fn_ptr': fn() -> Foo
1742 478..480 'r2': usize
1743 483..488 'lazy2': Lazy<Foo, fn() -> Foo>
1744 483..494 'lazy2.foo()': usize
1752 check_infer_with_mismatches(
1755 enum Option<T> { Some(T), None }
1757 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1761 let x = Option::Some(1u32);
1764 let y: Option<i64> = x.map(|_v| 1);
1767 86..90 'self': Option<T>
1769 111..122 '{ loop {} }': Option<U>
1770 113..120 'loop {}': !
1772 136..255 '{ ... 1); }': ()
1773 146..147 'x': Option<u32>
1774 150..162 'Option::Some': Some<u32>(u32) -> Option<u32>
1775 150..168 'Option...(1u32)': Option<u32>
1776 163..167 '1u32': u32
1777 174..175 'x': Option<u32>
1778 174..190 'x.map(...v + 1)': Option<u32>
1779 180..189 '|v| v + 1': |u32| -> u32
1782 184..189 'v + 1': u32
1784 196..197 'x': Option<u32>
1785 196..212 'x.map(... 1u64)': Option<u64>
1786 202..211 '|_v| 1u64': |u32| -> u64
1788 207..211 '1u64': u64
1789 222..223 'y': Option<i64>
1790 239..240 'x': Option<u32>
1791 239..252 'x.map(|_v| 1)': Option<i64>
1792 245..251 '|_v| 1': |u32| -> i64
1803 //- minicore: add, fn
1805 impl core::ops::Add for u64 {
1807 fn add(self, rhs: u64) -> Self::Output {0}
1810 impl core::ops::Add for u128 {
1812 fn add(self, rhs: u128) -> Self::Output {0}
1815 fn test<F: FnOnce(u32) -> u64>(f: F) {
1821 //^^^^^^^^^ |u64| -> u64
1824 let h = |v| 1u128 + v;
1825 //^^^^^^^^^^^^^ |u128| -> u128
1831 fn closure_as_argument_inference_order() {
1832 check_infer_with_mismatches(
1835 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
1836 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
1840 fn method(self) -> u64;
1842 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
1843 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
1847 let x1 = foo1(S, |s| s.method());
1848 let x2 = foo2(|s| s.method(), S);
1849 let x3 = S.foo1(S, |s| s.method());
1850 let x4 = S.foo2(|s| s.method(), S);
1855 50..61 '{ loop {} }': U
1860 112..123 '{ loop {} }': U
1861 114..121 'loop {}': !
1867 233..244 '{ loop {} }': U
1868 235..242 'loop {}': !
1873 305..316 '{ loop {} }': U
1874 307..314 'loop {}': !
1876 330..489 '{ ... S); }': ()
1878 345..349 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
1879 345..368 'foo1(S...hod())': u64
1881 353..367 '|s| s.method()': |S| -> u64
1884 357..367 's.method()': u64
1886 383..387 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
1887 383..406 'foo2(|...(), S)': u64
1888 388..402 '|s| s.method()': |S| -> u64
1891 392..402 's.method()': u64
1895 421..446 'S.foo1...hod())': u64
1897 431..445 '|s| s.method()': |S| -> u64
1900 435..445 's.method()': u64
1903 461..486 'S.foo2...(), S)': u64
1904 468..482 '|s| s.method()': |S| -> u64
1907 472..482 's.method()': u64
1914 fn fn_item_fn_trait() {
1922 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
1926 } //^^^^^^^^^^^^^^^^^^ S
1932 fn unselected_projection_in_trait_env_1() {
1941 fn foo(&self) -> u32;
1944 fn test<T: Trait>() where T::Item: Trait2 {
1945 let x: T::Item = no_matter;
1953 fn unselected_projection_in_trait_env_2() {
1961 fn foo(&self) -> u32;
1964 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
1965 let x: T::Item = no_matter;
1973 fn unselected_projection_on_impl_self() {
1980 fn f(&self, x: Self::Item);
1987 fn f(&self, x: Self::Item) { let y = x; }
1994 fn f(&self, x: <Self>::Item) { let y = x; }
1997 40..44 'self': &Self
1998 46..47 'x': Trait::Item<Self>
2001 147..161 '{ let y = x; }': ()
2004 228..232 'self': &S2
2006 251..265 '{ let y = x; }': ()
2014 fn unselected_projection_on_trait_self() {
2020 fn f(&self) -> Self::Item { loop {} }
2036 fn unselected_projection_chalk_fold() {
2040 trait Fold<I: Interner, TI = I> {
2044 struct Ty<I: Interner> {}
2045 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2046 type Result = Ty<TI>;
2049 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2056 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2058 } //^^^^^^^^^^^^^^^^^ Ty<I>
2064 fn trait_impl_self_ty() {
2073 impl Trait<Self> for S {}
2083 fn trait_impl_self_ty_cycle() {
2092 impl Trait for S<Self> {}
2096 } //^^^^^^^ {unknown}
2102 fn unselected_projection_in_trait_env_cycle_1() {
2103 // This is not a cycle, because the `T: Trait2<T::Item>` bound depends only on the `T: Trait`
2104 // bound, not on itself (since only `Trait` can define `Item`).
2113 fn test<T: Trait>() where T: Trait2<T::Item> {
2114 let x: T::Item = no_matter;
2115 } //^^^^^^^^^ Trait::Item<T>
2121 fn unselected_projection_in_trait_env_cycle_2() {
2122 // this is a legitimate cycle
2130 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2131 let x: T::Item = no_matter;
2132 } //^^^^^^^^^ {unknown}
2138 fn unselected_projection_in_trait_env_cycle_3() {
2139 // this is a cycle for rustc; we currently accept it
2148 fn test<T>() where T: Trait<OtherItem = T::Item> {
2149 let x: T::Item = no_matter;
2150 } //^^^^^^^^^ Trait::Item<T>
2156 fn unselected_projection_in_trait_env_no_cycle() {
2157 // this is not a cycle
2165 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2167 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2170 fn len(&self) -> usize;
2173 pub trait UnificationStoreMut: UnificationStoreBase {
2174 fn push(&mut self, value: Self::Key);
2177 fn test<T>(t: T) where T: UnificationStoreMut {
2182 } //^^^^^^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2188 fn inline_assoc_type_bounds_1() {
2194 trait OtherTrait<T> {
2198 // workaround for Chalk assoc type normalization problems
2200 impl<T: Iterator> Iterator for S<T> {
2201 type Item = <T as Iterator>::Item;
2204 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2205 let x: <S<I> as Iterator>::Item;
2213 fn inline_assoc_type_bounds_2() {
2220 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2221 let x: <<I as Iterator>::Item as Iterator>::Item;
2229 fn proc_macro_server_types() {
2232 macro_rules! with_api {
2233 ($S:ident, $self:ident, $m:ident) => {
2236 fn new() -> $S::TokenStream;
2243 macro_rules! associated_item {
2244 (type TokenStream) =>
2245 (type TokenStream: 'static;);
2247 (type Group: 'static;);
2248 ($($item:tt)*) => ($($item)*;)
2250 macro_rules! declare_server_traits {
2252 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2255 $(associated_item!(type $name);)*
2258 $(pub trait $name: Types {
2259 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2262 pub trait Server: Types $(+ $name)* {}
2263 impl<S: Types $(+ $name)*> Server for S {}
2267 with_api!(Self, self_, declare_server_traits);
2271 impl Types for Rustc {
2272 type TokenStream = T;
2276 fn make<T>() -> T { loop {} }
2277 impl TokenStream for Rustc {
2278 fn new() -> Self::TokenStream {
2279 let group: Self::Group = make();
2284 1061..1072 '{ loop {} }': T
2285 1063..1070 'loop {}': !
2287 1136..1199 '{ ... }': T
2288 1150..1155 'group': G
2289 1171..1175 'make': fn make<G>() -> G
2290 1171..1177 'make()': G
2291 1187..1191 'make': fn make<T>() -> T
2292 1187..1193 'make()': T
2298 fn unify_impl_trait() {
2299 check_infer_with_mismatches(
2304 fn foo(x: impl Trait<u32>) { loop {} }
2305 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2308 impl<T> Trait<T> for S<T> {}
2310 fn default<T>() -> T { loop {} }
2312 fn test() -> impl Trait<i32> {
2313 let s1 = S(default());
2315 let x: i32 = bar(S(default()));
2319 26..27 'x': impl Trait<u32>
2320 46..57 '{ loop {} }': ()
2323 68..69 'x': impl Trait<T>
2324 91..102 '{ loop {} }': T
2325 93..100 'loop {}': !
2327 171..182 '{ loop {} }': T
2328 173..180 'loop {}': !
2330 213..309 '{ ...t()) }': S<{unknown}>
2331 223..225 's1': S<u32>
2332 228..229 'S': S<u32>(u32) -> S<u32>
2333 228..240 'S(default())': S<u32>
2334 230..237 'default': fn default<u32>() -> u32
2335 230..239 'default()': u32
2336 246..249 'foo': fn foo(S<u32>)
2337 246..253 'foo(s1)': ()
2338 250..252 's1': S<u32>
2340 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2341 272..289 'bar(S(...lt()))': i32
2342 276..277 'S': S<i32>(i32) -> S<i32>
2343 276..288 'S(default())': S<i32>
2344 278..285 'default': fn default<i32>() -> i32
2345 278..287 'default()': i32
2346 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2347 295..307 'S(default())': S<{unknown}>
2348 297..304 'default': fn default<{unknown}>() -> {unknown}
2349 297..306 'default()': {unknown}
2355 fn assoc_types_from_bounds() {
2374 f::<(), _>(|z| { z; });
2379 132..163 '{ ... }); }': ()
2380 138..148 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2381 138..160 'f::<()... z; })': ()
2382 149..159 '|z| { z; }': |&()| -> ()
2384 153..159 '{ z; }': ()
2391 fn associated_type_bound() {
2395 type Item: OtherTrait<u32>;
2397 pub trait OtherTrait<T> {
2401 // this is just a workaround for chalk#234
2403 impl<T: Trait> Trait for S<T> {
2404 type Item = <T as Trait>::Item;
2407 fn test<T: Trait>() {
2408 let y: <S<T> as Trait>::Item = no_matter;
2416 fn dyn_trait_through_chalk() {
2420 struct Box<T: ?Sized> {}
2421 impl<T: ?Sized> core::ops::Deref for Box<T> {
2428 fn test(x: Box<dyn Trait>) {
2436 fn string_to_owned() {
2442 fn to_owned(&self) -> Self::Owned;
2444 impl ToOwned for str {
2445 type Owned = String;
2449 } //^^^^^^^^^^^^^^^^ String
2455 fn iterator_chain() {
2456 check_infer_with_mismatches(
2458 //- minicore: fn, option
2459 pub trait Iterator {
2462 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2464 F: FnMut(Self::Item) -> Option<B>,
2467 fn for_each<F>(self, f: F)
2469 F: FnMut(Self::Item),
2473 pub trait IntoIterator {
2475 type IntoIter: Iterator<Item = Self::Item>;
2476 fn into_iter(self) -> Self::IntoIter;
2479 pub struct FilterMap<I, F> { }
2480 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2482 F: FnMut(I::Item) -> Option<B>,
2487 #[stable(feature = "rust1", since = "1.0.0")]
2488 impl<I: Iterator> IntoIterator for I {
2489 type Item = I::Item;
2492 fn into_iter(self) -> I {
2499 fn new() -> Self { loop {} }
2502 impl<T> IntoIterator for Vec<T> {
2504 type IntoIter = IntoIter<T>;
2507 pub struct IntoIter<T> { }
2508 impl<T> Iterator for IntoIter<T> {
2513 Vec::<i32>::new().into_iter()
2514 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2515 .for_each(|y| { y; });
2520 152..163 '{ loop {} }': FilterMap<Self, F>
2521 154..161 'loop {}': !
2523 184..188 'self': Self
2525 240..251 '{ loop {} }': ()
2526 242..249 'loop {}': !
2528 360..364 'self': Self
2530 700..720 '{ ... }': I
2532 779..790 '{ loop {} }': Vec<T>
2533 781..788 'loop {}': !
2535 977..1104 '{ ... }); }': ()
2536 983..998 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2537 983..1000 'Vec::<...:new()': Vec<i32>
2538 983..1012 'Vec::<...iter()': IntoIter<i32>
2539 983..1075 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2540 983..1101 'Vec::<... y; })': ()
2541 1029..1074 '|x| if...None }': |i32| -> Option<u32>
2543 1033..1074 'if x >...None }': Option<u32>
2545 1036..1041 'x > 0': bool
2547 1042..1060 '{ Some...u32) }': Option<u32>
2548 1044..1048 'Some': Some<u32>(u32) -> Option<u32>
2549 1044..1058 'Some(x as u32)': Option<u32>
2551 1049..1057 'x as u32': u32
2552 1066..1074 '{ None }': Option<u32>
2553 1068..1072 'None': Option<u32>
2554 1090..1100 '|y| { y; }': |u32| -> ()
2556 1094..1100 '{ y; }': ()
2579 fn foo() -> Self::Output;
2583 type Output = T::OutputA;
2584 fn foo() -> Self::Output { loop {} }
2595 fn trait_object_no_coercion() {
2596 check_infer_with_mismatches(
2600 fn foo(x: &dyn Foo) {}
2602 fn test(x: &dyn Foo) {
2606 21..22 'x': &dyn Foo
2608 46..47 'x': &dyn Foo
2609 59..74 '{ foo(x); }': ()
2610 65..68 'foo': fn foo(&dyn Foo)
2612 69..70 'x': &dyn Foo
2619 check_infer_with_mismatches(
2623 impl Copy for IsCopy {}
2626 trait Test { fn test(&self) -> bool; }
2627 impl<T: Copy> Test for T {}
2632 (IsCopy, IsCopy).test();
2633 (IsCopy, NotCopy).test();
2636 78..82 'self': &Self
2637 134..235 '{ ...t(); }': ()
2638 140..146 'IsCopy': IsCopy
2639 140..153 'IsCopy.test()': bool
2640 159..166 'NotCopy': NotCopy
2641 159..173 'NotCopy.test()': {unknown}
2642 179..195 '(IsCop...sCopy)': (IsCopy, IsCopy)
2643 179..202 '(IsCop...test()': bool
2644 180..186 'IsCopy': IsCopy
2645 188..194 'IsCopy': IsCopy
2646 208..225 '(IsCop...tCopy)': (IsCopy, NotCopy)
2647 208..232 '(IsCop...test()': {unknown}
2648 209..215 'IsCopy': IsCopy
2649 217..224 'NotCopy': NotCopy
2655 fn builtin_fn_def_copy() {
2656 check_infer_with_mismatches(
2660 fn bar<T: Copy>(T) -> T {}
2661 struct Struct(usize);
2662 enum Enum { Variant(usize) }
2664 trait Test { fn test(&self) -> bool; }
2665 impl<T: Copy> Test for T {}
2671 Enum::Variant.test();
2675 28..29 'T': {unknown}
2677 36..38: expected T, got ()
2678 113..117 'self': &Self
2679 169..249 '{ ...t(); }': ()
2680 175..178 'foo': fn foo()
2681 175..185 'foo.test()': bool
2682 191..194 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2683 191..201 'bar.test()': bool
2684 207..213 'Struct': Struct(usize) -> Struct
2685 207..220 'Struct.test()': bool
2686 226..239 'Enum::Variant': Variant(usize) -> Enum
2687 226..246 'Enum::...test()': bool
2693 fn builtin_fn_ptr_copy() {
2694 check_infer_with_mismatches(
2697 trait Test { fn test(&self) -> bool; }
2698 impl<T: Copy> Test for T {}
2700 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2706 22..26 'self': &Self
2708 86..88 'f2': fn(usize) -> u8
2709 107..109 'f3': fn(u8, u8) -> &u8
2710 130..178 '{ ...t(); }': ()
2712 136..145 'f1.test()': bool
2713 151..153 'f2': fn(usize) -> u8
2714 151..160 'f2.test()': bool
2715 166..168 'f3': fn(u8, u8) -> &u8
2716 166..175 'f3.test()': bool
2722 fn builtin_sized() {
2723 check_infer_with_mismatches(
2726 trait Test { fn test(&self) -> bool; }
2727 impl<T: Sized> Test for T {}
2731 (*"foo").test(); // not Sized
2733 (1u8, *"foo").test(); // not Sized
2736 22..26 'self': &Self
2737 79..194 '{ ...ized }': ()
2739 85..95 '1u8.test()': bool
2740 101..116 '(*"foo").test()': {unknown}
2741 102..108 '*"foo"': str
2742 103..108 '"foo"': &str
2743 135..145 '(1u8, 1u8)': (u8, u8)
2744 135..152 '(1u8, ...test()': bool
2747 158..171 '(1u8, *"foo")': (u8, str)
2748 158..178 '(1u8, ...test()': {unknown}
2750 164..170 '*"foo"': str
2751 165..170 '"foo"': &str
2757 fn integer_range_iterate() {
2760 //- /main.rs crate:main deps:core
2762 for x in 0..100 { x; }
2765 //- /core.rs crate:core
2767 pub struct Range<Idx> {
2774 pub trait Iterator {
2778 pub trait IntoIterator {
2780 type IntoIter: Iterator<Item = Self::Item>;
2783 impl<T> IntoIterator for T where T: Iterator {
2784 type Item = <T as Iterator>::Item;
2785 type IntoIter = Self;
2790 impl Step for i32 {}
2791 impl Step for i64 {}
2793 impl<A: Step> iter::Iterator for ops::Range<A> {
2801 fn infer_closure_arg() {
2812 let s = Option::None;
2813 let f = |x: Option<i32>| {};
2817 52..126 '{ ...)(s) }': ()
2818 62..63 's': Option<i32>
2819 66..78 'Option::None': Option<i32>
2820 88..89 'f': |Option<i32>| -> ()
2821 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
2822 93..94 'x': Option<i32>
2824 117..124 '(&f)(s)': ()
2825 118..120 '&f': &|Option<i32>| -> ()
2826 119..120 'f': |Option<i32>| -> ()
2827 122..123 's': Option<i32>
2833 fn dyn_fn_param_informs_call_site_closure_signature() {
2834 cov_mark::check!(dyn_fn_param_informs_call_site_closure_signature);
2837 //- minicore: fn, coerce_unsized
2840 fn inherent(&self) -> u8 { 0 }
2842 fn take_dyn_fn(f: &dyn Fn(S)) {}
2845 take_dyn_fn(&|x| { x.inherent(); });
2853 fn infer_fn_trait_arg() {
2854 check_infer_with_mismatches(
2856 //- minicore: fn, option
2857 fn foo<F, T>(f: F) -> T
2859 F: Fn(Option<i32>) -> T,
2867 59..89 '{ ...f(s) }': T
2868 69..70 's': Option<i32>
2869 73..77 'None': Option<i32>
2872 85..86 's': Option<i32>
2878 fn infer_box_fn_arg() {
2879 // The type mismatch is because we don't define Unsize and CoerceUnsized
2880 check_infer_with_mismatches(
2882 //- minicore: fn, deref, option
2883 #[lang = "owned_box"]
2884 pub struct Box<T: ?Sized> {
2888 impl<T: ?Sized> core::ops::Deref for Box<T> {
2891 fn deref(&self) -> &T {
2898 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
2902 154..158 'self': &Box<T>
2903 166..193 '{ ... }': &T
2904 176..187 '&self.inner': &*mut T
2905 177..181 'self': &Box<T>
2906 177..187 'self.inner': *mut T
2907 206..296 '{ ...&s); }': ()
2908 216..217 's': Option<i32>
2909 220..224 'None': Option<i32>
2910 234..235 'f': Box<dyn FnOnce(&Option<i32>)>
2911 269..282 'box (|ps| {})': Box<|{unknown}| -> ()>
2912 274..281 '|ps| {}': |{unknown}| -> ()
2913 275..277 'ps': {unknown}
2915 288..289 'f': Box<dyn FnOnce(&Option<i32>)>
2916 288..293 'f(&s)': ()
2917 290..292 '&s': &Option<i32>
2918 291..292 's': Option<i32>
2919 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
2925 fn infer_dyn_fn_output() {
2930 let f: &dyn Fn() -> i32;
2938 fn infer_dyn_fn_once_output() {
2943 let f: dyn FnOnce() -> i32;
2951 fn variable_kinds_1() {
2954 trait Trait<T> { fn get(self, t: T) -> T; }
2956 impl Trait<u128> for S {}
2957 impl Trait<f32> for S {}
2969 fn variable_kinds_2() {
2972 trait Trait { fn get(self) -> Self; }
2973 impl Trait for u128 {}
2974 impl Trait for f32 {}
2986 fn underscore_import() {
2991 fn method(&self) -> u8 { 0 }
2996 impl crate::tr::Tr for Tr {}
2998 use crate::tr::Tr as _;
3013 fn method(&self) -> u8 { 0 }
3030 fn trait_in_scope_with_inner_item() {
3035 fn method(&self) -> u8 { 0 }
3050 46..50 'self': &Self
3053 115..185 '{ ... } }': ()
3054 132..183 '{ ... }': ()
3056 142..153 '().method()': u8
3062 fn inner_use_in_block() {
3067 fn method(&self) -> u8 { 0 }
3083 //^^^^^^^^^^^ {unknown}
3087 //^^^^^^^^^^^ {unknown}
3094 fn nested_inner_function_calling_self() {
3104 17..73 '{ ... } }': ()
3105 39..71 '{ ... }': ()
3107 57..62 'inner': fn inner() -> S
3114 fn infer_default_trait_type_parameter() {
3119 trait Op<RHS=Self> {
3122 fn do_op(self, rhs: RHS) -> Self::Output;
3128 fn do_op(self, rhs: Self) -> Self::Output {
3143 186..206 '{ ... }': bool
3144 196..200 'true': bool
3145 220..277 '{ ...(y); }': ()
3152 264..274 'x.do_op(y)': bool
3159 fn qualified_path_as_qualified_trait() {
3169 fn boo() -> Self::Output {
3176 impl foo::Foo for F {
3179 impl foo::Bar for F {
3180 type Output = <F as foo::Foo>::Target;
3185 let x = <F as Bar>::boo();
3188 132..163 '{ ... }': Bar::Output<Self>
3189 146..153 'loop {}': !
3191 306..358 '{ ...o(); }': ()
3193 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3194 338..355 '<F as ...:boo()': ()
3200 fn renamed_extern_crate_in_block() {
3203 //- /lib.rs crate:lib deps:serde
3204 use serde::Deserialize;
3209 extern crate serde as _serde;
3210 impl _serde::Deserialize for Foo {
3211 fn deserialize() -> u8 { 0 }
3217 //^^^^^^^^^^^^^^^^^^ u8
3220 //- /serde.rs crate:serde
3222 pub trait Deserialize {
3223 fn deserialize() -> u8;
3229 fn bin_op_adt_with_rhs_primitive() {
3230 check_infer_with_mismatches(
3233 pub trait Add<Rhs = Self> {
3235 fn add(self, rhs: Rhs) -> Self::Output;
3238 struct Wrapper(u32);
3239 impl Add<u32> for Wrapper {
3241 fn add(self, rhs: u32) -> Wrapper {
3246 let wrapped = Wrapper(10);
3248 let res = wrapped + num;
3254 192..196 'self': Wrapper
3256 219..247 '{ ... }': Wrapper
3257 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3258 229..241 'Wrapper(rhs)': Wrapper
3260 259..345 '{ ...um; }': ()
3261 269..276 'wrapped': Wrapper
3262 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3263 279..290 'Wrapper(10)': Wrapper
3267 322..325 'res': Wrapper
3268 328..335 'wrapped': Wrapper
3269 328..341 'wrapped + num': Wrapper
3281 fn do_thing(&self) -> Self::Output;
3284 impl T for [u8; 4] {
3285 type Output = usize;
3286 fn do_thing(&self) -> Self::Output {
3291 impl T for [u8; 2] {
3293 fn do_thing(&self) -> Self::Output {
3300 let v2 = v.do_thing();
3302 let v4 = v3.do_thing();
3306 44..48 'self': &Self
3307 133..137 'self': &[u8; 4]
3308 155..172 '{ ... }': usize
3310 236..240 'self': &[u8; 2]
3311 258..275 '{ ... }': u8
3313 289..392 '{ ...g(); }': ()
3314 299..300 'v': [u8; 2]
3315 303..311 '[0u8; 2]': [u8; 2]
3319 326..327 'v': [u8; 2]
3320 326..338 'v.do_thing()': u8
3321 348..350 'v3': [u8; 4]
3322 353..361 '[0u8; 4]': [u8; 4]
3325 371..373 'v4': usize
3326 376..378 'v3': [u8; 4]
3327 376..389 'v3.do_thing()': usize
3332 // FIXME: We should infer the length of the returned array :)
3334 fn const_generics() {
3339 fn do_thing(&self) -> Self::Output;
3342 impl<const L: usize> T for [u8; L] {
3343 type Output = [u8; L];
3344 fn do_thing(&self) -> Self::Output {
3351 let v2 = v.do_thing();
3355 44..48 'self': &Self
3356 151..155 'self': &[u8; _]
3357 173..194 '{ ... }': [u8; _]
3358 183..188 '*self': [u8; _]
3359 184..188 'self': &[u8; _]
3360 208..260 '{ ...g(); }': ()
3361 218..219 'v': [u8; 2]
3362 222..230 '[0u8; 2]': [u8; 2]
3365 240..242 'v2': [u8; _]
3366 245..246 'v': [u8; 2]
3367 245..257 'v.do_thing()': [u8; _]
3373 fn fn_returning_unit() {
3374 check_infer_with_mismatches(
3377 fn test<F: FnOnce()>(f: F) {
3382 27..51 '{ ...f(); }': ()
3391 fn trait_in_scope_of_trait_impl() {
3397 fn bar(self) -> usize { 0 }
3400 impl foo::Foo for u32 {
3402 let _x = self.bar();
3409 82..87 '{ 0 }': usize
3411 131..135 'self': u32
3412 137..173 '{ ... }': ()
3413 151..153 '_x': usize
3414 156..160 'self': u32
3415 156..166 'self.bar()': usize
3421 fn infer_async_ret_type() {
3424 //- minicore: future, result
3428 fn collect<B: Convert>(self) -> B {
3436 impl Convert for u32 {
3437 fn new() -> Self { 0 }
3440 async fn get_accounts() -> Result<u32, ()> {
3441 let ret = Fooey.collect();
3442 // ^^^^^^^^^^^^^^^ u32
3451 check!(block_local_impls);
3460 impl Trait<u32> for S {
3461 fn foo(&self) -> u32 { 0 }
3473 check!(block_local_impls);
3482 impl Trait<u32> for S {
3483 fn foo(&self) -> u32 { 0 }
3495 check!(block_local_impls);
3507 impl Trait<S1> for S2 {
3508 fn foo(&self) -> S1 { S1 }
3520 fn associated_type_sized_bounds() {
3525 trait IsSized { const IS_SIZED: Yes; }
3526 impl<T: Sized> IsSized for T { const IS_SIZED: Yes = Yes; }
3529 type Explicit: Sized;
3531 type Relaxed: ?Sized;
3534 F::Explicit::IS_SIZED;
3535 F::Implicit::IS_SIZED;
3536 F::Relaxed::IS_SIZED;
3541 212..295 '{ ...ZED; }': ()
3542 218..239 'F::Exp..._SIZED': Yes
3543 245..266 'F::Imp..._SIZED': Yes
3544 272..292 'F::Rel..._SIZED': {unknown}