2 use expect_test::expect;
4 use super::{check, check_infer, check_infer_with_mismatches, check_no_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>>
86 fn auto_sized_async_block() {
89 //- minicore: future, sized
91 use core::future::Future;
92 struct MyFut<Fut>(Fut);
94 impl<Fut> Future for MyFut<Fut>
97 type Output = Fut::Output;
99 async fn reproduction() -> usize {
100 let f = async {999usize};
113 pub trait Unsize<T: ?Sized> {}
115 #[lang = "coerce_unsized"]
116 pub trait CoerceUnsized<T> {}
118 pub unsafe trait Allocator {}
121 unsafe impl Allocator for Global {}
123 #[lang = "owned_box"]
125 pub struct Box<T: ?Sized, A: Allocator = Global>;
127 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
129 fn send() -> Box<dyn Future<Output = ()> + Send + 'static>{
133 fn not_send() -> Box<dyn Future<Output = ()> + 'static> {
144 //- /main.rs crate:main deps:core
146 let r: Result<i32, u64> = Result::Ok(1);
151 //- /core.rs crate:core
160 pub enum Result<O, E> {
165 impl<O, E> crate::ops::Try for Result<O, E> {
173 pub use crate::{result::*, ops::*};
181 fn infer_try_trait_v2() {
184 //- /main.rs crate:main deps:core
186 let r: Result<i32, u64> = Result::Ok(1);
191 //- /core.rs crate:core
194 pub trait Try: FromResidual {
198 pub trait FromResidual<R = <Self as Try>::Residual> {}
201 pub use self::try_trait::FromResidual;
202 pub use self::try_trait::Try;
207 impl<T> From<T> for T {}
211 use crate::convert::From;
212 use crate::ops::{Try, FromResidual};
214 pub enum Infallible {}
215 pub enum Result<O, E> {
220 impl<O, E> Try for Result<O, E> {
222 type Error = Result<Infallible, E>;
225 impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
230 pub use crate::result::*;
238 fn infer_for_loop() {
241 //- /main.rs crate:main deps:core,alloc
243 use alloc::collections::Vec;
253 //- /core.rs crate:core
255 pub trait IntoIterator {
261 pub use crate::iter::*;
265 //- /alloc.rs crate:alloc deps:core
267 pub mod collections {
270 pub fn new() -> Self { Vec {} }
271 pub fn push(&mut self, t: T) { }
274 impl<T> IntoIterator for Vec<T> {
286 //- /main.rs crate:main deps:std
290 impl std::ops::Neg for Bar {
300 //- /std.rs crate:std
301 #[prelude_import] use ops::*;
316 //- /main.rs crate:main deps:std
320 impl std::ops::Not for Bar {
330 //- /std.rs crate:std
331 #[prelude_import] use ops::*;
343 fn infer_from_bound_1() {
348 impl<U> Trait<U> for S<U> {}
349 fn foo<T: Trait<u32>>(t: T) {}
359 fn infer_from_bound_2() {
364 impl<U> Trait<U> for S<U> {}
365 fn foo<U, T: Trait<U>>(t: T) -> U { loop {} }
375 fn trait_default_method_self_bound_implements_trait() {
376 cov_mark::check!(trait_self_implements_self);
380 fn foo(&self) -> i64;
381 fn bar(&self) -> () {
383 // ^^^^^^^^^^ type: i64
390 fn trait_default_method_self_bound_implements_super_trait() {
394 fn foo(&self) -> i64;
396 trait Trait: SuperTrait {
397 fn bar(&self) -> () {
399 // ^^^^^^^^^^ type: i64
406 fn infer_project_associated_type() {
413 impl Iterable for S { type Item = u32; }
414 fn test<T: Iterable>() {
415 let x: <S as Iterable>::Item = 1;
417 let y: <T as Iterable>::Item = u;
418 // ^ Iterable::Item<T>
420 // ^ Iterable::Item<T>
421 let a: <T>::Item = u;
422 // ^ Iterable::Item<T>
428 fn infer_return_associated_type() {
435 impl Iterable for S { type Item = u32; }
436 fn foo1<T: Iterable>(t: T) -> T::Item { loop {} }
437 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item { loop {} }
438 fn foo3<T: Iterable>(t: T) -> <T>::Item { loop {} }
451 fn associated_type_shorthand_from_method_bound() {
459 fn foo(self) -> T::Item where T: Iterable { loop {} }
461 fn test<T: Iterable>() {
464 // ^^^^^^^ Iterable::Item<T>
470 fn associated_type_shorthand_from_self_issue_12484() {
478 fn test(a: Self::A, _: impl Bar) {
487 fn infer_associated_type_bound() {
493 fn test<T: Iterable<Item=u32>>() {
494 let y: T::Item = unknown;
501 fn infer_const_body() {
502 // FIXME make check_types work with other bodies
505 const A: u32 = 1 + 1;
506 static B: u64 = { let x = 1; x };
512 38..54 '{ let ...1; x }': u64
521 fn tuple_struct_fields() {
531 37..86 '{ ... a.1 }': u64
533 51..52 'S': S(i32, u64) -> S
547 fn tuple_struct_with_fn() {
550 struct S(fn(u32) -> u64);
557 43..101 '{ ...0(2) }': u64
559 57..58 'S': S(fn(u32) -> u64) -> S
560 57..67 'S(|i| 2*i)': S
561 59..66 '|i| 2*i': |u32| -> u64
568 81..84 'a.0': fn(u32) -> u64
572 93..96 'a.0': fn(u32) -> u64
580 fn indexing_arrays() {
582 "fn main() { &mut [9][2]; }",
584 10..26 '{ &mut...[2]; }': ()
585 12..23 '&mut [9][2]': &mut {unknown}
586 17..20 '[9]': [i32; 1]
587 17..23 '[9][2]': {unknown}
595 fn infer_ops_index() {
602 impl core::ops::Index<u32> for Bar {
616 fn infer_ops_index_field() {
625 impl core::ops::Index<u32> for Bar {
631 let b = a[1u32].field;
639 fn infer_ops_index_field_autoderef() {
648 impl core::ops::Index<u32> for Bar {
654 let b = (&a[1u32]).field;
662 fn infer_ops_index_int() {
669 impl core::ops::Index<u32> for Bar {
674 impl core::ops::Index<Range> for Bar {
689 fn infer_ops_index_autoderef() {
692 //- minicore: index, slice
694 let a = &[1u32, 2, 3];
707 struct Arc<T: ?Sized>;
708 impl<T: ?Sized> core::ops::Deref for Arc<T> {
714 fn foo(&self) -> u128 { 0 }
719 } //^^^^^^^^^^^^^ (S, u128)
725 fn deref_trait_with_inference_var() {
729 struct Arc<T: ?Sized>;
730 fn new_arc<T: ?Sized>() -> Arc<T> { Arc }
731 impl<T: ?Sized> core::ops::Deref for Arc<T> {
749 fn deref_trait_infinite_recursion() {
755 impl core::ops::Deref for S {
761 } //^^^^^^^ {unknown}
767 fn deref_trait_with_question_mark_size() {
771 struct Arc<T: ?Sized>;
772 impl<T: ?Sized> core::ops::Deref for Arc<T> {
778 fn foo(&self) -> u128 { 0 }
783 } //^^^^^^^^^^^^^ (S, u128)
789 fn deref_trait_with_implicit_sized_requirement_on_inference_var() {
794 impl<T> core::ops::Deref for Foo<T> {
801 let _: Foo<u8> = foo;
808 fn obligation_from_function_clause() {
814 impl Trait<u32> for S {}
816 fn foo<T: Trait<U>, U>(t: T) -> U { loop {} }
826 fn obligation_from_method_clause() {
833 impl Trait<isize> for S {}
837 fn foo<T: Trait<U>, U>(&self, t: T) -> U { loop {} }
848 fn obligation_from_self_method_clause() {
854 impl Trait<i64> for S {}
857 fn foo<U>(&self) -> U where Self: Trait<U> { loop {} }
868 fn obligation_from_impl_clause() {
874 impl Trait<&str> for S {}
877 impl<U, T: Trait<U>> O<T> {
878 fn foo(&self) -> U { loop {} }
889 fn generic_param_env_1() {
893 trait Trait { fn foo(self) -> u128; }
896 impl<T> Trait for T where T: Clone {}
897 fn test<T: Clone>(t: T) { t.foo(); }
904 fn generic_param_env_1_not_met() {
909 trait Trait { fn foo(self) -> u128; }
912 impl<T> Trait for T where T: Clone {}
913 fn test<T>(t: T) { t.foo(); }
920 fn generic_param_env_2() {
923 trait Trait { fn foo(self) -> u128; }
926 fn test<T: Trait>(t: T) { t.foo(); }
933 fn generic_param_env_2_not_met() {
936 trait Trait { fn foo(self) -> u128; }
939 fn test<T>(t: T) { t.foo(); }
946 fn generic_param_env_deref() {
951 impl<T> core::ops::Deref for T where T: Trait {
954 fn test<T: Trait>(t: T) { *t; }
961 fn associated_type_placeholder() {
962 // 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].
969 pub struct RefMutL<T>;
971 impl<T> ApplyL for RefMutL<T> {
972 type Out = <T as ApplyL>::Out;
975 fn test<T: ApplyL>() {
976 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
984 fn associated_type_placeholder_2() {
990 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
992 fn test<T: ApplyL>(t: T) {
1001 fn argument_impl_trait() {
1002 check_infer_with_mismatches(
1007 fn foo2(&self) -> i64;
1009 fn bar(x: impl Trait<u16>) {}
1011 impl<T> Trait<T> for S<T> {}
1013 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
1026 29..33 'self': &Self
1027 54..58 'self': &Self
1028 77..78 'x': impl Trait<u16>
1030 154..155 'x': impl Trait<u64>
1031 174..175 'y': &impl Trait<u32>
1032 195..323 '{ ...2(); }': ()
1033 201..202 'x': impl Trait<u64>
1034 208..209 'y': &impl Trait<u32>
1035 219..220 'z': S<u16>
1036 223..224 'S': S<u16>(u16) -> S<u16>
1037 223..227 'S(1)': S<u16>
1039 233..236 'bar': fn bar(S<u16>)
1040 233..239 'bar(z)': ()
1041 237..238 'z': S<u16>
1042 245..246 'x': impl Trait<u64>
1043 245..252 'x.foo()': u64
1044 258..259 'y': &impl Trait<u32>
1045 258..265 'y.foo()': u32
1046 271..272 'z': S<u16>
1047 271..278 'z.foo()': u16
1048 284..285 'x': impl Trait<u64>
1049 284..292 'x.foo2()': i64
1050 298..299 'y': &impl Trait<u32>
1051 298..306 'y.foo2()': i64
1052 312..313 'z': S<u16>
1053 312..320 'z.foo2()': i64
1059 fn argument_impl_trait_type_args_1() {
1060 check_infer_with_mismatches(
1065 // this function has an implicit Self param, an explicit type param,
1066 // and an implicit impl Trait param!
1067 fn bar<T>(x: impl Trait) -> T { loop {} }
1069 fn foo<T>(x: impl Trait) -> T { loop {} }
1080 <F as Foo>::bar::<u32>(S);
1084 foo::<u32, i32>(S); // we should ignore the extraneous i32
1087 155..156 'x': impl Trait
1088 175..186 '{ loop {} }': T
1089 177..184 'loop {}': !
1091 199..200 'x': impl Trait
1092 219..230 '{ loop {} }': T
1093 221..228 'loop {}': !
1095 300..509 '{ ... i32 }': ()
1096 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1097 306..317 'Foo::bar(S)': {unknown}
1099 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1100 323..341 '<F as ...bar(S)': {unknown}
1102 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1103 347..356 'F::bar(S)': {unknown}
1105 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1106 362..380 'Foo::b...32>(S)': u32
1108 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1109 386..411 '<F as ...32>(S)': u32
1111 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1112 418..424 'foo(S)': {unknown}
1114 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1115 430..443 'foo::<u32>(S)': u32
1117 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1118 449..467 'foo::<...32>(S)': u32
1125 fn argument_impl_trait_type_args_2() {
1126 check_infer_with_mismatches(
1134 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1140 F::<u32>.foo::<i32>(S);
1141 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1145 93..94 'x': impl Trait
1146 118..129 '{ loop {} }': (T, U)
1147 120..127 'loop {}': !
1149 143..283 '{ ...ored }': ()
1150 149..150 'F': F<{unknown}>
1151 149..157 'F.foo(S)': ({unknown}, {unknown})
1153 163..171 'F::<u32>': F<u32>
1154 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1156 184..192 'F::<u32>': F<u32>
1157 184..206 'F::<u3...32>(S)': (u32, i32)
1159 212..220 'F::<u32>': F<u32>
1160 212..239 'F::<u3...32>(S)': (u32, i32)
1167 fn argument_impl_trait_to_fn_pointer() {
1168 check_infer_with_mismatches(
1172 fn foo(x: impl Trait) { loop {} }
1177 let f: fn(S) -> () = foo;
1180 22..23 'x': impl Trait
1181 37..48 '{ loop {} }': ()
1184 90..123 '{ ...foo; }': ()
1186 117..120 'foo': fn foo(S)
1198 fn foo2(&self) -> i64;
1200 fn bar() -> impl Trait<u64> {}
1202 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1214 29..33 'self': &Self
1215 54..58 'self': &Self
1217 110..111 'x': impl Trait<u64>
1218 130..131 'y': &impl Trait<u64>
1219 151..268 '{ ...2(); }': ()
1220 157..158 'x': impl Trait<u64>
1221 164..165 'y': &impl Trait<u64>
1222 175..176 'z': impl Trait<u64>
1223 179..182 'bar': fn bar() -> impl Trait<u64>
1224 179..184 'bar()': impl Trait<u64>
1225 190..191 'x': impl Trait<u64>
1226 190..197 'x.foo()': u64
1227 203..204 'y': &impl Trait<u64>
1228 203..210 'y.foo()': u64
1229 216..217 'z': impl Trait<u64>
1230 216..223 'z.foo()': u64
1231 229..230 'x': impl Trait<u64>
1232 229..237 'x.foo2()': i64
1233 243..244 'y': &impl Trait<u64>
1234 243..251 'y.foo2()': i64
1235 257..258 'z': impl Trait<u64>
1236 257..265 'z.foo2()': i64
1242 fn simple_return_pos_impl_trait() {
1243 cov_mark::check!(lower_rpit);
1250 fn bar() -> impl Trait<u64> { loop {} }
1257 29..33 'self': &Self
1258 71..82 '{ loop {} }': !
1261 94..129 '{ ...o(); }': ()
1262 104..105 'a': impl Trait<u64>
1263 108..111 'bar': fn bar() -> impl Trait<u64>
1264 108..113 'bar()': impl Trait<u64>
1265 119..120 'a': impl Trait<u64>
1266 119..126 'a.foo()': u64
1272 fn more_return_pos_impl_trait() {
1278 fn next(&mut self) -> Self::Item;
1283 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1284 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1290 let (c, d) = baz(1u128);
1295 49..53 'self': &mut Self
1296 101..105 'self': &Self
1297 184..195 '{ loop {} }': ({unknown}, {unknown})
1298 186..193 'loop {}': !
1301 268..279 '{ loop {} }': ({unknown}, {unknown})
1302 270..277 'loop {}': !
1304 291..413 '{ ...o(); }': ()
1305 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1306 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1307 305..306 'b': impl Trait<u64>
1308 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1309 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1310 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1311 321..329 'a.next()': impl Trait<u32>
1312 321..335 'a.next().foo()': u32
1313 341..342 'b': impl Trait<u64>
1314 341..348 'b.foo()': u64
1315 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1316 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1317 362..363 'd': impl Trait<u128>
1318 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1319 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1320 371..376 '1u128': u128
1321 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1322 383..391 'c.next()': impl Trait<u128>
1323 383..397 'c.next().foo()': u128
1324 403..404 'd': impl Trait<u128>
1325 403..410 'd.foo()': u128
1331 fn infer_from_return_pos_impl_trait() {
1332 check_infer_with_mismatches(
1334 //- minicore: fn, sized
1337 impl<T> Trait<T> for Bar<T> {}
1338 fn foo<const C: u8, T>() -> (impl FnOnce(&str, T), impl Trait<u8>) {
1339 (|input, t| {}, Bar(C))
1343 134..165 '{ ...(C)) }': (|&str, T| -> (), Bar<u8>)
1344 140..163 '(|inpu...ar(C))': (|&str, T| -> (), Bar<u8>)
1345 141..154 '|input, t| {}': |&str, T| -> ()
1346 142..147 'input': &str
1349 156..159 'Bar': Bar<u8>(u8) -> Bar<u8>
1350 156..162 'Bar(C)': Bar<u8>
1363 fn foo2(&self) -> i64;
1365 fn bar() -> dyn Trait<u64> {}
1367 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1379 29..33 'self': &Self
1380 54..58 'self': &Self
1381 97..99 '{}': dyn Trait<u64>
1382 109..110 'x': dyn Trait<u64>
1383 128..129 'y': &dyn Trait<u64>
1384 148..265 '{ ...2(); }': ()
1385 154..155 'x': dyn Trait<u64>
1386 161..162 'y': &dyn Trait<u64>
1387 172..173 'z': dyn Trait<u64>
1388 176..179 'bar': fn bar() -> dyn Trait<u64>
1389 176..181 'bar()': dyn Trait<u64>
1390 187..188 'x': dyn Trait<u64>
1391 187..194 'x.foo()': u64
1392 200..201 'y': &dyn Trait<u64>
1393 200..207 'y.foo()': u64
1394 213..214 'z': dyn Trait<u64>
1395 213..220 'z.foo()': u64
1396 226..227 'x': dyn Trait<u64>
1397 226..234 'x.foo2()': i64
1398 240..241 'y': &dyn Trait<u64>
1399 240..248 'y.foo2()': i64
1400 254..255 'z': dyn Trait<u64>
1401 254..262 'z.foo2()': i64
1407 fn dyn_trait_in_impl() {
1412 fn foo(&self) -> (T, U);
1415 impl<T, U> S<T, U> {
1416 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1418 trait Trait2<T, U> {
1419 fn baz(&self) -> (T, U);
1421 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1423 fn test(s: S<u32, i32>) {
1427 32..36 'self': &Self
1428 102..106 'self': &S<T, U>
1429 128..139 '{ loop {} }': &dyn Trait<T, U>
1430 130..137 'loop {}': !
1432 175..179 'self': &Self
1433 251..252 's': S<u32, i32>
1434 267..289 '{ ...z(); }': ()
1435 273..274 's': S<u32, i32>
1436 273..280 's.bar()': &dyn Trait<u32, i32>
1437 273..286 's.bar().baz()': (u32, i32)
1443 fn dyn_trait_bare() {
1448 fn foo(&self) -> u64;
1450 fn bar() -> Trait {}
1452 fn test(x: Trait, y: &Trait) -> u64 {
1461 26..30 'self': &Self
1462 60..62 '{}': dyn Trait
1463 72..73 'x': dyn Trait
1464 82..83 'y': &dyn Trait
1465 100..175 '{ ...o(); }': u64
1466 106..107 'x': dyn Trait
1467 113..114 'y': &dyn Trait
1468 124..125 'z': dyn Trait
1469 128..131 'bar': fn bar() -> dyn Trait
1470 128..133 'bar()': dyn Trait
1471 139..140 'x': dyn Trait
1472 139..146 'x.foo()': u64
1473 152..153 'y': &dyn Trait
1474 152..159 'y.foo()': u64
1475 165..166 'z': dyn Trait
1476 165..172 'z.foo()': u64
1488 a: impl Trait + 'lifetime,
1491 d: impl ('lifetime),
1493 f: impl Trait + ?Sized
1497 28..29 'a': impl Trait
1498 59..60 'b': impl Sized
1499 82..83 'c': impl Trait
1500 103..104 'd': impl Sized
1501 128..129 'e': impl ?Sized
1502 148..149 'f': impl Trait + ?Sized
1509 fn error_bound_chalk() {
1513 fn foo(&self) -> u32 { 0 }
1516 fn test(x: (impl Trait + UnknownTrait)) {
1524 fn assoc_type_bindings() {
1532 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1533 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1534 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1537 impl<T> Trait for S<T> { type Type = T; }
1539 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1550 77..79 '{}': Trait::Type<T>
1557 262..263 'y': impl Trait<Type = i64>
1558 289..397 '{ ...r>); }': ()
1559 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1560 295..301 'get(x)': u32
1562 307..311 'get2': fn get2<u32, T>(T) -> u32
1563 307..314 'get2(x)': u32
1565 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1566 320..326 'get(y)': i64
1567 324..325 'y': impl Trait<Type = i64>
1568 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1569 332..339 'get2(y)': i64
1570 337..338 'y': impl Trait<Type = i64>
1571 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1572 345..356 'get(set(S))': u64
1573 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1574 349..355 'set(S)': S<u64>
1575 353..354 'S': S<u64>
1576 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1577 362..374 'get2(set(S))': u64
1578 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1579 367..373 'set(S)': S<u64>
1580 371..372 'S': S<u64>
1581 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1582 380..394 'get2(S::<str>)': str
1583 385..393 'S::<str>': S<str>
1589 fn impl_trait_assoc_binding_projection_bug() {
1592 //- minicore: iterator
1593 pub trait Language {
1596 pub enum RustLanguage {}
1597 impl Language for RustLanguage {
1598 type Kind = SyntaxKind;
1600 struct SyntaxNode<L> {}
1601 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1604 fn clone(&self) -> Self;
1607 fn api_walkthrough() {
1610 } //^^^^^^^^^^^^ {unknown}
1617 fn projection_eq_within_chalk() {
1626 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1628 fn test<T: Trait1<Type = u32>>(x: T) {
1634 169..185 '{ ...o(); }': ()
1636 175..182 'x.foo()': u32
1642 fn where_clause_trait_in_scope_for_method_resolution() {
1647 fn foo(&self) -> u32 { 0 }
1651 fn test<T: foo::Trait>(x: T) {
1659 fn super_trait_method_resolution() {
1664 fn foo(&self) -> u32 {}
1667 trait Trait1: foo::SuperTrait {}
1668 trait Trait2 where Self: foo::SuperTrait {}
1670 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1675 49..53 'self': &Self
1679 193..222 '{ ...o(); }': ()
1681 199..206 'x.foo()': u32
1683 212..219 'y.foo()': u32
1689 fn super_trait_impl_trait_method_resolution() {
1695 fn foo(&self) -> u32 {}
1698 trait Trait1: foo::SuperTrait {}
1700 fn test(x: &impl Trait1) {
1704 49..53 'self': &Self
1706 115..116 'x': &impl Trait1
1707 132..148 '{ ...o(); }': ()
1708 138..139 'x': &impl Trait1
1709 138..145 'x.foo()': u32
1715 fn super_trait_cycle() {
1716 // This just needs to not crash
1722 fn test<T: A>(x: T) {
1728 49..65 '{ ...o(); }': ()
1730 55..62 'x.foo()': {unknown}
1736 fn super_trait_assoc_type_bounds() {
1739 trait SuperTrait { type Type; }
1740 trait Trait where Self: SuperTrait {}
1742 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1743 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1746 impl<T> SuperTrait for S<T> { type Type = T; }
1747 impl<T> Trait for S<T> {}
1758 258..279 '{ ...S)); }': ()
1759 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1760 264..276 'get2(set(S))': u64
1761 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1762 269..275 'set(S)': S<u64>
1763 273..274 'S': S<u64>
1770 check_infer_with_mismatches(
1772 trait FnOnce<Args> {
1775 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1778 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1779 f.call_once((1, 2));
1785 155..183 '{ ...2)); }': ()
1787 161..180 'f.call...1, 2))': u128
1788 173..179 '(1, 2)': (u32, u64)
1796 fn fn_ptr_and_item() {
1797 check_infer_with_mismatches(
1800 trait FnOnce<Args> {
1803 fn call_once(self, args: Args) -> Self::Output;
1812 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1813 fn foo(&self) -> (A1, R) { loop {} }
1816 enum Opt<T> { None, Some(T) }
1818 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1822 let bar: Bar<fn(u8) -> u32>;
1826 let f: fn(u8) -> u32;
1832 139..143 'self': &Self
1833 243..247 'self': &Bar<F>
1834 260..271 '{ loop {} }': (A1, R)
1835 262..269 'loop {}': !
1837 355..359 'self': Opt<T>
1839 377..388 '{ loop {} }': Opt<U>
1840 379..386 'loop {}': !
1842 402..518 '{ ...(f); }': ()
1843 412..415 'bar': Bar<fn(u8) -> u32>
1844 441..444 'bar': Bar<fn(u8) -> u32>
1845 441..450 'bar.foo()': (u8, u32)
1846 461..464 'opt': Opt<u8>
1847 483..484 'f': fn(u8) -> u32
1848 505..508 'opt': Opt<u8>
1849 505..515 'opt.map(f)': Opt<u32>
1850 513..514 'f': fn(u8) -> u32
1856 fn fn_trait_deref_with_ty_default() {
1859 //- minicore: deref, fn
1863 fn foo(&self) -> usize {}
1866 struct Lazy<T, F = fn() -> T>(F);
1868 impl<T, F> Lazy<T, F> {
1869 pub fn new(f: F) -> Lazy<T, F> {}
1872 impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> {
1877 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1878 let r1 = lazy1.foo();
1880 fn make_foo_fn() -> Foo {}
1881 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1882 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1883 let r2 = lazy2.foo();
1889 151..153 '{}': Lazy<T, F>
1890 251..497 '{ ...o(); }': ()
1891 261..266 'lazy1': Lazy<Foo, || -> Foo>
1892 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1893 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1894 293..299 '|| Foo': || -> Foo
1896 310..312 'r1': usize
1897 315..320 'lazy1': Lazy<Foo, || -> Foo>
1898 315..326 'lazy1.foo()': usize
1899 368..383 'make_foo_fn_ptr': fn() -> Foo
1900 399..410 'make_foo_fn': fn make_foo_fn() -> Foo
1901 420..425 'lazy2': Lazy<Foo, fn() -> Foo>
1902 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1903 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1904 452..467 'make_foo_fn_ptr': fn() -> Foo
1905 478..480 'r2': usize
1906 483..488 'lazy2': Lazy<Foo, fn() -> Foo>
1907 483..494 'lazy2.foo()': usize
1915 check_infer_with_mismatches(
1918 enum Option<T> { Some(T), None }
1920 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1924 let x = Option::Some(1u32);
1927 let y: Option<i64> = x.map(|_v| 1);
1930 86..90 'self': Option<T>
1932 111..122 '{ loop {} }': Option<U>
1933 113..120 'loop {}': !
1935 136..255 '{ ... 1); }': ()
1936 146..147 'x': Option<u32>
1937 150..162 'Option::Some': Some<u32>(u32) -> Option<u32>
1938 150..168 'Option...(1u32)': Option<u32>
1939 163..167 '1u32': u32
1940 174..175 'x': Option<u32>
1941 174..190 'x.map(...v + 1)': Option<u32>
1942 180..189 '|v| v + 1': |u32| -> u32
1945 184..189 'v + 1': u32
1947 196..197 'x': Option<u32>
1948 196..212 'x.map(... 1u64)': Option<u64>
1949 202..211 '|_v| 1u64': |u32| -> u64
1951 207..211 '1u64': u64
1952 222..223 'y': Option<i64>
1953 239..240 'x': Option<u32>
1954 239..252 'x.map(|_v| 1)': Option<i64>
1955 245..251 '|_v| 1': |u32| -> i64
1966 //- minicore: add, fn
1968 impl core::ops::Add for u64 {
1970 fn add(self, rhs: u64) -> Self::Output {0}
1973 impl core::ops::Add for u128 {
1975 fn add(self, rhs: u128) -> Self::Output {0}
1978 fn test<F: FnOnce(u32) -> u64>(f: F) {
1984 //^^^^^^^^^ |u64| -> u64
1987 let h = |v| 1u128 + v;
1988 //^^^^^^^^^^^^^ |u128| -> u128
1994 fn closure_as_argument_inference_order() {
1995 check_infer_with_mismatches(
1998 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
1999 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
2003 fn method(self) -> u64;
2005 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
2006 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
2010 let x1 = foo1(S, |s| s.method());
2011 let x2 = foo2(|s| s.method(), S);
2012 let x3 = S.foo1(S, |s| s.method());
2013 let x4 = S.foo2(|s| s.method(), S);
2018 50..61 '{ loop {} }': U
2023 112..123 '{ loop {} }': U
2024 114..121 'loop {}': !
2030 233..244 '{ loop {} }': U
2031 235..242 'loop {}': !
2036 305..316 '{ loop {} }': U
2037 307..314 'loop {}': !
2039 330..489 '{ ... S); }': ()
2041 345..349 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2042 345..368 'foo1(S...hod())': u64
2044 353..367 '|s| s.method()': |S| -> u64
2047 357..367 's.method()': u64
2049 383..387 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2050 383..406 'foo2(|...(), S)': u64
2051 388..402 '|s| s.method()': |S| -> u64
2054 392..402 's.method()': u64
2058 421..446 'S.foo1...hod())': u64
2060 431..445 '|s| s.method()': |S| -> u64
2063 435..445 's.method()': u64
2066 461..486 'S.foo2...(), S)': u64
2067 468..482 '|s| s.method()': |S| -> u64
2070 472..482 's.method()': u64
2077 fn fn_item_fn_trait() {
2085 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2089 } //^^^^^^^^^^^^^^^^^^ S
2095 fn unselected_projection_in_trait_env_1() {
2104 fn foo(&self) -> u32;
2107 fn test<T: Trait>() where T::Item: Trait2 {
2108 let x: T::Item = no_matter;
2116 fn unselected_projection_in_trait_env_2() {
2124 fn foo(&self) -> u32;
2127 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2128 let x: T::Item = no_matter;
2136 fn unselected_projection_on_impl_self() {
2143 fn f(&self, x: Self::Item);
2150 fn f(&self, x: Self::Item) { let y = x; }
2157 fn f(&self, x: <Self>::Item) { let y = x; }
2160 40..44 'self': &Self
2161 46..47 'x': Trait::Item<Self>
2164 147..161 '{ let y = x; }': ()
2167 228..232 'self': &S2
2169 251..265 '{ let y = x; }': ()
2177 fn unselected_projection_on_trait_self() {
2183 fn f(&self) -> Self::Item { loop {} }
2199 fn unselected_projection_chalk_fold() {
2203 trait Fold<I: Interner, TI = I> {
2207 struct Ty<I: Interner> {}
2208 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2209 type Result = Ty<TI>;
2212 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2219 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2221 } //^^^^^^^^^^^^^^^^^ Ty<I>
2227 fn trait_impl_self_ty() {
2236 impl Trait<Self> for S {}
2246 fn trait_impl_self_ty_cycle() {
2255 impl Trait for S<Self> {}
2259 } //^^^^^^^ {unknown}
2265 fn unselected_projection_in_trait_env_cycle_1() {
2266 // This is not a cycle, because the `T: Trait2<T::Item>` bound depends only on the `T: Trait`
2267 // bound, not on itself (since only `Trait` can define `Item`).
2276 fn test<T: Trait>() where T: Trait2<T::Item> {
2277 let x: T::Item = no_matter;
2278 } //^^^^^^^^^ Trait::Item<T>
2284 fn unselected_projection_in_trait_env_cycle_2() {
2285 // this is a legitimate cycle
2293 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2294 let x: T::Item = no_matter;
2295 } //^^^^^^^^^ {unknown}
2301 fn unselected_projection_in_trait_env_cycle_3() {
2302 // this is a cycle for rustc; we currently accept it
2311 fn test<T>() where T: Trait<OtherItem = T::Item> {
2312 let x: T::Item = no_matter;
2313 } //^^^^^^^^^ Trait::Item<T>
2319 fn unselected_projection_in_trait_env_no_cycle() {
2320 // this is not a cycle
2328 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2330 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2333 fn len(&self) -> usize;
2336 pub trait UnificationStoreMut: UnificationStoreBase {
2337 fn push(&mut self, value: Self::Key);
2340 fn test<T>(t: T) where T: UnificationStoreMut {
2345 } //^^^^^^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2351 fn inline_assoc_type_bounds_1() {
2357 trait OtherTrait<T> {
2361 // workaround for Chalk assoc type normalization problems
2363 impl<T: Iterator> Iterator for S<T> {
2364 type Item = <T as Iterator>::Item;
2367 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2368 let x: <S<I> as Iterator>::Item;
2376 fn inline_assoc_type_bounds_2() {
2383 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2384 let x: <<I as Iterator>::Item as Iterator>::Item;
2392 fn proc_macro_server_types() {
2395 macro_rules! with_api {
2396 ($S:ident, $self:ident, $m:ident) => {
2399 fn new() -> $S::TokenStream;
2406 macro_rules! associated_item {
2407 (type TokenStream) =>
2408 (type TokenStream: 'static;);
2410 (type Group: 'static;);
2411 ($($item:tt)*) => ($($item)*;)
2413 macro_rules! declare_server_traits {
2415 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2418 $(associated_item!(type $name);)*
2421 $(pub trait $name: Types {
2422 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2425 pub trait Server: Types $(+ $name)* {}
2426 impl<S: Types $(+ $name)*> Server for S {}
2430 with_api!(Self, self_, declare_server_traits);
2433 struct RustAnalyzer;
2434 impl Types for RustAnalyzer {
2435 type TokenStream = T;
2439 fn make<T>() -> T { loop {} }
2440 impl TokenStream for RustAnalyzer {
2441 fn new() -> Self::TokenStream {
2442 let group: Self::Group = make();
2447 1075..1086 '{ loop {} }': T
2448 1077..1084 'loop {}': !
2450 1157..1220 '{ ... }': T
2451 1171..1176 'group': G
2452 1192..1196 'make': fn make<G>() -> G
2453 1192..1198 'make()': G
2454 1208..1212 'make': fn make<T>() -> T
2455 1208..1214 'make()': T
2461 fn unify_impl_trait() {
2462 check_infer_with_mismatches(
2467 fn foo(x: impl Trait<u32>) { loop {} }
2468 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2471 impl<T> Trait<T> for S<T> {}
2473 fn default<T>() -> T { loop {} }
2475 fn test() -> impl Trait<i32> {
2476 let s1 = S(default());
2478 let x: i32 = bar(S(default()));
2482 26..27 'x': impl Trait<u32>
2483 46..57 '{ loop {} }': ()
2486 68..69 'x': impl Trait<T>
2487 91..102 '{ loop {} }': T
2488 93..100 'loop {}': !
2490 171..182 '{ loop {} }': T
2491 173..180 'loop {}': !
2493 213..309 '{ ...t()) }': S<i32>
2494 223..225 's1': S<u32>
2495 228..229 'S': S<u32>(u32) -> S<u32>
2496 228..240 'S(default())': S<u32>
2497 230..237 'default': fn default<u32>() -> u32
2498 230..239 'default()': u32
2499 246..249 'foo': fn foo(S<u32>)
2500 246..253 'foo(s1)': ()
2501 250..252 's1': S<u32>
2503 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2504 272..289 'bar(S(...lt()))': i32
2505 276..277 'S': S<i32>(i32) -> S<i32>
2506 276..288 'S(default())': S<i32>
2507 278..285 'default': fn default<i32>() -> i32
2508 278..287 'default()': i32
2509 295..296 'S': S<i32>(i32) -> S<i32>
2510 295..307 'S(default())': S<i32>
2511 297..304 'default': fn default<i32>() -> i32
2512 297..306 'default()': i32
2518 fn assoc_types_from_bounds() {
2537 f::<(), _>(|z| { z; });
2542 132..163 '{ ... }); }': ()
2543 138..148 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2544 138..160 'f::<()... z; })': ()
2545 149..159 '|z| { z; }': |&()| -> ()
2547 153..159 '{ z; }': ()
2554 fn associated_type_bound() {
2558 type Item: OtherTrait<u32>;
2560 pub trait OtherTrait<T> {
2564 // this is just a workaround for chalk#234
2566 impl<T: Trait> Trait for S<T> {
2567 type Item = <T as Trait>::Item;
2570 fn test<T: Trait>() {
2571 let y: <S<T> as Trait>::Item = no_matter;
2579 fn dyn_trait_through_chalk() {
2583 struct Box<T: ?Sized> {}
2584 impl<T: ?Sized> core::ops::Deref for Box<T> {
2591 fn test(x: Box<dyn Trait>) {
2599 fn string_to_owned() {
2605 fn to_owned(&self) -> Self::Owned;
2607 impl ToOwned for str {
2608 type Owned = String;
2612 } //^^^^^^^^^^^^^^^^ String
2618 fn iterator_chain() {
2619 check_infer_with_mismatches(
2621 //- minicore: fn, option
2622 pub trait Iterator {
2625 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2627 F: FnMut(Self::Item) -> Option<B>,
2630 fn for_each<F>(self, f: F)
2632 F: FnMut(Self::Item),
2636 pub trait IntoIterator {
2638 type IntoIter: Iterator<Item = Self::Item>;
2639 fn into_iter(self) -> Self::IntoIter;
2642 pub struct FilterMap<I, F> { }
2643 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2645 F: FnMut(I::Item) -> Option<B>,
2650 #[stable(feature = "rust1", since = "1.0.0")]
2651 impl<I: Iterator> IntoIterator for I {
2652 type Item = I::Item;
2655 fn into_iter(self) -> I {
2662 fn new() -> Self { loop {} }
2665 impl<T> IntoIterator for Vec<T> {
2667 type IntoIter = IntoIter<T>;
2670 pub struct IntoIter<T> { }
2671 impl<T> Iterator for IntoIter<T> {
2676 Vec::<i32>::new().into_iter()
2677 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2678 .for_each(|y| { y; });
2683 152..163 '{ loop {} }': FilterMap<Self, F>
2684 154..161 'loop {}': !
2686 184..188 'self': Self
2688 240..251 '{ loop {} }': ()
2689 242..249 'loop {}': !
2691 360..364 'self': Self
2693 700..720 '{ ... }': I
2695 779..790 '{ loop {} }': Vec<T>
2696 781..788 'loop {}': !
2698 977..1104 '{ ... }); }': ()
2699 983..998 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2700 983..1000 'Vec::<...:new()': Vec<i32>
2701 983..1012 'Vec::<...iter()': IntoIter<i32>
2702 983..1075 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2703 983..1101 'Vec::<... y; })': ()
2704 1029..1074 '|x| if...None }': |i32| -> Option<u32>
2706 1033..1074 'if x >...None }': Option<u32>
2708 1036..1041 'x > 0': bool
2710 1042..1060 '{ Some...u32) }': Option<u32>
2711 1044..1048 'Some': Some<u32>(u32) -> Option<u32>
2712 1044..1058 'Some(x as u32)': Option<u32>
2714 1049..1057 'x as u32': u32
2715 1066..1074 '{ None }': Option<u32>
2716 1068..1072 'None': Option<u32>
2717 1090..1100 '|y| { y; }': |u32| -> ()
2719 1094..1100 '{ y; }': ()
2742 fn foo() -> Self::Output;
2746 type Output = T::OutputA;
2747 fn foo() -> Self::Output { loop {} }
2758 fn trait_object_no_coercion() {
2759 check_infer_with_mismatches(
2763 fn foo(x: &dyn Foo) {}
2765 fn test(x: &dyn Foo) {
2769 21..22 'x': &dyn Foo
2771 46..47 'x': &dyn Foo
2772 59..74 '{ foo(x); }': ()
2773 65..68 'foo': fn foo(&dyn Foo)
2775 69..70 'x': &dyn Foo
2782 check_infer_with_mismatches(
2786 impl Copy for IsCopy {}
2789 trait Test { fn test(&self) -> bool; }
2790 impl<T: Copy> Test for T {}
2795 (IsCopy, IsCopy).test();
2796 (IsCopy, NotCopy).test();
2799 78..82 'self': &Self
2800 134..235 '{ ...t(); }': ()
2801 140..146 'IsCopy': IsCopy
2802 140..153 'IsCopy.test()': bool
2803 159..166 'NotCopy': NotCopy
2804 159..173 'NotCopy.test()': {unknown}
2805 179..195 '(IsCop...sCopy)': (IsCopy, IsCopy)
2806 179..202 '(IsCop...test()': bool
2807 180..186 'IsCopy': IsCopy
2808 188..194 'IsCopy': IsCopy
2809 208..225 '(IsCop...tCopy)': (IsCopy, NotCopy)
2810 208..232 '(IsCop...test()': {unknown}
2811 209..215 'IsCopy': IsCopy
2812 217..224 'NotCopy': NotCopy
2818 fn builtin_fn_def_copy() {
2819 check_infer_with_mismatches(
2823 fn bar<T: Copy>(T) -> T {}
2824 struct Struct(usize);
2825 enum Enum { Variant(usize) }
2827 trait Test { fn test(&self) -> bool; }
2828 impl<T: Copy> Test for T {}
2834 Enum::Variant.test();
2838 28..29 'T': {unknown}
2840 36..38: expected T, got ()
2841 113..117 'self': &Self
2842 169..249 '{ ...t(); }': ()
2843 175..178 'foo': fn foo()
2844 175..185 'foo.test()': bool
2845 191..194 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2846 191..201 'bar.test()': bool
2847 207..213 'Struct': Struct(usize) -> Struct
2848 207..220 'Struct.test()': bool
2849 226..239 'Enum::Variant': Variant(usize) -> Enum
2850 226..246 'Enum::...test()': bool
2856 fn builtin_fn_ptr_copy() {
2857 check_infer_with_mismatches(
2860 trait Test { fn test(&self) -> bool; }
2861 impl<T: Copy> Test for T {}
2863 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2869 22..26 'self': &Self
2871 86..88 'f2': fn(usize) -> u8
2872 107..109 'f3': fn(u8, u8) -> &u8
2873 130..178 '{ ...t(); }': ()
2875 136..145 'f1.test()': bool
2876 151..153 'f2': fn(usize) -> u8
2877 151..160 'f2.test()': bool
2878 166..168 'f3': fn(u8, u8) -> &u8
2879 166..175 'f3.test()': bool
2885 fn builtin_sized() {
2886 check_infer_with_mismatches(
2889 trait Test { fn test(&self) -> bool; }
2890 impl<T: Sized> Test for T {}
2894 (*"foo").test(); // not Sized
2896 (1u8, *"foo").test(); // not Sized
2899 22..26 'self': &Self
2900 79..194 '{ ...ized }': ()
2902 85..95 '1u8.test()': bool
2903 101..116 '(*"foo").test()': {unknown}
2904 102..108 '*"foo"': str
2905 103..108 '"foo"': &str
2906 135..145 '(1u8, 1u8)': (u8, u8)
2907 135..152 '(1u8, ...test()': bool
2910 158..171 '(1u8, *"foo")': (u8, str)
2911 158..178 '(1u8, ...test()': {unknown}
2913 164..170 '*"foo"': str
2914 165..170 '"foo"': &str
2920 fn integer_range_iterate() {
2923 //- /main.rs crate:main deps:core
2925 for x in 0..100 { x; }
2928 //- /core.rs crate:core
2930 pub struct Range<Idx> {
2937 pub trait Iterator {
2941 pub trait IntoIterator {
2943 type IntoIter: Iterator<Item = Self::Item>;
2946 impl<T> IntoIterator for T where T: Iterator {
2947 type Item = <T as Iterator>::Item;
2948 type IntoIter = Self;
2953 impl Step for i32 {}
2954 impl Step for i64 {}
2956 impl<A: Step> iter::Iterator for ops::Range<A> {
2964 fn infer_closure_arg() {
2975 let s = Option::None;
2976 let f = |x: Option<i32>| {};
2980 52..126 '{ ...)(s) }': ()
2981 62..63 's': Option<i32>
2982 66..78 'Option::None': Option<i32>
2983 88..89 'f': |Option<i32>| -> ()
2984 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
2985 93..94 'x': Option<i32>
2987 117..124 '(&f)(s)': ()
2988 118..120 '&f': &|Option<i32>| -> ()
2989 119..120 'f': |Option<i32>| -> ()
2990 122..123 's': Option<i32>
2996 fn dyn_fn_param_informs_call_site_closure_signature() {
2997 cov_mark::check!(dyn_fn_param_informs_call_site_closure_signature);
3000 //- minicore: fn, coerce_unsized
3003 fn inherent(&self) -> u8 { 0 }
3005 fn take_dyn_fn(f: &dyn Fn(S)) {}
3008 take_dyn_fn(&|x| { x.inherent(); });
3016 fn infer_fn_trait_arg() {
3017 check_infer_with_mismatches(
3019 //- minicore: fn, option
3020 fn foo<F, T>(f: F) -> T
3022 F: Fn(Option<i32>) -> T,
3030 59..89 '{ ...f(s) }': T
3031 69..70 's': Option<i32>
3032 73..77 'None': Option<i32>
3035 85..86 's': Option<i32>
3041 fn infer_box_fn_arg() {
3042 // The type mismatch is because we don't define Unsize and CoerceUnsized
3043 check_infer_with_mismatches(
3045 //- minicore: fn, deref, option
3046 #[lang = "owned_box"]
3047 pub struct Box<T: ?Sized> {
3051 impl<T: ?Sized> core::ops::Deref for Box<T> {
3054 fn deref(&self) -> &T {
3061 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3065 154..158 'self': &Box<T>
3066 166..193 '{ ... }': &T
3067 176..187 '&self.inner': &*mut T
3068 177..181 'self': &Box<T>
3069 177..187 'self.inner': *mut T
3070 206..296 '{ ...&s); }': ()
3071 216..217 's': Option<i32>
3072 220..224 'None': Option<i32>
3073 234..235 'f': Box<dyn FnOnce(&Option<i32>)>
3074 269..282 'box (|ps| {})': Box<|&Option<i32>| -> ()>
3075 274..281 '|ps| {}': |&Option<i32>| -> ()
3076 275..277 'ps': &Option<i32>
3078 288..289 'f': Box<dyn FnOnce(&Option<i32>)>
3079 288..293 'f(&s)': ()
3080 290..292 '&s': &Option<i32>
3081 291..292 's': Option<i32>
3082 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|&Option<i32>| -> ()>
3088 fn infer_dyn_fn_output() {
3093 let f: &dyn Fn() -> i32;
3101 fn infer_dyn_fn_once_output() {
3106 let f: dyn FnOnce() -> i32;
3114 fn variable_kinds_1() {
3117 trait Trait<T> { fn get(self, t: T) -> T; }
3119 impl Trait<u128> for S {}
3120 impl Trait<f32> for S {}
3132 fn variable_kinds_2() {
3135 trait Trait { fn get(self) -> Self; }
3136 impl Trait for u128 {}
3137 impl Trait for f32 {}
3149 fn underscore_import() {
3154 fn method(&self) -> u8 { 0 }
3159 impl crate::tr::Tr for Tr {}
3161 use crate::tr::Tr as _;
3176 fn method(&self) -> u8 { 0 }
3193 fn trait_in_scope_with_inner_item() {
3198 fn method(&self) -> u8 { 0 }
3213 46..50 'self': &Self
3216 115..185 '{ ... } }': ()
3217 132..183 '{ ... }': ()
3219 142..153 '().method()': u8
3225 fn inner_use_in_block() {
3230 fn method(&self) -> u8 { 0 }
3246 //^^^^^^^^^^^ {unknown}
3250 //^^^^^^^^^^^ {unknown}
3257 fn nested_inner_function_calling_self() {
3267 17..73 '{ ... } }': ()
3270 57..62 'inner': fn inner() -> S
3277 fn infer_default_trait_type_parameter() {
3282 trait Op<RHS=Self> {
3285 fn do_op(self, rhs: RHS) -> Self::Output;
3291 fn do_op(self, rhs: Self) -> Self::Output {
3306 186..206 '{ ... }': bool
3307 196..200 'true': bool
3308 220..277 '{ ...(y); }': ()
3315 264..274 'x.do_op(y)': bool
3322 fn qualified_path_as_qualified_trait() {
3332 fn boo() -> Self::Output {
3339 impl foo::Foo for F {
3342 impl foo::Bar for F {
3343 type Output = <F as foo::Foo>::Target;
3348 let x = <F as Bar>::boo();
3351 132..163 '{ ... }': Bar::Output<Self>
3352 146..153 'loop {}': !
3354 306..358 '{ ...o(); }': ()
3356 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3357 338..355 '<F as ...:boo()': ()
3363 fn renamed_extern_crate_in_block() {
3366 //- /lib.rs crate:lib deps:serde
3367 use serde::Deserialize;
3372 extern crate serde as _serde;
3373 impl _serde::Deserialize for Foo {
3374 fn deserialize() -> u8 { 0 }
3380 //^^^^^^^^^^^^^^^^^^ u8
3383 //- /serde.rs crate:serde
3385 pub trait Deserialize {
3386 fn deserialize() -> u8;
3392 fn bin_op_with_rhs_is_self_for_assoc_bound() {
3393 check_no_mismatches(
3395 fn repro<T>(t: T) -> bool
3398 T::Output: Convertable,
3400 let a = execute(&t).convert();
3401 let b = execute(&t).convert();
3403 let a = execute(&t).convert2();
3404 let b = execute(&t).convert2();
3407 fn execute<T>(t: &T) -> T::Output
3411 <T as Request>::output()
3414 type TraitSelf: PartialEq<Self::TraitSelf>;
3415 type AssocAsDefaultSelf: PartialEq;
3416 fn convert(self) -> Self::AssocAsDefaultSelf;
3417 fn convert2(self) -> Self::TraitSelf;
3421 fn output() -> Self::Output;
3428 fn bin_op_adt_with_rhs_primitive() {
3429 check_infer_with_mismatches(
3432 pub trait Add<Rhs = Self> {
3434 fn add(self, rhs: Rhs) -> Self::Output;
3437 struct Wrapper(u32);
3438 impl Add<u32> for Wrapper {
3440 fn add(self, rhs: u32) -> Wrapper {
3445 let wrapped = Wrapper(10);
3447 let res = wrapped + num;
3453 192..196 'self': Wrapper
3455 219..247 '{ ... }': Wrapper
3456 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3457 229..241 'Wrapper(rhs)': Wrapper
3459 259..345 '{ ...um; }': ()
3460 269..276 'wrapped': Wrapper
3461 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3462 279..290 'Wrapper(10)': Wrapper
3466 322..325 'res': Wrapper
3467 328..335 'wrapped': Wrapper
3468 328..341 'wrapped + num': Wrapper
3480 fn do_thing(&self) -> Self::Output;
3483 impl T for [u8; 4] {
3484 type Output = usize;
3485 fn do_thing(&self) -> Self::Output {
3490 impl T for [u8; 2] {
3492 fn do_thing(&self) -> Self::Output {
3499 let v2 = v.do_thing();
3501 let v4 = v3.do_thing();
3505 44..48 'self': &Self
3506 133..137 'self': &[u8; 4]
3507 155..172 '{ ... }': usize
3509 236..240 'self': &[u8; 2]
3510 258..275 '{ ... }': u8
3512 289..392 '{ ...g(); }': ()
3513 299..300 'v': [u8; 2]
3514 303..311 '[0u8; 2]': [u8; 2]
3518 326..327 'v': [u8; 2]
3519 326..338 'v.do_thing()': u8
3520 348..350 'v3': [u8; 4]
3521 353..361 '[0u8; 4]': [u8; 4]
3524 371..373 'v4': usize
3525 376..378 'v3': [u8; 4]
3526 376..389 'v3.do_thing()': usize
3532 fn const_generics() {
3537 fn do_thing(&self) -> Self::Output;
3540 impl<const L: usize> T for [u8; L] {
3541 type Output = [u8; L];
3542 fn do_thing(&self) -> Self::Output {
3549 let v2 = v.do_thing();
3553 44..48 'self': &Self
3554 151..155 'self': &[u8; L]
3555 173..194 '{ ... }': [u8; L]
3556 183..188 '*self': [u8; L]
3557 184..188 'self': &[u8; L]
3558 208..260 '{ ...g(); }': ()
3559 218..219 'v': [u8; 2]
3560 222..230 '[0u8; 2]': [u8; 2]
3563 240..242 'v2': [u8; 2]
3564 245..246 'v': [u8; 2]
3565 245..257 'v.do_thing()': [u8; 2]
3571 fn fn_returning_unit() {
3572 check_infer_with_mismatches(
3575 fn test<F: FnOnce()>(f: F) {
3580 27..51 '{ ...f(); }': ()
3589 fn trait_in_scope_of_trait_impl() {
3595 fn bar(self) -> usize { 0 }
3598 impl foo::Foo for u32 {
3600 let _x = self.bar();
3607 82..87 '{ 0 }': usize
3609 131..135 'self': u32
3610 137..173 '{ ... }': ()
3611 151..153 '_x': usize
3612 156..160 'self': u32
3613 156..166 'self.bar()': usize
3619 fn infer_async_ret_type() {
3622 //- minicore: future, result
3626 fn collect<B: Convert>(self) -> B {
3634 impl Convert for u32 {
3635 fn new() -> Self { 0 }
3638 async fn get_accounts() -> Result<u32, ()> {
3639 let ret = Fooey.collect();
3640 // ^^^^^^^^^^^^^^^ u32
3649 check!(block_local_impls);
3658 impl Trait<u32> for S {
3659 fn foo(&self) -> u32 { 0 }
3671 check!(block_local_impls);
3680 impl Trait<u32> for S {
3681 fn foo(&self) -> u32 { 0 }
3693 check!(block_local_impls);
3705 impl Trait<S1> for S2 {
3706 fn foo(&self) -> S1 { S1 }
3718 fn associated_type_sized_bounds() {
3723 trait IsSized { const IS_SIZED: Yes; }
3724 impl<T: Sized> IsSized for T { const IS_SIZED: Yes = Yes; }
3727 type Explicit: Sized;
3729 type Relaxed: ?Sized;
3732 F::Explicit::IS_SIZED;
3733 F::Implicit::IS_SIZED;
3734 F::Relaxed::IS_SIZED;
3739 212..295 '{ ...ZED; }': ()
3740 218..239 'F::Exp..._SIZED': Yes
3741 245..266 'F::Imp..._SIZED': Yes
3742 272..292 'F::Rel..._SIZED': {unknown}
3751 pub struct Key<K, V, P = (K, V)> {}
3758 impl<K, V> Policy for (K, V) {
3763 pub struct KeyMap<KEY> {}
3765 impl<P: Policy> KeyMap<Key<P::K, P::V, P>> {
3766 pub fn get(&self, key: &P::K) -> P::V {
3772 struct FunctionId {}
3775 let key_map: &KeyMap<Key<Fn, FunctionId>> = loop {};
3777 let result = key_map.get(key);