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 associated_type_shorthand_from_method_bound() {
404 fn foo(self) -> T::Item where T: Iterable { loop {} }
406 fn test<T: Iterable>() {
409 // ^^^^^^^ Iterable::Item<T>
415 fn infer_associated_type_bound() {
421 fn test<T: Iterable<Item=u32>>() {
422 let y: T::Item = unknown;
429 fn infer_const_body() {
430 // FIXME make check_types work with other bodies
433 const A: u32 = 1 + 1;
434 static B: u64 = { let x = 1; x };
440 38..54 '{ let ...1; x }': u64
449 fn tuple_struct_fields() {
459 37..86 '{ ... a.1 }': u64
461 51..52 'S': S(i32, u64) -> S
475 fn tuple_struct_with_fn() {
478 struct S(fn(u32) -> u64);
485 43..101 '{ ...0(2) }': u64
487 57..58 'S': S(fn(u32) -> u64) -> S
488 57..67 'S(|i| 2*i)': S
489 59..66 '|i| 2*i': |u32| -> u64
496 81..84 'a.0': fn(u32) -> u64
500 93..96 'a.0': fn(u32) -> u64
508 fn indexing_arrays() {
510 "fn main() { &mut [9][2]; }",
512 10..26 '{ &mut...[2]; }': ()
513 12..23 '&mut [9][2]': &mut {unknown}
514 17..20 '[9]': [i32; 1]
515 17..23 '[9][2]': {unknown}
523 fn infer_ops_index() {
530 impl core::ops::Index<u32> for Bar {
544 fn infer_ops_index_field() {
553 impl core::ops::Index<u32> for Bar {
559 let b = a[1u32].field;
567 fn infer_ops_index_field_autoderef() {
576 impl core::ops::Index<u32> for Bar {
582 let b = (&a[1u32]).field;
590 fn infer_ops_index_int() {
597 impl core::ops::Index<u32> for Bar {
602 impl core::ops::Index<Range> for Bar {
617 fn infer_ops_index_autoderef() {
620 //- minicore: index, slice
622 let a = &[1u32, 2, 3];
635 struct Arc<T: ?Sized>;
636 impl<T: ?Sized> core::ops::Deref for Arc<T> {
642 fn foo(&self) -> u128 { 0 }
647 } //^^^^^^^^^^^^^ (S, u128)
653 fn deref_trait_with_inference_var() {
657 struct Arc<T: ?Sized>;
658 fn new_arc<T: ?Sized>() -> Arc<T> { Arc }
659 impl<T: ?Sized> core::ops::Deref for Arc<T> {
677 fn deref_trait_infinite_recursion() {
683 impl core::ops::Deref for S {
689 } //^^^^^^^ {unknown}
695 fn deref_trait_with_question_mark_size() {
699 struct Arc<T: ?Sized>;
700 impl<T: ?Sized> core::ops::Deref for Arc<T> {
706 fn foo(&self) -> u128 { 0 }
711 } //^^^^^^^^^^^^^ (S, u128)
717 fn deref_trait_with_implicit_sized_requirement_on_inference_var() {
722 impl<T> core::ops::Deref for Foo<T> {
729 let _: Foo<u8> = foo;
736 fn obligation_from_function_clause() {
742 impl Trait<u32> for S {}
744 fn foo<T: Trait<U>, U>(t: T) -> U { loop {} }
754 fn obligation_from_method_clause() {
761 impl Trait<isize> for S {}
765 fn foo<T: Trait<U>, U>(&self, t: T) -> U { loop {} }
776 fn obligation_from_self_method_clause() {
782 impl Trait<i64> for S {}
785 fn foo<U>(&self) -> U where Self: Trait<U> { loop {} }
796 fn obligation_from_impl_clause() {
802 impl Trait<&str> for S {}
805 impl<U, T: Trait<U>> O<T> {
806 fn foo(&self) -> U { loop {} }
817 fn generic_param_env_1() {
821 trait Trait { fn foo(self) -> u128; }
824 impl<T> Trait for T where T: Clone {}
825 fn test<T: Clone>(t: T) { t.foo(); }
832 fn generic_param_env_1_not_met() {
837 trait Trait { fn foo(self) -> u128; }
840 impl<T> Trait for T where T: Clone {}
841 fn test<T>(t: T) { t.foo(); }
848 fn generic_param_env_2() {
851 trait Trait { fn foo(self) -> u128; }
854 fn test<T: Trait>(t: T) { t.foo(); }
861 fn generic_param_env_2_not_met() {
864 trait Trait { fn foo(self) -> u128; }
867 fn test<T>(t: T) { t.foo(); }
874 fn generic_param_env_deref() {
879 impl<T> core::ops::Deref for T where T: Trait {
882 fn test<T: Trait>(t: T) { *t; }
889 fn associated_type_placeholder() {
890 // 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].
897 pub struct RefMutL<T>;
899 impl<T> ApplyL for RefMutL<T> {
900 type Out = <T as ApplyL>::Out;
903 fn test<T: ApplyL>() {
904 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
912 fn associated_type_placeholder_2() {
918 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
920 fn test<T: ApplyL>(t: T) {
929 fn argument_impl_trait() {
930 check_infer_with_mismatches(
935 fn foo2(&self) -> i64;
937 fn bar(x: impl Trait<u16>) {}
939 impl<T> Trait<T> for S<T> {}
941 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
956 77..78 'x': impl Trait<u16>
958 154..155 'x': impl Trait<u64>
959 174..175 'y': &impl Trait<u32>
960 195..323 '{ ...2(); }': ()
961 201..202 'x': impl Trait<u64>
962 208..209 'y': &impl Trait<u32>
964 223..224 'S': S<u16>(u16) -> S<u16>
965 223..227 'S(1)': S<u16>
967 233..236 'bar': fn bar(S<u16>)
968 233..239 'bar(z)': ()
970 245..246 'x': impl Trait<u64>
971 245..252 'x.foo()': u64
972 258..259 'y': &impl Trait<u32>
973 258..265 'y.foo()': u32
975 271..278 'z.foo()': u16
976 284..285 'x': impl Trait<u64>
977 284..292 'x.foo2()': i64
978 298..299 'y': &impl Trait<u32>
979 298..306 'y.foo2()': i64
981 312..320 'z.foo2()': i64
987 fn argument_impl_trait_type_args_1() {
988 check_infer_with_mismatches(
993 // this function has an implicit Self param, an explicit type param,
994 // and an implicit impl Trait param!
995 fn bar<T>(x: impl Trait) -> T { loop {} }
997 fn foo<T>(x: impl Trait) -> T { loop {} }
1008 <F as Foo>::bar::<u32>(S);
1012 foo::<u32, i32>(S); // we should ignore the extraneous i32
1015 155..156 'x': impl Trait
1016 175..186 '{ loop {} }': T
1017 177..184 'loop {}': !
1019 199..200 'x': impl Trait
1020 219..230 '{ loop {} }': T
1021 221..228 'loop {}': !
1023 300..509 '{ ... i32 }': ()
1024 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1025 306..317 'Foo::bar(S)': {unknown}
1027 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1028 323..341 '<F as ...bar(S)': {unknown}
1030 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1031 347..356 'F::bar(S)': {unknown}
1033 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1034 362..380 'Foo::b...32>(S)': u32
1036 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1037 386..411 '<F as ...32>(S)': u32
1039 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1040 418..424 'foo(S)': {unknown}
1042 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1043 430..443 'foo::<u32>(S)': u32
1045 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1046 449..467 'foo::<...32>(S)': u32
1053 fn argument_impl_trait_type_args_2() {
1054 check_infer_with_mismatches(
1062 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1068 F::<u32>.foo::<i32>(S);
1069 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1073 93..94 'x': impl Trait
1074 118..129 '{ loop {} }': (T, U)
1075 120..127 'loop {}': !
1077 143..283 '{ ...ored }': ()
1078 149..150 'F': F<{unknown}>
1079 149..157 'F.foo(S)': ({unknown}, {unknown})
1081 163..171 'F::<u32>': F<u32>
1082 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1084 184..192 'F::<u32>': F<u32>
1085 184..206 'F::<u3...32>(S)': (u32, i32)
1087 212..220 'F::<u32>': F<u32>
1088 212..239 'F::<u3...32>(S)': (u32, i32)
1095 fn argument_impl_trait_to_fn_pointer() {
1096 check_infer_with_mismatches(
1100 fn foo(x: impl Trait) { loop {} }
1105 let f: fn(S) -> () = foo;
1108 22..23 'x': impl Trait
1109 37..48 '{ loop {} }': ()
1112 90..123 '{ ...foo; }': ()
1114 117..120 'foo': fn foo(S)
1126 fn foo2(&self) -> i64;
1128 fn bar() -> impl Trait<u64> {}
1130 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1142 29..33 'self': &Self
1143 54..58 'self': &Self
1145 110..111 'x': impl Trait<u64>
1146 130..131 'y': &impl Trait<u64>
1147 151..268 '{ ...2(); }': ()
1148 157..158 'x': impl Trait<u64>
1149 164..165 'y': &impl Trait<u64>
1150 175..176 'z': impl Trait<u64>
1151 179..182 'bar': fn bar() -> impl Trait<u64>
1152 179..184 'bar()': impl Trait<u64>
1153 190..191 'x': impl Trait<u64>
1154 190..197 'x.foo()': u64
1155 203..204 'y': &impl Trait<u64>
1156 203..210 'y.foo()': u64
1157 216..217 'z': impl Trait<u64>
1158 216..223 'z.foo()': u64
1159 229..230 'x': impl Trait<u64>
1160 229..237 'x.foo2()': i64
1161 243..244 'y': &impl Trait<u64>
1162 243..251 'y.foo2()': i64
1163 257..258 'z': impl Trait<u64>
1164 257..265 'z.foo2()': i64
1170 fn simple_return_pos_impl_trait() {
1171 cov_mark::check!(lower_rpit);
1178 fn bar() -> impl Trait<u64> { loop {} }
1185 29..33 'self': &Self
1186 71..82 '{ loop {} }': !
1189 94..129 '{ ...o(); }': ()
1190 104..105 'a': impl Trait<u64>
1191 108..111 'bar': fn bar() -> impl Trait<u64>
1192 108..113 'bar()': impl Trait<u64>
1193 119..120 'a': impl Trait<u64>
1194 119..126 'a.foo()': u64
1200 fn more_return_pos_impl_trait() {
1206 fn next(&mut self) -> Self::Item;
1211 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1212 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1218 let (c, d) = baz(1u128);
1223 49..53 'self': &mut Self
1224 101..105 'self': &Self
1225 184..195 '{ loop {} }': ({unknown}, {unknown})
1226 186..193 'loop {}': !
1229 268..279 '{ loop {} }': ({unknown}, {unknown})
1230 270..277 'loop {}': !
1232 291..413 '{ ...o(); }': ()
1233 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1234 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1235 305..306 'b': impl Trait<u64>
1236 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1237 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1238 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1239 321..329 'a.next()': impl Trait<u32>
1240 321..335 'a.next().foo()': u32
1241 341..342 'b': impl Trait<u64>
1242 341..348 'b.foo()': u64
1243 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1244 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1245 362..363 'd': impl Trait<u128>
1246 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1247 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1248 371..376 '1u128': u128
1249 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1250 383..391 'c.next()': impl Trait<u128>
1251 383..397 'c.next().foo()': u128
1252 403..404 'd': impl Trait<u128>
1253 403..410 'd.foo()': u128
1265 fn foo2(&self) -> i64;
1267 fn bar() -> dyn Trait<u64> {}
1269 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1281 29..33 'self': &Self
1282 54..58 'self': &Self
1284 109..110 'x': dyn Trait<u64>
1285 128..129 'y': &dyn Trait<u64>
1286 148..265 '{ ...2(); }': ()
1287 154..155 'x': dyn Trait<u64>
1288 161..162 'y': &dyn Trait<u64>
1289 172..173 'z': dyn Trait<u64>
1290 176..179 'bar': fn bar() -> dyn Trait<u64>
1291 176..181 'bar()': dyn Trait<u64>
1292 187..188 'x': dyn Trait<u64>
1293 187..194 'x.foo()': u64
1294 200..201 'y': &dyn Trait<u64>
1295 200..207 'y.foo()': u64
1296 213..214 'z': dyn Trait<u64>
1297 213..220 'z.foo()': u64
1298 226..227 'x': dyn Trait<u64>
1299 226..234 'x.foo2()': i64
1300 240..241 'y': &dyn Trait<u64>
1301 240..248 'y.foo2()': i64
1302 254..255 'z': dyn Trait<u64>
1303 254..262 'z.foo2()': i64
1309 fn dyn_trait_in_impl() {
1314 fn foo(&self) -> (T, U);
1317 impl<T, U> S<T, U> {
1318 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1320 trait Trait2<T, U> {
1321 fn baz(&self) -> (T, U);
1323 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1325 fn test(s: S<u32, i32>) {
1329 32..36 'self': &Self
1330 102..106 'self': &S<T, U>
1331 128..139 '{ loop {} }': &dyn Trait<T, U>
1332 130..137 'loop {}': !
1334 175..179 'self': &Self
1335 251..252 's': S<u32, i32>
1336 267..289 '{ ...z(); }': ()
1337 273..274 's': S<u32, i32>
1338 273..280 's.bar()': &dyn Trait<u32, i32>
1339 273..286 's.bar().baz()': (u32, i32)
1345 fn dyn_trait_bare() {
1350 fn foo(&self) -> u64;
1352 fn bar() -> Trait {}
1354 fn test(x: Trait, y: &Trait) -> u64 {
1363 26..30 'self': &Self
1365 72..73 'x': dyn Trait
1366 82..83 'y': &dyn Trait
1367 100..175 '{ ...o(); }': ()
1368 106..107 'x': dyn Trait
1369 113..114 'y': &dyn Trait
1370 124..125 'z': dyn Trait
1371 128..131 'bar': fn bar() -> dyn Trait
1372 128..133 'bar()': dyn Trait
1373 139..140 'x': dyn Trait
1374 139..146 'x.foo()': u64
1375 152..153 'y': &dyn Trait
1376 152..159 'y.foo()': u64
1377 165..166 'z': dyn Trait
1378 165..172 'z.foo()': u64
1390 a: impl Trait + 'lifetime,
1393 d: impl ('lifetime),
1395 f: impl Trait + ?Sized
1399 28..29 'a': impl Trait
1400 59..60 'b': impl Sized
1401 82..83 'c': impl Trait
1402 103..104 'd': impl Sized
1403 128..129 'e': impl ?Sized
1404 148..149 'f': impl Trait + ?Sized
1411 fn error_bound_chalk() {
1415 fn foo(&self) -> u32 { 0 }
1418 fn test(x: (impl Trait + UnknownTrait)) {
1426 fn assoc_type_bindings() {
1434 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1435 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1436 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1439 impl<T> Trait for S<T> { type Type = T; }
1441 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1459 262..263 'y': impl Trait<Type = i64>
1460 289..397 '{ ...r>); }': ()
1461 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1462 295..301 'get(x)': u32
1464 307..311 'get2': fn get2<u32, T>(T) -> u32
1465 307..314 'get2(x)': u32
1467 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1468 320..326 'get(y)': i64
1469 324..325 'y': impl Trait<Type = i64>
1470 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1471 332..339 'get2(y)': i64
1472 337..338 'y': impl Trait<Type = i64>
1473 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1474 345..356 'get(set(S))': u64
1475 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1476 349..355 'set(S)': S<u64>
1477 353..354 'S': S<u64>
1478 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1479 362..374 'get2(set(S))': u64
1480 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1481 367..373 'set(S)': S<u64>
1482 371..372 'S': S<u64>
1483 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1484 380..394 'get2(S::<str>)': str
1485 385..393 'S::<str>': S<str>
1491 fn impl_trait_assoc_binding_projection_bug() {
1494 //- minicore: iterator
1495 pub trait Language {
1498 pub enum RustLanguage {}
1499 impl Language for RustLanguage {
1500 type Kind = SyntaxKind;
1502 struct SyntaxNode<L> {}
1503 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1506 fn clone(&self) -> Self;
1509 fn api_walkthrough() {
1512 } //^^^^^^^^^^^^ {unknown}
1519 fn projection_eq_within_chalk() {
1528 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1530 fn test<T: Trait1<Type = u32>>(x: T) {
1536 169..185 '{ ...o(); }': ()
1538 175..182 'x.foo()': u32
1544 fn where_clause_trait_in_scope_for_method_resolution() {
1549 fn foo(&self) -> u32 { 0 }
1553 fn test<T: foo::Trait>(x: T) {
1561 fn super_trait_method_resolution() {
1566 fn foo(&self) -> u32 {}
1569 trait Trait1: foo::SuperTrait {}
1570 trait Trait2 where Self: foo::SuperTrait {}
1572 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1577 49..53 'self': &Self
1581 193..222 '{ ...o(); }': ()
1583 199..206 'x.foo()': u32
1585 212..219 'y.foo()': u32
1591 fn super_trait_impl_trait_method_resolution() {
1597 fn foo(&self) -> u32 {}
1600 trait Trait1: foo::SuperTrait {}
1602 fn test(x: &impl Trait1) {
1606 49..53 'self': &Self
1608 115..116 'x': &impl Trait1
1609 132..148 '{ ...o(); }': ()
1610 138..139 'x': &impl Trait1
1611 138..145 'x.foo()': u32
1617 fn super_trait_cycle() {
1618 // This just needs to not crash
1624 fn test<T: A>(x: T) {
1630 49..65 '{ ...o(); }': ()
1632 55..62 'x.foo()': {unknown}
1638 fn super_trait_assoc_type_bounds() {
1641 trait SuperTrait { type Type; }
1642 trait Trait where Self: SuperTrait {}
1644 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1645 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1648 impl<T> SuperTrait for S<T> { type Type = T; }
1649 impl<T> Trait for S<T> {}
1660 258..279 '{ ...S)); }': ()
1661 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1662 264..276 'get2(set(S))': u64
1663 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1664 269..275 'set(S)': S<u64>
1665 273..274 'S': S<u64>
1672 check_infer_with_mismatches(
1674 trait FnOnce<Args> {
1677 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1680 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1681 f.call_once((1, 2));
1687 155..183 '{ ...2)); }': ()
1689 161..180 'f.call...1, 2))': u128
1690 173..179 '(1, 2)': (u32, u64)
1698 fn fn_ptr_and_item() {
1699 check_infer_with_mismatches(
1702 trait FnOnce<Args> {
1705 fn call_once(self, args: Args) -> Self::Output;
1714 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1715 fn foo(&self) -> (A1, R) { loop {} }
1718 enum Opt<T> { None, Some(T) }
1720 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1724 let bar: Bar<fn(u8) -> u32>;
1728 let f: fn(u8) -> u32;
1734 139..143 'self': &Self
1735 243..247 'self': &Bar<F>
1736 260..271 '{ loop {} }': (A1, R)
1737 262..269 'loop {}': !
1739 355..359 'self': Opt<T>
1741 377..388 '{ loop {} }': Opt<U>
1742 379..386 'loop {}': !
1744 402..518 '{ ...(f); }': ()
1745 412..415 'bar': Bar<fn(u8) -> u32>
1746 441..444 'bar': Bar<fn(u8) -> u32>
1747 441..450 'bar.foo()': (u8, u32)
1748 461..464 'opt': Opt<u8>
1749 483..484 'f': fn(u8) -> u32
1750 505..508 'opt': Opt<u8>
1751 505..515 'opt.map(f)': Opt<u32>
1752 513..514 'f': fn(u8) -> u32
1758 fn fn_trait_deref_with_ty_default() {
1761 //- minicore: deref, fn
1765 fn foo(&self) -> usize {}
1768 struct Lazy<T, F = fn() -> T>(F);
1770 impl<T, F> Lazy<T, F> {
1771 pub fn new(f: F) -> Lazy<T, F> {}
1774 impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> {
1779 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1780 let r1 = lazy1.foo();
1782 fn make_foo_fn() -> Foo {}
1783 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1784 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1785 let r2 = lazy2.foo();
1792 251..497 '{ ...o(); }': ()
1793 261..266 'lazy1': Lazy<Foo, || -> Foo>
1794 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1795 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1796 293..299 '|| Foo': || -> Foo
1798 310..312 'r1': usize
1799 315..320 'lazy1': Lazy<Foo, || -> Foo>
1800 315..326 'lazy1.foo()': usize
1801 368..383 'make_foo_fn_ptr': fn() -> Foo
1802 399..410 'make_foo_fn': fn make_foo_fn() -> Foo
1803 420..425 'lazy2': Lazy<Foo, fn() -> Foo>
1804 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1805 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1806 452..467 'make_foo_fn_ptr': fn() -> Foo
1807 478..480 'r2': usize
1808 483..488 'lazy2': Lazy<Foo, fn() -> Foo>
1809 483..494 'lazy2.foo()': usize
1817 check_infer_with_mismatches(
1820 enum Option<T> { Some(T), None }
1822 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1826 let x = Option::Some(1u32);
1829 let y: Option<i64> = x.map(|_v| 1);
1832 86..90 'self': Option<T>
1834 111..122 '{ loop {} }': Option<U>
1835 113..120 'loop {}': !
1837 136..255 '{ ... 1); }': ()
1838 146..147 'x': Option<u32>
1839 150..162 'Option::Some': Some<u32>(u32) -> Option<u32>
1840 150..168 'Option...(1u32)': Option<u32>
1841 163..167 '1u32': u32
1842 174..175 'x': Option<u32>
1843 174..190 'x.map(...v + 1)': Option<u32>
1844 180..189 '|v| v + 1': |u32| -> u32
1847 184..189 'v + 1': u32
1849 196..197 'x': Option<u32>
1850 196..212 'x.map(... 1u64)': Option<u64>
1851 202..211 '|_v| 1u64': |u32| -> u64
1853 207..211 '1u64': u64
1854 222..223 'y': Option<i64>
1855 239..240 'x': Option<u32>
1856 239..252 'x.map(|_v| 1)': Option<i64>
1857 245..251 '|_v| 1': |u32| -> i64
1868 //- minicore: add, fn
1870 impl core::ops::Add for u64 {
1872 fn add(self, rhs: u64) -> Self::Output {0}
1875 impl core::ops::Add for u128 {
1877 fn add(self, rhs: u128) -> Self::Output {0}
1880 fn test<F: FnOnce(u32) -> u64>(f: F) {
1886 //^^^^^^^^^ |u64| -> u64
1889 let h = |v| 1u128 + v;
1890 //^^^^^^^^^^^^^ |u128| -> u128
1896 fn closure_as_argument_inference_order() {
1897 check_infer_with_mismatches(
1900 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
1901 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
1905 fn method(self) -> u64;
1907 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
1908 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
1912 let x1 = foo1(S, |s| s.method());
1913 let x2 = foo2(|s| s.method(), S);
1914 let x3 = S.foo1(S, |s| s.method());
1915 let x4 = S.foo2(|s| s.method(), S);
1920 50..61 '{ loop {} }': U
1925 112..123 '{ loop {} }': U
1926 114..121 'loop {}': !
1932 233..244 '{ loop {} }': U
1933 235..242 'loop {}': !
1938 305..316 '{ loop {} }': U
1939 307..314 'loop {}': !
1941 330..489 '{ ... S); }': ()
1943 345..349 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
1944 345..368 'foo1(S...hod())': u64
1946 353..367 '|s| s.method()': |S| -> u64
1949 357..367 's.method()': u64
1951 383..387 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
1952 383..406 'foo2(|...(), S)': u64
1953 388..402 '|s| s.method()': |S| -> u64
1956 392..402 's.method()': u64
1960 421..446 'S.foo1...hod())': u64
1962 431..445 '|s| s.method()': |S| -> u64
1965 435..445 's.method()': u64
1968 461..486 'S.foo2...(), S)': u64
1969 468..482 '|s| s.method()': |S| -> u64
1972 472..482 's.method()': u64
1979 fn fn_item_fn_trait() {
1987 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
1991 } //^^^^^^^^^^^^^^^^^^ S
1997 fn unselected_projection_in_trait_env_1() {
2006 fn foo(&self) -> u32;
2009 fn test<T: Trait>() where T::Item: Trait2 {
2010 let x: T::Item = no_matter;
2018 fn unselected_projection_in_trait_env_2() {
2026 fn foo(&self) -> u32;
2029 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2030 let x: T::Item = no_matter;
2038 fn unselected_projection_on_impl_self() {
2045 fn f(&self, x: Self::Item);
2052 fn f(&self, x: Self::Item) { let y = x; }
2059 fn f(&self, x: <Self>::Item) { let y = x; }
2062 40..44 'self': &Self
2063 46..47 'x': Trait::Item<Self>
2066 147..161 '{ let y = x; }': ()
2069 228..232 'self': &S2
2071 251..265 '{ let y = x; }': ()
2079 fn unselected_projection_on_trait_self() {
2085 fn f(&self) -> Self::Item { loop {} }
2101 fn unselected_projection_chalk_fold() {
2105 trait Fold<I: Interner, TI = I> {
2109 struct Ty<I: Interner> {}
2110 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2111 type Result = Ty<TI>;
2114 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2121 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2123 } //^^^^^^^^^^^^^^^^^ Ty<I>
2129 fn trait_impl_self_ty() {
2138 impl Trait<Self> for S {}
2148 fn trait_impl_self_ty_cycle() {
2157 impl Trait for S<Self> {}
2161 } //^^^^^^^ {unknown}
2167 fn unselected_projection_in_trait_env_cycle_1() {
2168 // This is not a cycle, because the `T: Trait2<T::Item>` bound depends only on the `T: Trait`
2169 // bound, not on itself (since only `Trait` can define `Item`).
2178 fn test<T: Trait>() where T: Trait2<T::Item> {
2179 let x: T::Item = no_matter;
2180 } //^^^^^^^^^ Trait::Item<T>
2186 fn unselected_projection_in_trait_env_cycle_2() {
2187 // this is a legitimate cycle
2195 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2196 let x: T::Item = no_matter;
2197 } //^^^^^^^^^ {unknown}
2203 fn unselected_projection_in_trait_env_cycle_3() {
2204 // this is a cycle for rustc; we currently accept it
2213 fn test<T>() where T: Trait<OtherItem = T::Item> {
2214 let x: T::Item = no_matter;
2215 } //^^^^^^^^^ Trait::Item<T>
2221 fn unselected_projection_in_trait_env_no_cycle() {
2222 // this is not a cycle
2230 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2232 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2235 fn len(&self) -> usize;
2238 pub trait UnificationStoreMut: UnificationStoreBase {
2239 fn push(&mut self, value: Self::Key);
2242 fn test<T>(t: T) where T: UnificationStoreMut {
2247 } //^^^^^^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2253 fn inline_assoc_type_bounds_1() {
2259 trait OtherTrait<T> {
2263 // workaround for Chalk assoc type normalization problems
2265 impl<T: Iterator> Iterator for S<T> {
2266 type Item = <T as Iterator>::Item;
2269 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2270 let x: <S<I> as Iterator>::Item;
2278 fn inline_assoc_type_bounds_2() {
2285 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2286 let x: <<I as Iterator>::Item as Iterator>::Item;
2294 fn proc_macro_server_types() {
2297 macro_rules! with_api {
2298 ($S:ident, $self:ident, $m:ident) => {
2301 fn new() -> $S::TokenStream;
2308 macro_rules! associated_item {
2309 (type TokenStream) =>
2310 (type TokenStream: 'static;);
2312 (type Group: 'static;);
2313 ($($item:tt)*) => ($($item)*;)
2315 macro_rules! declare_server_traits {
2317 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2320 $(associated_item!(type $name);)*
2323 $(pub trait $name: Types {
2324 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2327 pub trait Server: Types $(+ $name)* {}
2328 impl<S: Types $(+ $name)*> Server for S {}
2332 with_api!(Self, self_, declare_server_traits);
2336 impl Types for Rustc {
2337 type TokenStream = T;
2341 fn make<T>() -> T { loop {} }
2342 impl TokenStream for Rustc {
2343 fn new() -> Self::TokenStream {
2344 let group: Self::Group = make();
2349 1061..1072 '{ loop {} }': T
2350 1063..1070 'loop {}': !
2352 1136..1199 '{ ... }': T
2353 1150..1155 'group': G
2354 1171..1175 'make': fn make<G>() -> G
2355 1171..1177 'make()': G
2356 1187..1191 'make': fn make<T>() -> T
2357 1187..1193 'make()': T
2363 fn unify_impl_trait() {
2364 check_infer_with_mismatches(
2369 fn foo(x: impl Trait<u32>) { loop {} }
2370 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2373 impl<T> Trait<T> for S<T> {}
2375 fn default<T>() -> T { loop {} }
2377 fn test() -> impl Trait<i32> {
2378 let s1 = S(default());
2380 let x: i32 = bar(S(default()));
2384 26..27 'x': impl Trait<u32>
2385 46..57 '{ loop {} }': ()
2388 68..69 'x': impl Trait<T>
2389 91..102 '{ loop {} }': T
2390 93..100 'loop {}': !
2392 171..182 '{ loop {} }': T
2393 173..180 'loop {}': !
2395 213..309 '{ ...t()) }': S<{unknown}>
2396 223..225 's1': S<u32>
2397 228..229 'S': S<u32>(u32) -> S<u32>
2398 228..240 'S(default())': S<u32>
2399 230..237 'default': fn default<u32>() -> u32
2400 230..239 'default()': u32
2401 246..249 'foo': fn foo(S<u32>)
2402 246..253 'foo(s1)': ()
2403 250..252 's1': S<u32>
2405 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2406 272..289 'bar(S(...lt()))': i32
2407 276..277 'S': S<i32>(i32) -> S<i32>
2408 276..288 'S(default())': S<i32>
2409 278..285 'default': fn default<i32>() -> i32
2410 278..287 'default()': i32
2411 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2412 295..307 'S(default())': S<{unknown}>
2413 297..304 'default': fn default<{unknown}>() -> {unknown}
2414 297..306 'default()': {unknown}
2420 fn assoc_types_from_bounds() {
2439 f::<(), _>(|z| { z; });
2444 132..163 '{ ... }); }': ()
2445 138..148 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2446 138..160 'f::<()... z; })': ()
2447 149..159 '|z| { z; }': |&()| -> ()
2449 153..159 '{ z; }': ()
2456 fn associated_type_bound() {
2460 type Item: OtherTrait<u32>;
2462 pub trait OtherTrait<T> {
2466 // this is just a workaround for chalk#234
2468 impl<T: Trait> Trait for S<T> {
2469 type Item = <T as Trait>::Item;
2472 fn test<T: Trait>() {
2473 let y: <S<T> as Trait>::Item = no_matter;
2481 fn dyn_trait_through_chalk() {
2485 struct Box<T: ?Sized> {}
2486 impl<T: ?Sized> core::ops::Deref for Box<T> {
2493 fn test(x: Box<dyn Trait>) {
2501 fn string_to_owned() {
2507 fn to_owned(&self) -> Self::Owned;
2509 impl ToOwned for str {
2510 type Owned = String;
2514 } //^^^^^^^^^^^^^^^^ String
2520 fn iterator_chain() {
2521 check_infer_with_mismatches(
2523 //- minicore: fn, option
2524 pub trait Iterator {
2527 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2529 F: FnMut(Self::Item) -> Option<B>,
2532 fn for_each<F>(self, f: F)
2534 F: FnMut(Self::Item),
2538 pub trait IntoIterator {
2540 type IntoIter: Iterator<Item = Self::Item>;
2541 fn into_iter(self) -> Self::IntoIter;
2544 pub struct FilterMap<I, F> { }
2545 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2547 F: FnMut(I::Item) -> Option<B>,
2552 #[stable(feature = "rust1", since = "1.0.0")]
2553 impl<I: Iterator> IntoIterator for I {
2554 type Item = I::Item;
2557 fn into_iter(self) -> I {
2564 fn new() -> Self { loop {} }
2567 impl<T> IntoIterator for Vec<T> {
2569 type IntoIter = IntoIter<T>;
2572 pub struct IntoIter<T> { }
2573 impl<T> Iterator for IntoIter<T> {
2578 Vec::<i32>::new().into_iter()
2579 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2580 .for_each(|y| { y; });
2585 152..163 '{ loop {} }': FilterMap<Self, F>
2586 154..161 'loop {}': !
2588 184..188 'self': Self
2590 240..251 '{ loop {} }': ()
2591 242..249 'loop {}': !
2593 360..364 'self': Self
2595 700..720 '{ ... }': I
2597 779..790 '{ loop {} }': Vec<T>
2598 781..788 'loop {}': !
2600 977..1104 '{ ... }); }': ()
2601 983..998 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2602 983..1000 'Vec::<...:new()': Vec<i32>
2603 983..1012 'Vec::<...iter()': IntoIter<i32>
2604 983..1075 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2605 983..1101 'Vec::<... y; })': ()
2606 1029..1074 '|x| if...None }': |i32| -> Option<u32>
2608 1033..1074 'if x >...None }': Option<u32>
2610 1036..1041 'x > 0': bool
2612 1042..1060 '{ Some...u32) }': Option<u32>
2613 1044..1048 'Some': Some<u32>(u32) -> Option<u32>
2614 1044..1058 'Some(x as u32)': Option<u32>
2616 1049..1057 'x as u32': u32
2617 1066..1074 '{ None }': Option<u32>
2618 1068..1072 'None': Option<u32>
2619 1090..1100 '|y| { y; }': |u32| -> ()
2621 1094..1100 '{ y; }': ()
2644 fn foo() -> Self::Output;
2648 type Output = T::OutputA;
2649 fn foo() -> Self::Output { loop {} }
2660 fn trait_object_no_coercion() {
2661 check_infer_with_mismatches(
2665 fn foo(x: &dyn Foo) {}
2667 fn test(x: &dyn Foo) {
2671 21..22 'x': &dyn Foo
2673 46..47 'x': &dyn Foo
2674 59..74 '{ foo(x); }': ()
2675 65..68 'foo': fn foo(&dyn Foo)
2677 69..70 'x': &dyn Foo
2684 check_infer_with_mismatches(
2688 impl Copy for IsCopy {}
2691 trait Test { fn test(&self) -> bool; }
2692 impl<T: Copy> Test for T {}
2697 (IsCopy, IsCopy).test();
2698 (IsCopy, NotCopy).test();
2701 78..82 'self': &Self
2702 134..235 '{ ...t(); }': ()
2703 140..146 'IsCopy': IsCopy
2704 140..153 'IsCopy.test()': bool
2705 159..166 'NotCopy': NotCopy
2706 159..173 'NotCopy.test()': {unknown}
2707 179..195 '(IsCop...sCopy)': (IsCopy, IsCopy)
2708 179..202 '(IsCop...test()': bool
2709 180..186 'IsCopy': IsCopy
2710 188..194 'IsCopy': IsCopy
2711 208..225 '(IsCop...tCopy)': (IsCopy, NotCopy)
2712 208..232 '(IsCop...test()': {unknown}
2713 209..215 'IsCopy': IsCopy
2714 217..224 'NotCopy': NotCopy
2720 fn builtin_fn_def_copy() {
2721 check_infer_with_mismatches(
2725 fn bar<T: Copy>(T) -> T {}
2726 struct Struct(usize);
2727 enum Enum { Variant(usize) }
2729 trait Test { fn test(&self) -> bool; }
2730 impl<T: Copy> Test for T {}
2736 Enum::Variant.test();
2740 28..29 'T': {unknown}
2742 36..38: expected T, got ()
2743 113..117 'self': &Self
2744 169..249 '{ ...t(); }': ()
2745 175..178 'foo': fn foo()
2746 175..185 'foo.test()': bool
2747 191..194 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2748 191..201 'bar.test()': bool
2749 207..213 'Struct': Struct(usize) -> Struct
2750 207..220 'Struct.test()': bool
2751 226..239 'Enum::Variant': Variant(usize) -> Enum
2752 226..246 'Enum::...test()': bool
2758 fn builtin_fn_ptr_copy() {
2759 check_infer_with_mismatches(
2762 trait Test { fn test(&self) -> bool; }
2763 impl<T: Copy> Test for T {}
2765 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2771 22..26 'self': &Self
2773 86..88 'f2': fn(usize) -> u8
2774 107..109 'f3': fn(u8, u8) -> &u8
2775 130..178 '{ ...t(); }': ()
2777 136..145 'f1.test()': bool
2778 151..153 'f2': fn(usize) -> u8
2779 151..160 'f2.test()': bool
2780 166..168 'f3': fn(u8, u8) -> &u8
2781 166..175 'f3.test()': bool
2787 fn builtin_sized() {
2788 check_infer_with_mismatches(
2791 trait Test { fn test(&self) -> bool; }
2792 impl<T: Sized> Test for T {}
2796 (*"foo").test(); // not Sized
2798 (1u8, *"foo").test(); // not Sized
2801 22..26 'self': &Self
2802 79..194 '{ ...ized }': ()
2804 85..95 '1u8.test()': bool
2805 101..116 '(*"foo").test()': {unknown}
2806 102..108 '*"foo"': str
2807 103..108 '"foo"': &str
2808 135..145 '(1u8, 1u8)': (u8, u8)
2809 135..152 '(1u8, ...test()': bool
2812 158..171 '(1u8, *"foo")': (u8, str)
2813 158..178 '(1u8, ...test()': {unknown}
2815 164..170 '*"foo"': str
2816 165..170 '"foo"': &str
2822 fn integer_range_iterate() {
2825 //- /main.rs crate:main deps:core
2827 for x in 0..100 { x; }
2830 //- /core.rs crate:core
2832 pub struct Range<Idx> {
2839 pub trait Iterator {
2843 pub trait IntoIterator {
2845 type IntoIter: Iterator<Item = Self::Item>;
2848 impl<T> IntoIterator for T where T: Iterator {
2849 type Item = <T as Iterator>::Item;
2850 type IntoIter = Self;
2855 impl Step for i32 {}
2856 impl Step for i64 {}
2858 impl<A: Step> iter::Iterator for ops::Range<A> {
2866 fn infer_closure_arg() {
2877 let s = Option::None;
2878 let f = |x: Option<i32>| {};
2882 52..126 '{ ...)(s) }': ()
2883 62..63 's': Option<i32>
2884 66..78 'Option::None': Option<i32>
2885 88..89 'f': |Option<i32>| -> ()
2886 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
2887 93..94 'x': Option<i32>
2889 117..124 '(&f)(s)': ()
2890 118..120 '&f': &|Option<i32>| -> ()
2891 119..120 'f': |Option<i32>| -> ()
2892 122..123 's': Option<i32>
2898 fn dyn_fn_param_informs_call_site_closure_signature() {
2899 cov_mark::check!(dyn_fn_param_informs_call_site_closure_signature);
2902 //- minicore: fn, coerce_unsized
2905 fn inherent(&self) -> u8 { 0 }
2907 fn take_dyn_fn(f: &dyn Fn(S)) {}
2910 take_dyn_fn(&|x| { x.inherent(); });
2918 fn infer_fn_trait_arg() {
2919 check_infer_with_mismatches(
2921 //- minicore: fn, option
2922 fn foo<F, T>(f: F) -> T
2924 F: Fn(Option<i32>) -> T,
2932 59..89 '{ ...f(s) }': T
2933 69..70 's': Option<i32>
2934 73..77 'None': Option<i32>
2937 85..86 's': Option<i32>
2943 fn infer_box_fn_arg() {
2944 // The type mismatch is because we don't define Unsize and CoerceUnsized
2945 check_infer_with_mismatches(
2947 //- minicore: fn, deref, option
2948 #[lang = "owned_box"]
2949 pub struct Box<T: ?Sized> {
2953 impl<T: ?Sized> core::ops::Deref for Box<T> {
2956 fn deref(&self) -> &T {
2963 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
2967 154..158 'self': &Box<T>
2968 166..193 '{ ... }': &T
2969 176..187 '&self.inner': &*mut T
2970 177..181 'self': &Box<T>
2971 177..187 'self.inner': *mut T
2972 206..296 '{ ...&s); }': ()
2973 216..217 's': Option<i32>
2974 220..224 'None': Option<i32>
2975 234..235 'f': Box<dyn FnOnce(&Option<i32>)>
2976 269..282 'box (|ps| {})': Box<|{unknown}| -> ()>
2977 274..281 '|ps| {}': |{unknown}| -> ()
2978 275..277 'ps': {unknown}
2980 288..289 'f': Box<dyn FnOnce(&Option<i32>)>
2981 288..293 'f(&s)': ()
2982 290..292 '&s': &Option<i32>
2983 291..292 's': Option<i32>
2984 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
2990 fn infer_dyn_fn_output() {
2995 let f: &dyn Fn() -> i32;
3003 fn infer_dyn_fn_once_output() {
3008 let f: dyn FnOnce() -> i32;
3016 fn variable_kinds_1() {
3019 trait Trait<T> { fn get(self, t: T) -> T; }
3021 impl Trait<u128> for S {}
3022 impl Trait<f32> for S {}
3034 fn variable_kinds_2() {
3037 trait Trait { fn get(self) -> Self; }
3038 impl Trait for u128 {}
3039 impl Trait for f32 {}
3051 fn underscore_import() {
3056 fn method(&self) -> u8 { 0 }
3061 impl crate::tr::Tr for Tr {}
3063 use crate::tr::Tr as _;
3078 fn method(&self) -> u8 { 0 }
3095 fn trait_in_scope_with_inner_item() {
3100 fn method(&self) -> u8 { 0 }
3115 46..50 'self': &Self
3118 115..185 '{ ... } }': ()
3119 132..183 '{ ... }': ()
3121 142..153 '().method()': u8
3127 fn inner_use_in_block() {
3132 fn method(&self) -> u8 { 0 }
3148 //^^^^^^^^^^^ {unknown}
3152 //^^^^^^^^^^^ {unknown}
3159 fn nested_inner_function_calling_self() {
3169 17..73 '{ ... } }': ()
3170 39..71 '{ ... }': ()
3172 57..62 'inner': fn inner() -> S
3179 fn infer_default_trait_type_parameter() {
3184 trait Op<RHS=Self> {
3187 fn do_op(self, rhs: RHS) -> Self::Output;
3193 fn do_op(self, rhs: Self) -> Self::Output {
3208 186..206 '{ ... }': bool
3209 196..200 'true': bool
3210 220..277 '{ ...(y); }': ()
3217 264..274 'x.do_op(y)': bool
3224 fn qualified_path_as_qualified_trait() {
3234 fn boo() -> Self::Output {
3241 impl foo::Foo for F {
3244 impl foo::Bar for F {
3245 type Output = <F as foo::Foo>::Target;
3250 let x = <F as Bar>::boo();
3253 132..163 '{ ... }': Bar::Output<Self>
3254 146..153 'loop {}': !
3256 306..358 '{ ...o(); }': ()
3258 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3259 338..355 '<F as ...:boo()': ()
3265 fn renamed_extern_crate_in_block() {
3268 //- /lib.rs crate:lib deps:serde
3269 use serde::Deserialize;
3274 extern crate serde as _serde;
3275 impl _serde::Deserialize for Foo {
3276 fn deserialize() -> u8 { 0 }
3282 //^^^^^^^^^^^^^^^^^^ u8
3285 //- /serde.rs crate:serde
3287 pub trait Deserialize {
3288 fn deserialize() -> u8;
3294 fn bin_op_adt_with_rhs_primitive() {
3295 check_infer_with_mismatches(
3298 pub trait Add<Rhs = Self> {
3300 fn add(self, rhs: Rhs) -> Self::Output;
3303 struct Wrapper(u32);
3304 impl Add<u32> for Wrapper {
3306 fn add(self, rhs: u32) -> Wrapper {
3311 let wrapped = Wrapper(10);
3313 let res = wrapped + num;
3319 192..196 'self': Wrapper
3321 219..247 '{ ... }': Wrapper
3322 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3323 229..241 'Wrapper(rhs)': Wrapper
3325 259..345 '{ ...um; }': ()
3326 269..276 'wrapped': Wrapper
3327 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3328 279..290 'Wrapper(10)': Wrapper
3332 322..325 'res': Wrapper
3333 328..335 'wrapped': Wrapper
3334 328..341 'wrapped + num': Wrapper
3346 fn do_thing(&self) -> Self::Output;
3349 impl T for [u8; 4] {
3350 type Output = usize;
3351 fn do_thing(&self) -> Self::Output {
3356 impl T for [u8; 2] {
3358 fn do_thing(&self) -> Self::Output {
3365 let v2 = v.do_thing();
3367 let v4 = v3.do_thing();
3371 44..48 'self': &Self
3372 133..137 'self': &[u8; 4]
3373 155..172 '{ ... }': usize
3375 236..240 'self': &[u8; 2]
3376 258..275 '{ ... }': u8
3378 289..392 '{ ...g(); }': ()
3379 299..300 'v': [u8; 2]
3380 303..311 '[0u8; 2]': [u8; 2]
3384 326..327 'v': [u8; 2]
3385 326..338 'v.do_thing()': u8
3386 348..350 'v3': [u8; 4]
3387 353..361 '[0u8; 4]': [u8; 4]
3390 371..373 'v4': usize
3391 376..378 'v3': [u8; 4]
3392 376..389 'v3.do_thing()': usize
3398 fn const_generics() {
3403 fn do_thing(&self) -> Self::Output;
3406 impl<const L: usize> T for [u8; L] {
3407 type Output = [u8; L];
3408 fn do_thing(&self) -> Self::Output {
3415 let v2 = v.do_thing();
3419 44..48 'self': &Self
3420 151..155 'self': &[u8; L]
3421 173..194 '{ ... }': [u8; L]
3422 183..188 '*self': [u8; L]
3423 184..188 'self': &[u8; L]
3424 208..260 '{ ...g(); }': ()
3425 218..219 'v': [u8; 2]
3426 222..230 '[0u8; 2]': [u8; 2]
3429 240..242 'v2': [u8; 2]
3430 245..246 'v': [u8; 2]
3431 245..257 'v.do_thing()': [u8; 2]
3437 fn fn_returning_unit() {
3438 check_infer_with_mismatches(
3441 fn test<F: FnOnce()>(f: F) {
3446 27..51 '{ ...f(); }': ()
3455 fn trait_in_scope_of_trait_impl() {
3461 fn bar(self) -> usize { 0 }
3464 impl foo::Foo for u32 {
3466 let _x = self.bar();
3473 82..87 '{ 0 }': usize
3475 131..135 'self': u32
3476 137..173 '{ ... }': ()
3477 151..153 '_x': usize
3478 156..160 'self': u32
3479 156..166 'self.bar()': usize
3485 fn infer_async_ret_type() {
3488 //- minicore: future, result
3492 fn collect<B: Convert>(self) -> B {
3500 impl Convert for u32 {
3501 fn new() -> Self { 0 }
3504 async fn get_accounts() -> Result<u32, ()> {
3505 let ret = Fooey.collect();
3506 // ^^^^^^^^^^^^^^^ u32
3515 check!(block_local_impls);
3524 impl Trait<u32> for S {
3525 fn foo(&self) -> u32 { 0 }
3537 check!(block_local_impls);
3546 impl Trait<u32> for S {
3547 fn foo(&self) -> u32 { 0 }
3559 check!(block_local_impls);
3571 impl Trait<S1> for S2 {
3572 fn foo(&self) -> S1 { S1 }
3584 fn associated_type_sized_bounds() {
3589 trait IsSized { const IS_SIZED: Yes; }
3590 impl<T: Sized> IsSized for T { const IS_SIZED: Yes = Yes; }
3593 type Explicit: Sized;
3595 type Relaxed: ?Sized;
3598 F::Explicit::IS_SIZED;
3599 F::Implicit::IS_SIZED;
3600 F::Relaxed::IS_SIZED;
3605 212..295 '{ ...ZED; }': ()
3606 218..239 'F::Exp..._SIZED': Yes
3607 245..266 'F::Imp..._SIZED': Yes
3608 272..292 'F::Rel..._SIZED': {unknown}