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
1259 fn infer_from_return_pos_impl_trait() {
1260 check_infer_with_mismatches(
1262 //- minicore: fn, sized
1265 impl<T> Trait<T> for Bar<T> {}
1266 fn foo<const C: u8, T>() -> (impl FnOnce(&str, T), impl Trait<u8>) {
1267 (|input, t| {}, Bar(C))
1271 134..165 '{ ...(C)) }': (|&str, T| -> (), Bar<u8>)
1272 140..163 '(|inpu...ar(C))': (|&str, T| -> (), Bar<u8>)
1273 141..154 '|input, t| {}': |&str, T| -> ()
1274 142..147 'input': &str
1277 156..159 'Bar': Bar<u8>(u8) -> Bar<u8>
1278 156..162 'Bar(C)': Bar<u8>
1291 fn foo2(&self) -> i64;
1293 fn bar() -> dyn Trait<u64> {}
1295 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1307 29..33 'self': &Self
1308 54..58 'self': &Self
1309 97..99 '{}': dyn Trait<u64>
1310 109..110 'x': dyn Trait<u64>
1311 128..129 'y': &dyn Trait<u64>
1312 148..265 '{ ...2(); }': ()
1313 154..155 'x': dyn Trait<u64>
1314 161..162 'y': &dyn Trait<u64>
1315 172..173 'z': dyn Trait<u64>
1316 176..179 'bar': fn bar() -> dyn Trait<u64>
1317 176..181 'bar()': dyn Trait<u64>
1318 187..188 'x': dyn Trait<u64>
1319 187..194 'x.foo()': u64
1320 200..201 'y': &dyn Trait<u64>
1321 200..207 'y.foo()': u64
1322 213..214 'z': dyn Trait<u64>
1323 213..220 'z.foo()': u64
1324 226..227 'x': dyn Trait<u64>
1325 226..234 'x.foo2()': i64
1326 240..241 'y': &dyn Trait<u64>
1327 240..248 'y.foo2()': i64
1328 254..255 'z': dyn Trait<u64>
1329 254..262 'z.foo2()': i64
1335 fn dyn_trait_in_impl() {
1340 fn foo(&self) -> (T, U);
1343 impl<T, U> S<T, U> {
1344 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1346 trait Trait2<T, U> {
1347 fn baz(&self) -> (T, U);
1349 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1351 fn test(s: S<u32, i32>) {
1355 32..36 'self': &Self
1356 102..106 'self': &S<T, U>
1357 128..139 '{ loop {} }': &dyn Trait<T, U>
1358 130..137 'loop {}': !
1360 175..179 'self': &Self
1361 251..252 's': S<u32, i32>
1362 267..289 '{ ...z(); }': ()
1363 273..274 's': S<u32, i32>
1364 273..280 's.bar()': &dyn Trait<u32, i32>
1365 273..286 's.bar().baz()': (u32, i32)
1371 fn dyn_trait_bare() {
1376 fn foo(&self) -> u64;
1378 fn bar() -> Trait {}
1380 fn test(x: Trait, y: &Trait) -> u64 {
1389 26..30 'self': &Self
1390 60..62 '{}': dyn Trait
1391 72..73 'x': dyn Trait
1392 82..83 'y': &dyn Trait
1393 100..175 '{ ...o(); }': u64
1394 106..107 'x': dyn Trait
1395 113..114 'y': &dyn Trait
1396 124..125 'z': dyn Trait
1397 128..131 'bar': fn bar() -> dyn Trait
1398 128..133 'bar()': dyn Trait
1399 139..140 'x': dyn Trait
1400 139..146 'x.foo()': u64
1401 152..153 'y': &dyn Trait
1402 152..159 'y.foo()': u64
1403 165..166 'z': dyn Trait
1404 165..172 'z.foo()': u64
1416 a: impl Trait + 'lifetime,
1419 d: impl ('lifetime),
1421 f: impl Trait + ?Sized
1425 28..29 'a': impl Trait
1426 59..60 'b': impl Sized
1427 82..83 'c': impl Trait
1428 103..104 'd': impl Sized
1429 128..129 'e': impl ?Sized
1430 148..149 'f': impl Trait + ?Sized
1437 fn error_bound_chalk() {
1441 fn foo(&self) -> u32 { 0 }
1444 fn test(x: (impl Trait + UnknownTrait)) {
1452 fn assoc_type_bindings() {
1460 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1461 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1462 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1465 impl<T> Trait for S<T> { type Type = T; }
1467 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1478 77..79 '{}': Trait::Type<T>
1485 262..263 'y': impl Trait<Type = i64>
1486 289..397 '{ ...r>); }': ()
1487 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1488 295..301 'get(x)': u32
1490 307..311 'get2': fn get2<u32, T>(T) -> u32
1491 307..314 'get2(x)': u32
1493 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1494 320..326 'get(y)': i64
1495 324..325 'y': impl Trait<Type = i64>
1496 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1497 332..339 'get2(y)': i64
1498 337..338 'y': impl Trait<Type = i64>
1499 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1500 345..356 'get(set(S))': u64
1501 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1502 349..355 'set(S)': S<u64>
1503 353..354 'S': S<u64>
1504 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1505 362..374 'get2(set(S))': u64
1506 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1507 367..373 'set(S)': S<u64>
1508 371..372 'S': S<u64>
1509 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1510 380..394 'get2(S::<str>)': str
1511 385..393 'S::<str>': S<str>
1517 fn impl_trait_assoc_binding_projection_bug() {
1520 //- minicore: iterator
1521 pub trait Language {
1524 pub enum RustLanguage {}
1525 impl Language for RustLanguage {
1526 type Kind = SyntaxKind;
1528 struct SyntaxNode<L> {}
1529 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1532 fn clone(&self) -> Self;
1535 fn api_walkthrough() {
1538 } //^^^^^^^^^^^^ {unknown}
1545 fn projection_eq_within_chalk() {
1554 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1556 fn test<T: Trait1<Type = u32>>(x: T) {
1562 169..185 '{ ...o(); }': ()
1564 175..182 'x.foo()': u32
1570 fn where_clause_trait_in_scope_for_method_resolution() {
1575 fn foo(&self) -> u32 { 0 }
1579 fn test<T: foo::Trait>(x: T) {
1587 fn super_trait_method_resolution() {
1592 fn foo(&self) -> u32 {}
1595 trait Trait1: foo::SuperTrait {}
1596 trait Trait2 where Self: foo::SuperTrait {}
1598 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1603 49..53 'self': &Self
1607 193..222 '{ ...o(); }': ()
1609 199..206 'x.foo()': u32
1611 212..219 'y.foo()': u32
1617 fn super_trait_impl_trait_method_resolution() {
1623 fn foo(&self) -> u32 {}
1626 trait Trait1: foo::SuperTrait {}
1628 fn test(x: &impl Trait1) {
1632 49..53 'self': &Self
1634 115..116 'x': &impl Trait1
1635 132..148 '{ ...o(); }': ()
1636 138..139 'x': &impl Trait1
1637 138..145 'x.foo()': u32
1643 fn super_trait_cycle() {
1644 // This just needs to not crash
1650 fn test<T: A>(x: T) {
1656 49..65 '{ ...o(); }': ()
1658 55..62 'x.foo()': {unknown}
1664 fn super_trait_assoc_type_bounds() {
1667 trait SuperTrait { type Type; }
1668 trait Trait where Self: SuperTrait {}
1670 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1671 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1674 impl<T> SuperTrait for S<T> { type Type = T; }
1675 impl<T> Trait for S<T> {}
1686 258..279 '{ ...S)); }': ()
1687 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1688 264..276 'get2(set(S))': u64
1689 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1690 269..275 'set(S)': S<u64>
1691 273..274 'S': S<u64>
1698 check_infer_with_mismatches(
1700 trait FnOnce<Args> {
1703 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1706 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1707 f.call_once((1, 2));
1713 155..183 '{ ...2)); }': ()
1715 161..180 'f.call...1, 2))': u128
1716 173..179 '(1, 2)': (u32, u64)
1724 fn fn_ptr_and_item() {
1725 check_infer_with_mismatches(
1728 trait FnOnce<Args> {
1731 fn call_once(self, args: Args) -> Self::Output;
1740 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1741 fn foo(&self) -> (A1, R) { loop {} }
1744 enum Opt<T> { None, Some(T) }
1746 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1750 let bar: Bar<fn(u8) -> u32>;
1754 let f: fn(u8) -> u32;
1760 139..143 'self': &Self
1761 243..247 'self': &Bar<F>
1762 260..271 '{ loop {} }': (A1, R)
1763 262..269 'loop {}': !
1765 355..359 'self': Opt<T>
1767 377..388 '{ loop {} }': Opt<U>
1768 379..386 'loop {}': !
1770 402..518 '{ ...(f); }': ()
1771 412..415 'bar': Bar<fn(u8) -> u32>
1772 441..444 'bar': Bar<fn(u8) -> u32>
1773 441..450 'bar.foo()': (u8, u32)
1774 461..464 'opt': Opt<u8>
1775 483..484 'f': fn(u8) -> u32
1776 505..508 'opt': Opt<u8>
1777 505..515 'opt.map(f)': Opt<u32>
1778 513..514 'f': fn(u8) -> u32
1784 fn fn_trait_deref_with_ty_default() {
1787 //- minicore: deref, fn
1791 fn foo(&self) -> usize {}
1794 struct Lazy<T, F = fn() -> T>(F);
1796 impl<T, F> Lazy<T, F> {
1797 pub fn new(f: F) -> Lazy<T, F> {}
1800 impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> {
1805 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1806 let r1 = lazy1.foo();
1808 fn make_foo_fn() -> Foo {}
1809 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1810 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1811 let r2 = lazy2.foo();
1817 151..153 '{}': Lazy<T, F>
1818 251..497 '{ ...o(); }': ()
1819 261..266 'lazy1': Lazy<Foo, || -> Foo>
1820 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1821 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1822 293..299 '|| Foo': || -> Foo
1824 310..312 'r1': usize
1825 315..320 'lazy1': Lazy<Foo, || -> Foo>
1826 315..326 'lazy1.foo()': usize
1827 368..383 'make_foo_fn_ptr': fn() -> Foo
1828 399..410 'make_foo_fn': fn make_foo_fn() -> Foo
1829 420..425 'lazy2': Lazy<Foo, fn() -> Foo>
1830 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1831 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1832 452..467 'make_foo_fn_ptr': fn() -> Foo
1833 478..480 'r2': usize
1834 483..488 'lazy2': Lazy<Foo, fn() -> Foo>
1835 483..494 'lazy2.foo()': usize
1843 check_infer_with_mismatches(
1846 enum Option<T> { Some(T), None }
1848 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1852 let x = Option::Some(1u32);
1855 let y: Option<i64> = x.map(|_v| 1);
1858 86..90 'self': Option<T>
1860 111..122 '{ loop {} }': Option<U>
1861 113..120 'loop {}': !
1863 136..255 '{ ... 1); }': ()
1864 146..147 'x': Option<u32>
1865 150..162 'Option::Some': Some<u32>(u32) -> Option<u32>
1866 150..168 'Option...(1u32)': Option<u32>
1867 163..167 '1u32': u32
1868 174..175 'x': Option<u32>
1869 174..190 'x.map(...v + 1)': Option<u32>
1870 180..189 '|v| v + 1': |u32| -> u32
1873 184..189 'v + 1': u32
1875 196..197 'x': Option<u32>
1876 196..212 'x.map(... 1u64)': Option<u64>
1877 202..211 '|_v| 1u64': |u32| -> u64
1879 207..211 '1u64': u64
1880 222..223 'y': Option<i64>
1881 239..240 'x': Option<u32>
1882 239..252 'x.map(|_v| 1)': Option<i64>
1883 245..251 '|_v| 1': |u32| -> i64
1894 //- minicore: add, fn
1896 impl core::ops::Add for u64 {
1898 fn add(self, rhs: u64) -> Self::Output {0}
1901 impl core::ops::Add for u128 {
1903 fn add(self, rhs: u128) -> Self::Output {0}
1906 fn test<F: FnOnce(u32) -> u64>(f: F) {
1912 //^^^^^^^^^ |u64| -> u64
1915 let h = |v| 1u128 + v;
1916 //^^^^^^^^^^^^^ |u128| -> u128
1922 fn closure_as_argument_inference_order() {
1923 check_infer_with_mismatches(
1926 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
1927 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
1931 fn method(self) -> u64;
1933 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
1934 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
1938 let x1 = foo1(S, |s| s.method());
1939 let x2 = foo2(|s| s.method(), S);
1940 let x3 = S.foo1(S, |s| s.method());
1941 let x4 = S.foo2(|s| s.method(), S);
1946 50..61 '{ loop {} }': U
1951 112..123 '{ loop {} }': U
1952 114..121 'loop {}': !
1958 233..244 '{ loop {} }': U
1959 235..242 'loop {}': !
1964 305..316 '{ loop {} }': U
1965 307..314 'loop {}': !
1967 330..489 '{ ... S); }': ()
1969 345..349 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
1970 345..368 'foo1(S...hod())': u64
1972 353..367 '|s| s.method()': |S| -> u64
1975 357..367 's.method()': u64
1977 383..387 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
1978 383..406 'foo2(|...(), S)': u64
1979 388..402 '|s| s.method()': |S| -> u64
1982 392..402 's.method()': u64
1986 421..446 'S.foo1...hod())': u64
1988 431..445 '|s| s.method()': |S| -> u64
1991 435..445 's.method()': u64
1994 461..486 'S.foo2...(), S)': u64
1995 468..482 '|s| s.method()': |S| -> u64
1998 472..482 's.method()': u64
2005 fn fn_item_fn_trait() {
2013 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2017 } //^^^^^^^^^^^^^^^^^^ S
2023 fn unselected_projection_in_trait_env_1() {
2032 fn foo(&self) -> u32;
2035 fn test<T: Trait>() where T::Item: Trait2 {
2036 let x: T::Item = no_matter;
2044 fn unselected_projection_in_trait_env_2() {
2052 fn foo(&self) -> u32;
2055 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2056 let x: T::Item = no_matter;
2064 fn unselected_projection_on_impl_self() {
2071 fn f(&self, x: Self::Item);
2078 fn f(&self, x: Self::Item) { let y = x; }
2085 fn f(&self, x: <Self>::Item) { let y = x; }
2088 40..44 'self': &Self
2089 46..47 'x': Trait::Item<Self>
2092 147..161 '{ let y = x; }': ()
2095 228..232 'self': &S2
2097 251..265 '{ let y = x; }': ()
2105 fn unselected_projection_on_trait_self() {
2111 fn f(&self) -> Self::Item { loop {} }
2127 fn unselected_projection_chalk_fold() {
2131 trait Fold<I: Interner, TI = I> {
2135 struct Ty<I: Interner> {}
2136 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2137 type Result = Ty<TI>;
2140 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2147 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2149 } //^^^^^^^^^^^^^^^^^ Ty<I>
2155 fn trait_impl_self_ty() {
2164 impl Trait<Self> for S {}
2174 fn trait_impl_self_ty_cycle() {
2183 impl Trait for S<Self> {}
2187 } //^^^^^^^ {unknown}
2193 fn unselected_projection_in_trait_env_cycle_1() {
2194 // This is not a cycle, because the `T: Trait2<T::Item>` bound depends only on the `T: Trait`
2195 // bound, not on itself (since only `Trait` can define `Item`).
2204 fn test<T: Trait>() where T: Trait2<T::Item> {
2205 let x: T::Item = no_matter;
2206 } //^^^^^^^^^ Trait::Item<T>
2212 fn unselected_projection_in_trait_env_cycle_2() {
2213 // this is a legitimate cycle
2221 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2222 let x: T::Item = no_matter;
2223 } //^^^^^^^^^ {unknown}
2229 fn unselected_projection_in_trait_env_cycle_3() {
2230 // this is a cycle for rustc; we currently accept it
2239 fn test<T>() where T: Trait<OtherItem = T::Item> {
2240 let x: T::Item = no_matter;
2241 } //^^^^^^^^^ Trait::Item<T>
2247 fn unselected_projection_in_trait_env_no_cycle() {
2248 // this is not a cycle
2256 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2258 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2261 fn len(&self) -> usize;
2264 pub trait UnificationStoreMut: UnificationStoreBase {
2265 fn push(&mut self, value: Self::Key);
2268 fn test<T>(t: T) where T: UnificationStoreMut {
2273 } //^^^^^^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2279 fn inline_assoc_type_bounds_1() {
2285 trait OtherTrait<T> {
2289 // workaround for Chalk assoc type normalization problems
2291 impl<T: Iterator> Iterator for S<T> {
2292 type Item = <T as Iterator>::Item;
2295 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2296 let x: <S<I> as Iterator>::Item;
2304 fn inline_assoc_type_bounds_2() {
2311 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2312 let x: <<I as Iterator>::Item as Iterator>::Item;
2320 fn proc_macro_server_types() {
2323 macro_rules! with_api {
2324 ($S:ident, $self:ident, $m:ident) => {
2327 fn new() -> $S::TokenStream;
2334 macro_rules! associated_item {
2335 (type TokenStream) =>
2336 (type TokenStream: 'static;);
2338 (type Group: 'static;);
2339 ($($item:tt)*) => ($($item)*;)
2341 macro_rules! declare_server_traits {
2343 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2346 $(associated_item!(type $name);)*
2349 $(pub trait $name: Types {
2350 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2353 pub trait Server: Types $(+ $name)* {}
2354 impl<S: Types $(+ $name)*> Server for S {}
2358 with_api!(Self, self_, declare_server_traits);
2362 impl Types for Rustc {
2363 type TokenStream = T;
2367 fn make<T>() -> T { loop {} }
2368 impl TokenStream for Rustc {
2369 fn new() -> Self::TokenStream {
2370 let group: Self::Group = make();
2375 1061..1072 '{ loop {} }': T
2376 1063..1070 'loop {}': !
2378 1136..1199 '{ ... }': T
2379 1150..1155 'group': G
2380 1171..1175 'make': fn make<G>() -> G
2381 1171..1177 'make()': G
2382 1187..1191 'make': fn make<T>() -> T
2383 1187..1193 'make()': T
2389 fn unify_impl_trait() {
2390 check_infer_with_mismatches(
2395 fn foo(x: impl Trait<u32>) { loop {} }
2396 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2399 impl<T> Trait<T> for S<T> {}
2401 fn default<T>() -> T { loop {} }
2403 fn test() -> impl Trait<i32> {
2404 let s1 = S(default());
2406 let x: i32 = bar(S(default()));
2410 26..27 'x': impl Trait<u32>
2411 46..57 '{ loop {} }': ()
2414 68..69 'x': impl Trait<T>
2415 91..102 '{ loop {} }': T
2416 93..100 'loop {}': !
2418 171..182 '{ loop {} }': T
2419 173..180 'loop {}': !
2421 213..309 '{ ...t()) }': S<i32>
2422 223..225 's1': S<u32>
2423 228..229 'S': S<u32>(u32) -> S<u32>
2424 228..240 'S(default())': S<u32>
2425 230..237 'default': fn default<u32>() -> u32
2426 230..239 'default()': u32
2427 246..249 'foo': fn foo(S<u32>)
2428 246..253 'foo(s1)': ()
2429 250..252 's1': S<u32>
2431 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2432 272..289 'bar(S(...lt()))': i32
2433 276..277 'S': S<i32>(i32) -> S<i32>
2434 276..288 'S(default())': S<i32>
2435 278..285 'default': fn default<i32>() -> i32
2436 278..287 'default()': i32
2437 295..296 'S': S<i32>(i32) -> S<i32>
2438 295..307 'S(default())': S<i32>
2439 297..304 'default': fn default<i32>() -> i32
2440 297..306 'default()': i32
2446 fn assoc_types_from_bounds() {
2465 f::<(), _>(|z| { z; });
2470 132..163 '{ ... }); }': ()
2471 138..148 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2472 138..160 'f::<()... z; })': ()
2473 149..159 '|z| { z; }': |&()| -> ()
2475 153..159 '{ z; }': ()
2482 fn associated_type_bound() {
2486 type Item: OtherTrait<u32>;
2488 pub trait OtherTrait<T> {
2492 // this is just a workaround for chalk#234
2494 impl<T: Trait> Trait for S<T> {
2495 type Item = <T as Trait>::Item;
2498 fn test<T: Trait>() {
2499 let y: <S<T> as Trait>::Item = no_matter;
2507 fn dyn_trait_through_chalk() {
2511 struct Box<T: ?Sized> {}
2512 impl<T: ?Sized> core::ops::Deref for Box<T> {
2519 fn test(x: Box<dyn Trait>) {
2527 fn string_to_owned() {
2533 fn to_owned(&self) -> Self::Owned;
2535 impl ToOwned for str {
2536 type Owned = String;
2540 } //^^^^^^^^^^^^^^^^ String
2546 fn iterator_chain() {
2547 check_infer_with_mismatches(
2549 //- minicore: fn, option
2550 pub trait Iterator {
2553 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2555 F: FnMut(Self::Item) -> Option<B>,
2558 fn for_each<F>(self, f: F)
2560 F: FnMut(Self::Item),
2564 pub trait IntoIterator {
2566 type IntoIter: Iterator<Item = Self::Item>;
2567 fn into_iter(self) -> Self::IntoIter;
2570 pub struct FilterMap<I, F> { }
2571 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2573 F: FnMut(I::Item) -> Option<B>,
2578 #[stable(feature = "rust1", since = "1.0.0")]
2579 impl<I: Iterator> IntoIterator for I {
2580 type Item = I::Item;
2583 fn into_iter(self) -> I {
2590 fn new() -> Self { loop {} }
2593 impl<T> IntoIterator for Vec<T> {
2595 type IntoIter = IntoIter<T>;
2598 pub struct IntoIter<T> { }
2599 impl<T> Iterator for IntoIter<T> {
2604 Vec::<i32>::new().into_iter()
2605 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2606 .for_each(|y| { y; });
2611 152..163 '{ loop {} }': FilterMap<Self, F>
2612 154..161 'loop {}': !
2614 184..188 'self': Self
2616 240..251 '{ loop {} }': ()
2617 242..249 'loop {}': !
2619 360..364 'self': Self
2621 700..720 '{ ... }': I
2623 779..790 '{ loop {} }': Vec<T>
2624 781..788 'loop {}': !
2626 977..1104 '{ ... }); }': ()
2627 983..998 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2628 983..1000 'Vec::<...:new()': Vec<i32>
2629 983..1012 'Vec::<...iter()': IntoIter<i32>
2630 983..1075 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2631 983..1101 'Vec::<... y; })': ()
2632 1029..1074 '|x| if...None }': |i32| -> Option<u32>
2634 1033..1074 'if x >...None }': Option<u32>
2636 1036..1041 'x > 0': bool
2638 1042..1060 '{ Some...u32) }': Option<u32>
2639 1044..1048 'Some': Some<u32>(u32) -> Option<u32>
2640 1044..1058 'Some(x as u32)': Option<u32>
2642 1049..1057 'x as u32': u32
2643 1066..1074 '{ None }': Option<u32>
2644 1068..1072 'None': Option<u32>
2645 1090..1100 '|y| { y; }': |u32| -> ()
2647 1094..1100 '{ y; }': ()
2670 fn foo() -> Self::Output;
2674 type Output = T::OutputA;
2675 fn foo() -> Self::Output { loop {} }
2686 fn trait_object_no_coercion() {
2687 check_infer_with_mismatches(
2691 fn foo(x: &dyn Foo) {}
2693 fn test(x: &dyn Foo) {
2697 21..22 'x': &dyn Foo
2699 46..47 'x': &dyn Foo
2700 59..74 '{ foo(x); }': ()
2701 65..68 'foo': fn foo(&dyn Foo)
2703 69..70 'x': &dyn Foo
2710 check_infer_with_mismatches(
2714 impl Copy for IsCopy {}
2717 trait Test { fn test(&self) -> bool; }
2718 impl<T: Copy> Test for T {}
2723 (IsCopy, IsCopy).test();
2724 (IsCopy, NotCopy).test();
2727 78..82 'self': &Self
2728 134..235 '{ ...t(); }': ()
2729 140..146 'IsCopy': IsCopy
2730 140..153 'IsCopy.test()': bool
2731 159..166 'NotCopy': NotCopy
2732 159..173 'NotCopy.test()': {unknown}
2733 179..195 '(IsCop...sCopy)': (IsCopy, IsCopy)
2734 179..202 '(IsCop...test()': bool
2735 180..186 'IsCopy': IsCopy
2736 188..194 'IsCopy': IsCopy
2737 208..225 '(IsCop...tCopy)': (IsCopy, NotCopy)
2738 208..232 '(IsCop...test()': {unknown}
2739 209..215 'IsCopy': IsCopy
2740 217..224 'NotCopy': NotCopy
2746 fn builtin_fn_def_copy() {
2747 check_infer_with_mismatches(
2751 fn bar<T: Copy>(T) -> T {}
2752 struct Struct(usize);
2753 enum Enum { Variant(usize) }
2755 trait Test { fn test(&self) -> bool; }
2756 impl<T: Copy> Test for T {}
2762 Enum::Variant.test();
2766 28..29 'T': {unknown}
2768 36..38: expected T, got ()
2769 113..117 'self': &Self
2770 169..249 '{ ...t(); }': ()
2771 175..178 'foo': fn foo()
2772 175..185 'foo.test()': bool
2773 191..194 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2774 191..201 'bar.test()': bool
2775 207..213 'Struct': Struct(usize) -> Struct
2776 207..220 'Struct.test()': bool
2777 226..239 'Enum::Variant': Variant(usize) -> Enum
2778 226..246 'Enum::...test()': bool
2784 fn builtin_fn_ptr_copy() {
2785 check_infer_with_mismatches(
2788 trait Test { fn test(&self) -> bool; }
2789 impl<T: Copy> Test for T {}
2791 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2797 22..26 'self': &Self
2799 86..88 'f2': fn(usize) -> u8
2800 107..109 'f3': fn(u8, u8) -> &u8
2801 130..178 '{ ...t(); }': ()
2803 136..145 'f1.test()': bool
2804 151..153 'f2': fn(usize) -> u8
2805 151..160 'f2.test()': bool
2806 166..168 'f3': fn(u8, u8) -> &u8
2807 166..175 'f3.test()': bool
2813 fn builtin_sized() {
2814 check_infer_with_mismatches(
2817 trait Test { fn test(&self) -> bool; }
2818 impl<T: Sized> Test for T {}
2822 (*"foo").test(); // not Sized
2824 (1u8, *"foo").test(); // not Sized
2827 22..26 'self': &Self
2828 79..194 '{ ...ized }': ()
2830 85..95 '1u8.test()': bool
2831 101..116 '(*"foo").test()': {unknown}
2832 102..108 '*"foo"': str
2833 103..108 '"foo"': &str
2834 135..145 '(1u8, 1u8)': (u8, u8)
2835 135..152 '(1u8, ...test()': bool
2838 158..171 '(1u8, *"foo")': (u8, str)
2839 158..178 '(1u8, ...test()': {unknown}
2841 164..170 '*"foo"': str
2842 165..170 '"foo"': &str
2848 fn integer_range_iterate() {
2851 //- /main.rs crate:main deps:core
2853 for x in 0..100 { x; }
2856 //- /core.rs crate:core
2858 pub struct Range<Idx> {
2865 pub trait Iterator {
2869 pub trait IntoIterator {
2871 type IntoIter: Iterator<Item = Self::Item>;
2874 impl<T> IntoIterator for T where T: Iterator {
2875 type Item = <T as Iterator>::Item;
2876 type IntoIter = Self;
2881 impl Step for i32 {}
2882 impl Step for i64 {}
2884 impl<A: Step> iter::Iterator for ops::Range<A> {
2892 fn infer_closure_arg() {
2903 let s = Option::None;
2904 let f = |x: Option<i32>| {};
2908 52..126 '{ ...)(s) }': ()
2909 62..63 's': Option<i32>
2910 66..78 'Option::None': Option<i32>
2911 88..89 'f': |Option<i32>| -> ()
2912 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
2913 93..94 'x': Option<i32>
2915 117..124 '(&f)(s)': ()
2916 118..120 '&f': &|Option<i32>| -> ()
2917 119..120 'f': |Option<i32>| -> ()
2918 122..123 's': Option<i32>
2924 fn dyn_fn_param_informs_call_site_closure_signature() {
2925 cov_mark::check!(dyn_fn_param_informs_call_site_closure_signature);
2928 //- minicore: fn, coerce_unsized
2931 fn inherent(&self) -> u8 { 0 }
2933 fn take_dyn_fn(f: &dyn Fn(S)) {}
2936 take_dyn_fn(&|x| { x.inherent(); });
2944 fn infer_fn_trait_arg() {
2945 check_infer_with_mismatches(
2947 //- minicore: fn, option
2948 fn foo<F, T>(f: F) -> T
2950 F: Fn(Option<i32>) -> T,
2958 59..89 '{ ...f(s) }': T
2959 69..70 's': Option<i32>
2960 73..77 'None': Option<i32>
2963 85..86 's': Option<i32>
2969 fn infer_box_fn_arg() {
2970 // The type mismatch is because we don't define Unsize and CoerceUnsized
2971 check_infer_with_mismatches(
2973 //- minicore: fn, deref, option
2974 #[lang = "owned_box"]
2975 pub struct Box<T: ?Sized> {
2979 impl<T: ?Sized> core::ops::Deref for Box<T> {
2982 fn deref(&self) -> &T {
2989 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
2993 154..158 'self': &Box<T>
2994 166..193 '{ ... }': &T
2995 176..187 '&self.inner': &*mut T
2996 177..181 'self': &Box<T>
2997 177..187 'self.inner': *mut T
2998 206..296 '{ ...&s); }': ()
2999 216..217 's': Option<i32>
3000 220..224 'None': Option<i32>
3001 234..235 'f': Box<dyn FnOnce(&Option<i32>)>
3002 269..282 'box (|ps| {})': Box<|&Option<i32>| -> ()>
3003 274..281 '|ps| {}': |&Option<i32>| -> ()
3004 275..277 'ps': &Option<i32>
3006 288..289 'f': Box<dyn FnOnce(&Option<i32>)>
3007 288..293 'f(&s)': ()
3008 290..292 '&s': &Option<i32>
3009 291..292 's': Option<i32>
3010 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|&Option<i32>| -> ()>
3016 fn infer_dyn_fn_output() {
3021 let f: &dyn Fn() -> i32;
3029 fn infer_dyn_fn_once_output() {
3034 let f: dyn FnOnce() -> i32;
3042 fn variable_kinds_1() {
3045 trait Trait<T> { fn get(self, t: T) -> T; }
3047 impl Trait<u128> for S {}
3048 impl Trait<f32> for S {}
3060 fn variable_kinds_2() {
3063 trait Trait { fn get(self) -> Self; }
3064 impl Trait for u128 {}
3065 impl Trait for f32 {}
3077 fn underscore_import() {
3082 fn method(&self) -> u8 { 0 }
3087 impl crate::tr::Tr for Tr {}
3089 use crate::tr::Tr as _;
3104 fn method(&self) -> u8 { 0 }
3121 fn trait_in_scope_with_inner_item() {
3126 fn method(&self) -> u8 { 0 }
3141 46..50 'self': &Self
3144 115..185 '{ ... } }': ()
3145 132..183 '{ ... }': ()
3147 142..153 '().method()': u8
3153 fn inner_use_in_block() {
3158 fn method(&self) -> u8 { 0 }
3174 //^^^^^^^^^^^ {unknown}
3178 //^^^^^^^^^^^ {unknown}
3185 fn nested_inner_function_calling_self() {
3195 17..73 '{ ... } }': ()
3198 57..62 'inner': fn inner() -> S
3205 fn infer_default_trait_type_parameter() {
3210 trait Op<RHS=Self> {
3213 fn do_op(self, rhs: RHS) -> Self::Output;
3219 fn do_op(self, rhs: Self) -> Self::Output {
3234 186..206 '{ ... }': bool
3235 196..200 'true': bool
3236 220..277 '{ ...(y); }': ()
3243 264..274 'x.do_op(y)': bool
3250 fn qualified_path_as_qualified_trait() {
3260 fn boo() -> Self::Output {
3267 impl foo::Foo for F {
3270 impl foo::Bar for F {
3271 type Output = <F as foo::Foo>::Target;
3276 let x = <F as Bar>::boo();
3279 132..163 '{ ... }': Bar::Output<Self>
3280 146..153 'loop {}': !
3282 306..358 '{ ...o(); }': ()
3284 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3285 338..355 '<F as ...:boo()': ()
3291 fn renamed_extern_crate_in_block() {
3294 //- /lib.rs crate:lib deps:serde
3295 use serde::Deserialize;
3300 extern crate serde as _serde;
3301 impl _serde::Deserialize for Foo {
3302 fn deserialize() -> u8 { 0 }
3308 //^^^^^^^^^^^^^^^^^^ u8
3311 //- /serde.rs crate:serde
3313 pub trait Deserialize {
3314 fn deserialize() -> u8;
3320 fn bin_op_adt_with_rhs_primitive() {
3321 check_infer_with_mismatches(
3324 pub trait Add<Rhs = Self> {
3326 fn add(self, rhs: Rhs) -> Self::Output;
3329 struct Wrapper(u32);
3330 impl Add<u32> for Wrapper {
3332 fn add(self, rhs: u32) -> Wrapper {
3337 let wrapped = Wrapper(10);
3339 let res = wrapped + num;
3345 192..196 'self': Wrapper
3347 219..247 '{ ... }': Wrapper
3348 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3349 229..241 'Wrapper(rhs)': Wrapper
3351 259..345 '{ ...um; }': ()
3352 269..276 'wrapped': Wrapper
3353 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3354 279..290 'Wrapper(10)': Wrapper
3358 322..325 'res': Wrapper
3359 328..335 'wrapped': Wrapper
3360 328..341 'wrapped + num': Wrapper
3372 fn do_thing(&self) -> Self::Output;
3375 impl T for [u8; 4] {
3376 type Output = usize;
3377 fn do_thing(&self) -> Self::Output {
3382 impl T for [u8; 2] {
3384 fn do_thing(&self) -> Self::Output {
3391 let v2 = v.do_thing();
3393 let v4 = v3.do_thing();
3397 44..48 'self': &Self
3398 133..137 'self': &[u8; 4]
3399 155..172 '{ ... }': usize
3401 236..240 'self': &[u8; 2]
3402 258..275 '{ ... }': u8
3404 289..392 '{ ...g(); }': ()
3405 299..300 'v': [u8; 2]
3406 303..311 '[0u8; 2]': [u8; 2]
3410 326..327 'v': [u8; 2]
3411 326..338 'v.do_thing()': u8
3412 348..350 'v3': [u8; 4]
3413 353..361 '[0u8; 4]': [u8; 4]
3416 371..373 'v4': usize
3417 376..378 'v3': [u8; 4]
3418 376..389 'v3.do_thing()': usize
3424 fn const_generics() {
3429 fn do_thing(&self) -> Self::Output;
3432 impl<const L: usize> T for [u8; L] {
3433 type Output = [u8; L];
3434 fn do_thing(&self) -> Self::Output {
3441 let v2 = v.do_thing();
3445 44..48 'self': &Self
3446 151..155 'self': &[u8; L]
3447 173..194 '{ ... }': [u8; L]
3448 183..188 '*self': [u8; L]
3449 184..188 'self': &[u8; L]
3450 208..260 '{ ...g(); }': ()
3451 218..219 'v': [u8; 2]
3452 222..230 '[0u8; 2]': [u8; 2]
3455 240..242 'v2': [u8; 2]
3456 245..246 'v': [u8; 2]
3457 245..257 'v.do_thing()': [u8; 2]
3463 fn fn_returning_unit() {
3464 check_infer_with_mismatches(
3467 fn test<F: FnOnce()>(f: F) {
3472 27..51 '{ ...f(); }': ()
3481 fn trait_in_scope_of_trait_impl() {
3487 fn bar(self) -> usize { 0 }
3490 impl foo::Foo for u32 {
3492 let _x = self.bar();
3499 82..87 '{ 0 }': usize
3501 131..135 'self': u32
3502 137..173 '{ ... }': ()
3503 151..153 '_x': usize
3504 156..160 'self': u32
3505 156..166 'self.bar()': usize
3511 fn infer_async_ret_type() {
3514 //- minicore: future, result
3518 fn collect<B: Convert>(self) -> B {
3526 impl Convert for u32 {
3527 fn new() -> Self { 0 }
3530 async fn get_accounts() -> Result<u32, ()> {
3531 let ret = Fooey.collect();
3532 // ^^^^^^^^^^^^^^^ u32
3541 check!(block_local_impls);
3550 impl Trait<u32> for S {
3551 fn foo(&self) -> u32 { 0 }
3563 check!(block_local_impls);
3572 impl Trait<u32> for S {
3573 fn foo(&self) -> u32 { 0 }
3585 check!(block_local_impls);
3597 impl Trait<S1> for S2 {
3598 fn foo(&self) -> S1 { S1 }
3610 fn associated_type_sized_bounds() {
3615 trait IsSized { const IS_SIZED: Yes; }
3616 impl<T: Sized> IsSized for T { const IS_SIZED: Yes = Yes; }
3619 type Explicit: Sized;
3621 type Relaxed: ?Sized;
3624 F::Explicit::IS_SIZED;
3625 F::Implicit::IS_SIZED;
3626 F::Relaxed::IS_SIZED;
3631 212..295 '{ ...ZED; }': ()
3632 218..239 'F::Exp..._SIZED': Yes
3633 245..266 'F::Imp..._SIZED': Yes
3634 272..292 'F::Rel..._SIZED': {unknown}
3643 pub struct Key<K, V, P = (K, V)> {}
3650 impl<K, V> Policy for (K, V) {
3655 pub struct KeyMap<KEY> {}
3657 impl<P: Policy> KeyMap<Key<P::K, P::V, P>> {
3658 pub fn get(&self, key: &P::K) -> P::V {
3664 struct FunctionId {}
3667 let key_map: &KeyMap<Key<Fn, FunctionId>> = loop {};
3669 let result = key_map.get(key);