1 use expect_test::expect;
3 use super::{check_infer, check_infer_with_mismatches, check_types};
9 //- /main.rs crate:main deps:core
12 impl Future for IntFuture {
22 //- /core.rs crate:core
25 #[lang = "future_trait"]
39 //- /main.rs crate:main deps:core
40 async fn foo() -> u64 {
50 //- /core.rs crate:core
51 #[prelude_import] use future::*;
53 #[lang = "future_trait"]
63 fn infer_desugar_async() {
66 //- /main.rs crate:main deps:core
67 async fn foo() -> u64 {
74 } //^ impl Future<Output = u64>
76 //- /core.rs crate:core
77 #[prelude_import] use future::*;
89 fn infer_async_block() {
92 //- /main.rs crate:main deps:core
96 // ^ impl Future<Output = i32>
100 let b = async {}.await;
104 let y = Option::None;
108 let _: Option<u64> = c.await;
110 // ^ impl Future<Output = Option<u64>>
113 enum Option<T> { None, Some(T) }
115 //- /core.rs crate:core
116 #[prelude_import] use future::*;
118 #[lang = "future_trait"]
132 //- /main.rs crate:main deps:core
134 let r: Result<i32, u64> = Result::Ok(1);
139 //- /core.rs crate:core
148 pub enum Result<O, E> {
153 impl<O, E> crate::ops::Try for Result<O, E> {
161 pub use crate::{result::*, ops::*};
169 fn infer_try_trait_v2() {
172 //- /main.rs crate:main deps:core
174 let r: Result<i32, u64> = Result::Ok(1);
179 //- /core.rs crate:core
182 pub trait Try: FromResidual {
186 pub trait FromResidual<R = <Self as Try>::Residual> {}
189 pub use self::try_trait::FromResidual;
190 pub use self::try_trait::Try;
195 impl<T> From<T> for T {}
199 use crate::convert::From;
200 use crate::ops::{Try, FromResidual};
202 pub enum Infallible {}
203 pub enum Result<O, E> {
208 impl<O, E> Try for Result<O, E> {
210 type Error = Result<Infallible, E>;
213 impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
218 pub use crate::result::*;
226 fn infer_for_loop() {
229 //- /main.rs crate:main deps:core,alloc
231 use alloc::collections::Vec;
241 //- /core.rs crate:core
243 pub trait IntoIterator {
249 pub use crate::iter::*;
253 //- /alloc.rs crate:alloc deps:core
258 pub fn new() -> Self { Vec {} }
259 pub fn push(&mut self, t: T) { }
262 impl<T> IntoIterator for Vec<T> {
274 //- /main.rs crate:main deps:std
278 impl std::ops::Neg for Bar {
288 //- /std.rs crate:std
289 #[prelude_import] use ops::*;
304 //- /main.rs crate:main deps:std
308 impl std::ops::Not for Bar {
318 //- /std.rs crate:std
319 #[prelude_import] use ops::*;
331 fn infer_from_bound_1() {
336 impl<U> Trait<U> for S<U> {}
337 fn foo<T: Trait<u32>>(t: T) {}
345 104..143 '{ ...(s); }': ()
347 118..119 'S': S<u32>(u32) -> S<u32>
348 118..128 'S(unknown)': S<u32>
349 120..127 'unknown': u32
350 134..137 'foo': fn foo<S<u32>>(S<u32>)
351 134..140 'foo(s)': ()
358 fn infer_from_bound_2() {
363 impl<U> Trait<U> for S<U> {}
364 fn foo<U, T: Trait<U>>(t: T) -> U {}
372 110..162 '{ ...(s); }': ()
374 124..125 'S': S<u32>(u32) -> S<u32>
375 124..134 'S(unknown)': S<u32>
376 126..133 'unknown': u32
378 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32
379 153..159 'foo(s)': u32
386 fn trait_default_method_self_bound_implements_trait() {
387 cov_mark::check!(trait_self_implements_self);
391 fn foo(&self) -> i64;
402 79..89 'self.foo()': i64
408 fn trait_default_method_self_bound_implements_super_trait() {
412 fn foo(&self) -> i64;
414 trait Trait: SuperTrait {
422 94..129 '{ ... }': ()
424 112..116 'self': &Self
425 112..122 'self.foo()': i64
431 fn infer_project_associated_type() {
438 impl Iterable for S { type Item = u32; }
439 fn test<T: Iterable>() {
440 let x: <S as Iterable>::Item = 1;
441 let y: <T as Iterable>::Item = no_matter;
442 let z: T::Item = no_matter;
443 let a: <T>::Item = no_matter;
446 108..261 '{ ...ter; }': ()
449 156..157 'y': Iterable::Item<T>
450 183..192 'no_matter': Iterable::Item<T>
451 202..203 'z': Iterable::Item<T>
452 215..224 'no_matter': Iterable::Item<T>
453 234..235 'a': Iterable::Item<T>
454 249..258 'no_matter': Iterable::Item<T>
460 fn infer_return_associated_type() {
467 impl Iterable for S { type Item = u32; }
468 fn foo1<T: Iterable>(t: T) -> T::Item {}
469 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {}
470 fn foo3<T: Iterable>(t: T) -> <T>::Item {}
483 234..300 '{ ...(S); }': ()
485 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item
486 248..255 'foo1(S)': u32
489 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item
490 269..276 'foo2(S)': u32
493 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item
494 290..297 'foo3(S)': u32
501 fn infer_associated_type_bound() {
507 fn test<T: Iterable<Item=u32>>() {
508 let y: T::Item = unknown;
511 67..100 '{ ...own; }': ()
513 90..97 'unknown': u32
519 fn infer_const_body() {
522 const A: u32 = 1 + 1;
523 static B: u64 = { let x = 1; x };"#,
528 38..54 '{ let ...1; x }': u64
537 fn tuple_struct_fields() {
547 37..86 '{ ... a.1 }': u64
549 51..52 'S': S(i32, u64) -> S
563 fn tuple_struct_with_fn() {
566 struct S(fn(u32) -> u64);
573 43..101 '{ ...0(2) }': u64
575 57..58 'S': S(fn(u32) -> u64) -> S
576 57..67 'S(|i| 2*i)': S
577 59..66 '|i| 2*i': |u32| -> u64
584 81..84 'a.0': fn(u32) -> u64
588 93..96 'a.0': fn(u32) -> u64
596 fn indexing_arrays() {
598 "fn main() { &mut [9][2]; }",
600 10..26 '{ &mut...[2]; }': ()
601 12..23 '&mut [9][2]': &mut {unknown}
602 17..20 '[9]': [i32; 1]
603 17..23 '[9][2]': {unknown}
611 fn infer_ops_index() {
614 //- /main.rs crate:main deps:std
618 impl std::ops::Index<u32> for Bar {
628 //- /std.rs crate:std
629 #[prelude_import] use ops::*;
632 pub trait Index<Idx> {
641 fn infer_ops_index_int() {
644 //- /main.rs crate:main deps:std
648 impl std::ops::Index<u32> for Bar {
653 impl std::ops::Index<Range> for Bar {
664 //- /std.rs crate:std
665 #[prelude_import] use ops::*;
668 pub trait Index<Idx> {
677 fn infer_ops_index_autoderef() {
680 //- /main.rs crate:main deps:std
682 let a = &[1u32, 2, 3];
687 //- /std.rs crate:std
688 impl<T> ops::Index<u32> for [T] {
692 #[prelude_import] use ops::*;
695 pub trait Index<Idx> {
709 impl<T> core::ops::Deref for Arc<T> {
715 fn foo(&self) -> u128 {}
726 fn deref_trait_with_inference_var() {
731 fn new_arc<T>() -> Arc<T> {}
732 impl<T> core::ops::Deref for Arc<T> {
750 fn deref_trait_infinite_recursion() {
756 impl core::ops::Deref for S {
768 fn deref_trait_with_question_mark_size() {
773 impl<T: ?Sized> core::ops::Deref for Arc<T> {
779 fn foo(&self) -> u128 {}
790 fn obligation_from_function_clause() {
796 impl Trait<u32> for S {}
798 fn foo<T: Trait<U>, U>(t: T) -> U {}
808 fn obligation_from_method_clause() {
815 impl Trait<isize> for S {}
819 fn foo<T: Trait<U>, U>(&self, t: T) -> U {}
830 fn obligation_from_self_method_clause() {
836 impl Trait<i64> for S {}
839 fn foo<U>(&self) -> U where Self: Trait<U> {}
850 fn obligation_from_impl_clause() {
856 impl Trait<&str> for S {}
859 impl<U, T: Trait<U>> O<T> {
860 fn foo(&self) -> U {}
871 fn generic_param_env_1() {
875 trait Trait { fn foo(self) -> u128; }
878 impl<T> Trait for T where T: Clone {}
879 fn test<T: Clone>(t: T) { t.foo(); }
886 fn generic_param_env_1_not_met() {
891 trait Trait { fn foo(self) -> u128; }
894 impl<T> Trait for T where T: Clone {}
895 fn test<T>(t: T) { t.foo(); }
902 fn generic_param_env_2() {
905 trait Trait { fn foo(self) -> u128; }
908 fn test<T: Trait>(t: T) { t.foo(); }
915 fn generic_param_env_2_not_met() {
918 trait Trait { fn foo(self) -> u128; }
921 fn test<T>(t: T) { t.foo(); }
928 fn generic_param_env_deref() {
936 impl<T> Deref for T where T: Trait {
939 fn test<T: Trait>(t: T) { (*t); }
946 fn associated_type_placeholder() {
947 // 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].
954 pub struct RefMutL<T>;
956 impl<T> ApplyL for RefMutL<T> {
957 type Out = <T as ApplyL>::Out;
960 fn test<T: ApplyL>() {
961 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
969 fn associated_type_placeholder_2() {
975 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
977 fn test<T: ApplyL>(t: T) {
986 fn argument_impl_trait() {
987 check_infer_with_mismatches(
991 fn foo2(&self) -> i64;
993 fn bar(x: impl Trait<u16>) {}
995 impl<T> Trait<T> for S<T> {}
997 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
1010 29..33 'self': &Self
1011 54..58 'self': &Self
1012 77..78 'x': impl Trait<u16>
1014 154..155 'x': impl Trait<u64>
1015 174..175 'y': &impl Trait<u32>
1016 195..323 '{ ...2(); }': ()
1017 201..202 'x': impl Trait<u64>
1018 208..209 'y': &impl Trait<u32>
1019 219..220 'z': S<u16>
1020 223..224 'S': S<u16>(u16) -> S<u16>
1021 223..227 'S(1)': S<u16>
1023 233..236 'bar': fn bar(S<u16>)
1024 233..239 'bar(z)': ()
1025 237..238 'z': S<u16>
1026 245..246 'x': impl Trait<u64>
1027 245..252 'x.foo()': u64
1028 258..259 'y': &impl Trait<u32>
1029 258..265 'y.foo()': u32
1030 271..272 'z': S<u16>
1031 271..278 'z.foo()': u16
1032 284..285 'x': impl Trait<u64>
1033 284..292 'x.foo2()': i64
1034 298..299 'y': &impl Trait<u32>
1035 298..306 'y.foo2()': i64
1036 312..313 'z': S<u16>
1037 312..320 'z.foo2()': i64
1043 fn argument_impl_trait_type_args_1() {
1044 check_infer_with_mismatches(
1048 // this function has an implicit Self param, an explicit type param,
1049 // and an implicit impl Trait param!
1050 fn bar<T>(x: impl Trait) -> T { loop {} }
1052 fn foo<T>(x: impl Trait) -> T { loop {} }
1063 <F as Foo>::bar::<u32>(S);
1067 foo::<u32, i32>(S); // we should ignore the extraneous i32
1070 155..156 'x': impl Trait
1071 175..186 '{ loop {} }': T
1072 177..184 'loop {}': !
1074 199..200 'x': impl Trait
1075 219..230 '{ loop {} }': T
1076 221..228 'loop {}': !
1078 300..509 '{ ... i32 }': ()
1079 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1080 306..317 'Foo::bar(S)': {unknown}
1082 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1083 323..341 '<F as ...bar(S)': {unknown}
1085 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1086 347..356 'F::bar(S)': {unknown}
1088 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1089 362..380 'Foo::b...32>(S)': u32
1091 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1092 386..411 '<F as ...32>(S)': u32
1094 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1095 418..424 'foo(S)': {unknown}
1097 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1098 430..443 'foo::<u32>(S)': u32
1100 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1101 449..467 'foo::<...32>(S)': u32
1108 fn argument_impl_trait_type_args_2() {
1109 check_infer_with_mismatches(
1116 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1122 F::<u32>.foo::<i32>(S);
1123 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1127 93..94 'x': impl Trait
1128 118..129 '{ loop {} }': (T, U)
1129 120..127 'loop {}': !
1131 143..283 '{ ...ored }': ()
1132 149..150 'F': F<{unknown}>
1133 149..157 'F.foo(S)': ({unknown}, {unknown})
1135 163..171 'F::<u32>': F<u32>
1136 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1138 184..192 'F::<u32>': F<u32>
1139 184..206 'F::<u3...32>(S)': (u32, i32)
1141 212..220 'F::<u32>': F<u32>
1142 212..239 'F::<u3...32>(S)': (u32, i32)
1149 fn argument_impl_trait_to_fn_pointer() {
1150 check_infer_with_mismatches(
1153 fn foo(x: impl Trait) { loop {} }
1158 let f: fn(S) -> () = foo;
1161 22..23 'x': impl Trait
1162 37..48 '{ loop {} }': ()
1165 90..123 '{ ...foo; }': ()
1167 117..120 'foo': fn foo(S)
1178 fn foo2(&self) -> i64;
1180 fn bar() -> impl Trait<u64> {}
1182 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1194 29..33 'self': &Self
1195 54..58 'self': &Self
1197 110..111 'x': impl Trait<u64>
1198 130..131 'y': &impl Trait<u64>
1199 151..268 '{ ...2(); }': ()
1200 157..158 'x': impl Trait<u64>
1201 164..165 'y': &impl Trait<u64>
1202 175..176 'z': impl Trait<u64>
1203 179..182 'bar': fn bar() -> impl Trait<u64>
1204 179..184 'bar()': impl Trait<u64>
1205 190..191 'x': impl Trait<u64>
1206 190..197 'x.foo()': u64
1207 203..204 'y': &impl Trait<u64>
1208 203..210 'y.foo()': u64
1209 216..217 'z': impl Trait<u64>
1210 216..223 'z.foo()': u64
1211 229..230 'x': impl Trait<u64>
1212 229..237 'x.foo2()': i64
1213 243..244 'y': &impl Trait<u64>
1214 243..251 'y.foo2()': i64
1215 257..258 'z': impl Trait<u64>
1216 257..265 'z.foo2()': i64
1222 fn simple_return_pos_impl_trait() {
1223 cov_mark::check!(lower_rpit);
1229 fn bar() -> impl Trait<u64> { loop {} }
1236 29..33 'self': &Self
1237 71..82 '{ loop {} }': !
1240 94..129 '{ ...o(); }': ()
1241 104..105 'a': impl Trait<u64>
1242 108..111 'bar': fn bar() -> impl Trait<u64>
1243 108..113 'bar()': impl Trait<u64>
1244 119..120 'a': impl Trait<u64>
1245 119..126 'a.foo()': u64
1251 fn more_return_pos_impl_trait() {
1256 fn next(&mut self) -> Self::Item;
1261 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1262 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1268 let (c, d) = baz(1u128);
1273 49..53 'self': &mut Self
1274 101..105 'self': &Self
1275 184..195 '{ loop {} }': ({unknown}, {unknown})
1276 186..193 'loop {}': !
1279 268..279 '{ loop {} }': ({unknown}, {unknown})
1280 270..277 'loop {}': !
1282 291..413 '{ ...o(); }': ()
1283 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1284 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1285 305..306 'b': impl Trait<u64>
1286 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1287 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1288 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1289 321..329 'a.next()': impl Trait<u32>
1290 321..335 'a.next().foo()': u32
1291 341..342 'b': impl Trait<u64>
1292 341..348 'b.foo()': u64
1293 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1294 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1295 362..363 'd': impl Trait<u128>
1296 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1297 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1298 371..376 '1u128': u128
1299 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1300 383..391 'c.next()': impl Trait<u128>
1301 383..397 'c.next().foo()': u128
1302 403..404 'd': impl Trait<u128>
1303 403..410 'd.foo()': u128
1314 fn foo2(&self) -> i64;
1316 fn bar() -> dyn Trait<u64> {}
1318 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1330 29..33 'self': &Self
1331 54..58 'self': &Self
1333 109..110 'x': dyn Trait<u64>
1334 128..129 'y': &dyn Trait<u64>
1335 148..265 '{ ...2(); }': ()
1336 154..155 'x': dyn Trait<u64>
1337 161..162 'y': &dyn Trait<u64>
1338 172..173 'z': dyn Trait<u64>
1339 176..179 'bar': fn bar() -> dyn Trait<u64>
1340 176..181 'bar()': dyn Trait<u64>
1341 187..188 'x': dyn Trait<u64>
1342 187..194 'x.foo()': u64
1343 200..201 'y': &dyn Trait<u64>
1344 200..207 'y.foo()': u64
1345 213..214 'z': dyn Trait<u64>
1346 213..220 'z.foo()': u64
1347 226..227 'x': dyn Trait<u64>
1348 226..234 'x.foo2()': i64
1349 240..241 'y': &dyn Trait<u64>
1350 240..248 'y.foo2()': i64
1351 254..255 'z': dyn Trait<u64>
1352 254..262 'z.foo2()': i64
1358 fn dyn_trait_in_impl() {
1362 fn foo(&self) -> (T, U);
1365 impl<T, U> S<T, U> {
1366 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1368 trait Trait2<T, U> {
1369 fn baz(&self) -> (T, U);
1371 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1373 fn test(s: S<u32, i32>) {
1377 32..36 'self': &Self
1378 102..106 'self': &S<T, U>
1379 128..139 '{ loop {} }': &dyn Trait<T, U>
1380 130..137 'loop {}': !
1382 175..179 'self': &Self
1383 251..252 's': S<u32, i32>
1384 267..289 '{ ...z(); }': ()
1385 273..274 's': S<u32, i32>
1386 273..280 's.bar()': &dyn Trait<u32, i32>
1387 273..286 's.bar().baz()': (u32, i32)
1393 fn dyn_trait_bare() {
1397 fn foo(&self) -> u64;
1399 fn bar() -> Trait {}
1401 fn test(x: Trait, y: &Trait) -> u64 {
1410 26..30 'self': &Self
1412 72..73 'x': dyn Trait
1413 82..83 'y': &dyn Trait
1414 100..175 '{ ...o(); }': ()
1415 106..107 'x': dyn Trait
1416 113..114 'y': &dyn Trait
1417 124..125 'z': dyn Trait
1418 128..131 'bar': fn bar() -> dyn Trait
1419 128..133 'bar()': dyn Trait
1420 139..140 'x': dyn Trait
1421 139..146 'x.foo()': u64
1422 152..153 'y': &dyn Trait
1423 152..159 'y.foo()': u64
1424 165..166 'z': dyn Trait
1425 165..172 'z.foo()': u64
1436 a: impl Trait + 'lifetime,
1439 d: impl ('lifetime),
1441 f: impl Trait + ?Sized
1445 28..29 'a': impl Trait
1447 82..83 'c': impl Trait
1450 148..149 'f': impl Trait
1457 fn error_bound_chalk() {
1461 fn foo(&self) -> u32 {}
1464 fn test(x: (impl Trait + UnknownTrait)) {
1472 fn assoc_type_bindings() {
1479 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1480 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1481 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1484 impl<T> Trait for S<T> { type Type = T; }
1486 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1504 262..263 'y': impl Trait<Type = i64>
1505 289..397 '{ ...r>); }': ()
1506 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1507 295..301 'get(x)': u32
1509 307..311 'get2': fn get2<u32, T>(T) -> u32
1510 307..314 'get2(x)': u32
1512 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1513 320..326 'get(y)': i64
1514 324..325 'y': impl Trait<Type = i64>
1515 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1516 332..339 'get2(y)': i64
1517 337..338 'y': impl Trait<Type = i64>
1518 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1519 345..356 'get(set(S))': u64
1520 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1521 349..355 'set(S)': S<u64>
1522 353..354 'S': S<u64>
1523 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1524 362..374 'get2(set(S))': u64
1525 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1526 367..373 'set(S)': S<u64>
1527 371..372 'S': S<u64>
1528 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1529 380..394 'get2(S::<str>)': str
1530 385..393 'S::<str>': S<str>
1536 fn impl_trait_assoc_binding_projection_bug() {
1539 //- /main.rs crate:main deps:std
1540 pub trait Language {
1543 pub enum RustLanguage {}
1544 impl Language for RustLanguage {
1545 type Kind = SyntaxKind;
1547 struct SyntaxNode<L> {}
1548 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1551 fn clone(&self) -> Self;
1554 fn api_walkthrough() {
1560 //- /std.rs crate:std
1561 #[prelude_import] use iter::*;
1563 trait IntoIterator {
1569 impl<T: Iterator> IntoIterator for T {
1570 type Item = <T as Iterator>::Item;
1578 fn projection_eq_within_chalk() {
1587 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1589 fn test<T: Trait1<Type = u32>>(x: T) {
1595 169..185 '{ ...o(); }': ()
1597 175..182 'x.foo()': u32
1603 fn where_clause_trait_in_scope_for_method_resolution() {
1608 fn foo(&self) -> u32 {}
1612 fn test<T: foo::Trait>(x: T) {
1620 fn super_trait_method_resolution() {
1625 fn foo(&self) -> u32 {}
1628 trait Trait1: foo::SuperTrait {}
1629 trait Trait2 where Self: foo::SuperTrait {}
1631 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1636 49..53 'self': &Self
1640 193..222 '{ ...o(); }': ()
1642 199..206 'x.foo()': u32
1644 212..219 'y.foo()': u32
1650 fn super_trait_impl_trait_method_resolution() {
1655 fn foo(&self) -> u32 {}
1658 trait Trait1: foo::SuperTrait {}
1660 fn test(x: &impl Trait1) {
1664 49..53 'self': &Self
1666 115..116 'x': &impl Trait1
1667 132..148 '{ ...o(); }': ()
1668 138..139 'x': &impl Trait1
1669 138..145 'x.foo()': u32
1675 fn super_trait_cycle() {
1676 // This just needs to not crash
1682 fn test<T: A>(x: T) {
1688 49..65 '{ ...o(); }': ()
1690 55..62 'x.foo()': {unknown}
1696 fn super_trait_assoc_type_bounds() {
1699 trait SuperTrait { type Type; }
1700 trait Trait where Self: SuperTrait {}
1702 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1703 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1706 impl<T> SuperTrait for S<T> { type Type = T; }
1707 impl<T> Trait for S<T> {}
1718 258..279 '{ ...S)); }': ()
1719 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1720 264..276 'get2(set(S))': u64
1721 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1722 269..275 'set(S)': S<u64>
1723 273..274 'S': S<u64>
1730 check_infer_with_mismatches(
1732 trait FnOnce<Args> {
1735 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1738 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1739 f.call_once((1, 2));
1745 155..183 '{ ...2)); }': ()
1747 161..180 'f.call...1, 2))': u128
1748 173..179 '(1, 2)': (u32, u64)
1756 fn fn_ptr_and_item() {
1757 check_infer_with_mismatches(
1760 trait FnOnce<Args> {
1763 fn call_once(self, args: Args) -> Self::Output;
1772 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1773 fn foo(&self) -> (A1, R) { loop {} }
1776 enum Opt<T> { None, Some(T) }
1778 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1782 let bar: Bar<fn(u8) -> u32>;
1786 let f: fn(u8) -> u32;
1792 139..143 'self': &Self
1793 243..247 'self': &Bar<F>
1794 260..271 '{ loop {} }': (A1, R)
1795 262..269 'loop {}': !
1797 355..359 'self': Opt<T>
1799 377..388 '{ loop {} }': Opt<U>
1800 379..386 'loop {}': !
1802 402..518 '{ ...(f); }': ()
1803 412..415 'bar': Bar<fn(u8) -> u32>
1804 441..444 'bar': Bar<fn(u8) -> u32>
1805 441..450 'bar.foo()': (u8, u32)
1806 461..464 'opt': Opt<u8>
1807 483..484 'f': fn(u8) -> u32
1808 505..508 'opt': Opt<u8>
1809 505..515 'opt.map(f)': Opt<u32>
1810 513..514 'f': fn(u8) -> u32
1816 fn fn_trait_deref_with_ty_default() {
1823 fn deref(&self) -> &Self::Target;
1827 trait FnOnce<Args> {
1830 fn call_once(self, args: Args) -> Self::Output;
1836 fn foo(&self) -> usize {}
1839 struct Lazy<T, F = fn() -> T>(F);
1841 impl<T, F> Lazy<T, F> {
1842 pub fn new(f: F) -> Lazy<T, F> {}
1845 impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
1850 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1851 let r1 = lazy1.foo();
1853 fn make_foo_fn() -> Foo {}
1854 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1855 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1856 let r2 = lazy2.foo();
1859 64..68 'self': &Self
1860 165..169 'self': Self
1861 171..175 'args': Args
1862 239..243 'self': &Foo
1866 443..689 '{ ...o(); }': ()
1867 453..458 'lazy1': Lazy<Foo, || -> Foo>
1868 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1869 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1870 485..491 '|| Foo': || -> Foo
1872 502..504 'r1': usize
1873 507..512 'lazy1': Lazy<Foo, || -> Foo>
1874 507..518 'lazy1.foo()': usize
1875 560..575 'make_foo_fn_ptr': fn() -> Foo
1876 591..602 'make_foo_fn': fn make_foo_fn() -> Foo
1877 612..617 'lazy2': Lazy<Foo, fn() -> Foo>
1878 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1879 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1880 644..659 'make_foo_fn_ptr': fn() -> Foo
1881 670..672 'r2': usize
1882 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1883 675..686 'lazy2.foo()': usize
1891 check_infer_with_mismatches(
1894 trait FnOnce<Args> {
1898 enum Option<T> { Some(T), None }
1900 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1904 let x = Option::Some(1u32);
1907 let y: Option<i64> = x.map(|_v| 1);
1910 147..151 'self': Option<T>
1912 172..183 '{ loop {} }': Option<U>
1913 174..181 'loop {}': !
1915 197..316 '{ ... 1); }': ()
1916 207..208 'x': Option<u32>
1917 211..223 'Option::Some': Some<u32>(u32) -> Option<u32>
1918 211..229 'Option...(1u32)': Option<u32>
1919 224..228 '1u32': u32
1920 235..236 'x': Option<u32>
1921 235..251 'x.map(...v + 1)': Option<u32>
1922 241..250 '|v| v + 1': |u32| -> u32
1925 245..250 'v + 1': u32
1927 257..258 'x': Option<u32>
1928 257..273 'x.map(... 1u64)': Option<u64>
1929 263..272 '|_v| 1u64': |u32| -> u64
1931 268..272 '1u64': u64
1932 283..284 'y': Option<i64>
1933 300..301 'x': Option<u32>
1934 300..313 'x.map(|_v| 1)': Option<i64>
1935 306..312 '|_v| 1': |u32| -> i64
1944 check_infer_with_mismatches(
1947 pub trait Add<Rhs = Self> {
1949 fn add(self, rhs: Rhs) -> Self::Output;
1952 trait FnOnce<Args> {
1958 fn add(self, rhs: u64) -> Self::Output {0}
1963 fn add(self, rhs: u128) -> Self::Output {0}
1966 fn test<F: FnOnce(u32) -> u64>(f: F) {
1970 let h = |v| 1u128 + v;
1975 203..207 'self': u64
1979 297..301 'self': u128
1980 303..306 'rhs': u128
1981 330..333 '{0}': u128
1984 374..450 '{ ...+ v; }': ()
1986 380..384 'f(1)': {unknown}
1988 394..395 'g': |u64| -> u64
1989 398..407 '|v| v + 1': |u64| -> u64
1992 402..407 'v + 1': u64
1994 413..414 'g': |u64| -> u64
1995 413..420 'g(1u64)': u64
1996 415..419 '1u64': u64
1997 430..431 'h': |u128| -> u128
1998 434..447 '|v| 1u128 + v': |u128| -> u128
2000 438..443 '1u128': u128
2001 438..447 '1u128 + v': u128
2008 fn closure_as_argument_inference_order() {
2009 check_infer_with_mismatches(
2012 trait FnOnce<Args> {
2016 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
2017 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
2021 fn method(self) -> u64;
2023 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
2024 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
2028 let x1 = foo1(S, |s| s.method());
2029 let x2 = foo2(|s| s.method(), S);
2030 let x3 = S.foo1(S, |s| s.method());
2031 let x4 = S.foo2(|s| s.method(), S);
2036 111..122 '{ loop {} }': U
2037 113..120 'loop {}': !
2041 173..184 '{ loop {} }': U
2042 175..182 'loop {}': !
2048 294..305 '{ loop {} }': U
2049 296..303 'loop {}': !
2054 366..377 '{ loop {} }': U
2055 368..375 'loop {}': !
2057 391..550 '{ ... S); }': ()
2059 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2060 406..429 'foo1(S...hod())': u64
2062 414..428 '|s| s.method()': |S| -> u64
2065 418..428 's.method()': u64
2067 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2068 444..467 'foo2(|...(), S)': u64
2069 449..463 '|s| s.method()': |S| -> u64
2072 453..463 's.method()': u64
2076 482..507 'S.foo1...hod())': u64
2078 492..506 '|s| s.method()': |S| -> u64
2081 496..506 's.method()': u64
2084 522..547 'S.foo2...(), S)': u64
2085 529..543 '|s| s.method()': |S| -> u64
2088 533..543 's.method()': u64
2095 fn fn_item_fn_trait() {
2099 trait FnOnce<Args> {
2107 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2111 } //^^^^^^^^^^^^^^^^^^ S
2117 fn unselected_projection_in_trait_env_1() {
2126 fn foo(&self) -> u32;
2129 fn test<T: Trait>() where T::Item: Trait2 {
2130 let x: T::Item = no_matter;
2138 fn unselected_projection_in_trait_env_2() {
2146 fn foo(&self) -> u32;
2149 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2150 let x: T::Item = no_matter;
2158 fn unselected_projection_on_impl_self() {
2165 fn f(&self, x: Self::Item);
2172 fn f(&self, x: Self::Item) { let y = x; }
2179 fn f(&self, x: <Self>::Item) { let y = x; }
2182 40..44 'self': &Self
2183 46..47 'x': Trait::Item<Self>
2186 147..161 '{ let y = x; }': ()
2189 228..232 'self': &S2
2191 251..265 '{ let y = x; }': ()
2199 fn unselected_projection_on_trait_self() {
2205 fn f(&self) -> Self::Item { loop {} }
2221 fn unselected_projection_chalk_fold() {
2225 trait Fold<I: Interner, TI = I> {
2229 struct Ty<I: Interner> {}
2230 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2231 type Result = Ty<TI>;
2234 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2241 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2249 fn trait_impl_self_ty() {
2258 impl Trait<Self> for S {}
2268 fn trait_impl_self_ty_cycle() {
2277 impl Trait for S<Self> {}
2287 fn unselected_projection_in_trait_env_cycle_1() {
2288 // this is a legitimate cycle
2297 fn test<T: Trait>() where T: Trait2<T::Item> {
2298 let x: T::Item = no_matter;
2305 fn unselected_projection_in_trait_env_cycle_2() {
2306 // this is a legitimate cycle
2314 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2315 let x: T::Item = no_matter;
2322 fn unselected_projection_in_trait_env_cycle_3() {
2323 // this is a cycle for rustc; we currently accept it
2332 fn test<T>() where T: Trait<OtherItem = T::Item> {
2333 let x: T::Item = no_matter;
2334 } //^ Trait::Item<T>
2340 fn unselected_projection_in_trait_env_no_cycle() {
2341 // this is not a cycle
2349 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2351 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2354 fn len(&self) -> usize;
2357 pub trait UnificationStoreMut: UnificationStoreBase {
2358 fn push(&mut self, value: Self::Key);
2361 fn test<T>(t: T) where T: UnificationStoreMut {
2366 } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2372 fn inline_assoc_type_bounds_1() {
2378 trait OtherTrait<T> {
2382 // workaround for Chalk assoc type normalization problems
2384 impl<T: Iterator> Iterator for S<T> {
2385 type Item = <T as Iterator>::Item;
2388 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2389 let x: <S<I> as Iterator>::Item;
2397 fn inline_assoc_type_bounds_2() {
2404 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2405 let x: <<I as Iterator>::Item as Iterator>::Item;
2413 fn proc_macro_server_types() {
2416 macro_rules! with_api {
2417 ($S:ident, $self:ident, $m:ident) => {
2420 fn new() -> $S::TokenStream;
2427 macro_rules! associated_item {
2428 (type TokenStream) =>
2429 (type TokenStream: 'static;);
2431 (type Group: 'static;);
2432 ($($item:tt)*) => ($($item)*;)
2434 macro_rules! declare_server_traits {
2436 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2439 $(associated_item!(type $name);)*
2442 $(pub trait $name: Types {
2443 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2446 pub trait Server: Types $(+ $name)* {}
2447 impl<S: Types $(+ $name)*> Server for S {}
2451 with_api!(Self, self_, declare_server_traits);
2455 impl Types for Rustc {
2456 type TokenStream = T;
2460 fn make<T>() -> T { loop {} }
2461 impl TokenStream for Rustc {
2462 fn new() -> Self::TokenStream {
2463 let group: Self::Group = make();
2468 1061..1072 '{ loop {} }': T
2469 1063..1070 'loop {}': !
2471 1136..1199 '{ ... }': T
2472 1150..1155 'group': G
2473 1171..1175 'make': fn make<G>() -> G
2474 1171..1177 'make()': G
2475 1187..1191 'make': fn make<T>() -> T
2476 1187..1193 'make()': T
2482 fn unify_impl_trait() {
2483 check_infer_with_mismatches(
2487 fn foo(x: impl Trait<u32>) { loop {} }
2488 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2491 impl<T> Trait<T> for S<T> {}
2493 fn default<T>() -> T { loop {} }
2495 fn test() -> impl Trait<i32> {
2496 let s1 = S(default());
2498 let x: i32 = bar(S(default()));
2502 26..27 'x': impl Trait<u32>
2503 46..57 '{ loop {} }': ()
2506 68..69 'x': impl Trait<T>
2507 91..102 '{ loop {} }': T
2508 93..100 'loop {}': !
2510 171..182 '{ loop {} }': T
2511 173..180 'loop {}': !
2513 213..309 '{ ...t()) }': S<{unknown}>
2514 223..225 's1': S<u32>
2515 228..229 'S': S<u32>(u32) -> S<u32>
2516 228..240 'S(default())': S<u32>
2517 230..237 'default': fn default<u32>() -> u32
2518 230..239 'default()': u32
2519 246..249 'foo': fn foo(S<u32>)
2520 246..253 'foo(s1)': ()
2521 250..252 's1': S<u32>
2523 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2524 272..289 'bar(S(...lt()))': i32
2525 276..277 'S': S<i32>(i32) -> S<i32>
2526 276..288 'S(default())': S<i32>
2527 278..285 'default': fn default<i32>() -> i32
2528 278..287 'default()': i32
2529 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2530 295..307 'S(default())': S<{unknown}>
2531 297..304 'default': fn default<{unknown}>() -> {unknown}
2532 297..306 'default()': {unknown}
2538 fn assoc_types_from_bounds() {
2543 trait FnOnce<Args> {
2562 f::<(), _>(|z| { z; });
2567 193..224 '{ ... }); }': ()
2568 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2569 199..221 'f::<()... z; })': ()
2570 210..220 '|z| { z; }': |&()| -> ()
2572 214..220 '{ z; }': ()
2579 fn associated_type_bound() {
2583 type Item: OtherTrait<u32>;
2585 pub trait OtherTrait<T> {
2589 // this is just a workaround for chalk#234
2591 impl<T: Trait> Trait for S<T> {
2592 type Item = <T as Trait>::Item;
2595 fn test<T: Trait>() {
2596 let y: <S<T> as Trait>::Item = no_matter;
2604 fn dyn_trait_through_chalk() {
2612 impl<T> Deref for Box<T> {
2619 fn test(x: Box<dyn Trait>) {
2627 fn string_to_owned() {
2633 fn to_owned(&self) -> Self::Owned;
2635 impl ToOwned for str {
2636 type Owned = String;
2646 fn iterator_chain() {
2647 check_infer_with_mismatches(
2651 trait FnOnce<Args> {
2655 trait FnMut<Args>: FnOnce<Args> { }
2657 enum Option<T> { Some(T), None }
2660 pub trait Iterator {
2663 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2665 F: FnMut(Self::Item) -> Option<B>,
2668 fn for_each<F>(self, f: F)
2670 F: FnMut(Self::Item),
2674 pub trait IntoIterator {
2676 type IntoIter: Iterator<Item = Self::Item>;
2677 fn into_iter(self) -> Self::IntoIter;
2680 pub struct FilterMap<I, F> { }
2681 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2683 F: FnMut(I::Item) -> Option<B>,
2688 #[stable(feature = "rust1", since = "1.0.0")]
2689 impl<I: Iterator> IntoIterator for I {
2690 type Item = I::Item;
2693 fn into_iter(self) -> I {
2700 fn new() -> Self { loop {} }
2703 impl<T> IntoIterator for Vec<T> {
2705 type IntoIter = IntoIter<T>;
2708 pub struct IntoIter<T> { }
2709 impl<T> Iterator for IntoIter<T> {
2714 Vec::<i32>::new().into_iter()
2715 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2716 .for_each(|y| { y; });
2719 226..230 'self': Self
2721 317..328 '{ loop {} }': FilterMap<Self, F>
2722 319..326 'loop {}': !
2724 349..353 'self': Self
2726 405..416 '{ loop {} }': ()
2727 407..414 'loop {}': !
2729 525..529 'self': Self
2731 865..885 '{ ... }': I
2733 944..955 '{ loop {} }': Vec<T>
2734 946..953 'loop {}': !
2736 1142..1269 '{ ... }); }': ()
2737 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2738 1148..1165 'Vec::<...:new()': Vec<i32>
2739 1148..1177 'Vec::<...iter()': IntoIter<i32>
2740 1148..1240 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2741 1148..1266 'Vec::<... y; })': ()
2742 1194..1239 '|x| if...None }': |i32| -> Option<u32>
2744 1198..1239 'if x >...None }': Option<u32>
2746 1201..1206 'x > 0': bool
2748 1207..1225 '{ Some...u32) }': Option<u32>
2749 1209..1213 'Some': Some<u32>(u32) -> Option<u32>
2750 1209..1223 'Some(x as u32)': Option<u32>
2752 1214..1222 'x as u32': u32
2753 1231..1239 '{ None }': Option<u32>
2754 1233..1237 'None': Option<u32>
2755 1255..1265 '|y| { y; }': |u32| -> ()
2757 1259..1265 '{ y; }': ()
2780 fn foo() -> Self::Output;
2784 type Output = T::OutputA;
2785 fn foo() -> Self::Output { loop {} }
2796 fn trait_object_no_coercion() {
2797 check_infer_with_mismatches(
2801 fn foo(x: &dyn Foo) {}
2803 fn test(x: &dyn Foo) {
2807 21..22 'x': &dyn Foo
2809 46..47 'x': &dyn Foo
2810 59..74 '{ foo(x); }': ()
2811 65..68 'foo': fn foo(&dyn Foo)
2813 69..70 'x': &dyn Foo
2820 check_infer_with_mismatches(
2826 impl Copy for IsCopy {}
2829 trait Test { fn test(&self) -> bool; }
2830 impl<T: Copy> Test for T {}
2835 (IsCopy, IsCopy).test();
2836 (IsCopy, NotCopy).test();
2839 110..114 'self': &Self
2840 166..267 '{ ...t(); }': ()
2841 172..178 'IsCopy': IsCopy
2842 172..185 'IsCopy.test()': bool
2843 191..198 'NotCopy': NotCopy
2844 191..205 'NotCopy.test()': {unknown}
2845 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy)
2846 211..234 '(IsCop...test()': bool
2847 212..218 'IsCopy': IsCopy
2848 220..226 'IsCopy': IsCopy
2849 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy)
2850 240..264 '(IsCop...test()': {unknown}
2851 241..247 'IsCopy': IsCopy
2852 249..256 'NotCopy': NotCopy
2858 fn builtin_fn_def_copy() {
2859 check_infer_with_mismatches(
2865 fn bar<T: Copy>(T) -> T {}
2866 struct Struct(usize);
2867 enum Enum { Variant(usize) }
2869 trait Test { fn test(&self) -> bool; }
2870 impl<T: Copy> Test for T {}
2876 Enum::Variant.test();
2880 60..61 'T': {unknown}
2882 68..70: expected T, got ()
2883 145..149 'self': &Self
2884 201..281 '{ ...t(); }': ()
2885 207..210 'foo': fn foo()
2886 207..217 'foo.test()': bool
2887 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2888 223..233 'bar.test()': bool
2889 239..245 'Struct': Struct(usize) -> Struct
2890 239..252 'Struct.test()': bool
2891 258..271 'Enum::Variant': Variant(usize) -> Enum
2892 258..278 'Enum::...test()': bool
2898 fn builtin_fn_ptr_copy() {
2899 check_infer_with_mismatches(
2904 trait Test { fn test(&self) -> bool; }
2905 impl<T: Copy> Test for T {}
2907 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2913 54..58 'self': &Self
2915 118..120 'f2': fn(usize) -> u8
2916 139..141 'f3': fn(u8, u8) -> &u8
2917 162..210 '{ ...t(); }': ()
2919 168..177 'f1.test()': bool
2920 183..185 'f2': fn(usize) -> u8
2921 183..192 'f2.test()': bool
2922 198..200 'f3': fn(u8, u8) -> &u8
2923 198..207 'f3.test()': bool
2929 fn builtin_sized() {
2930 check_infer_with_mismatches(
2935 trait Test { fn test(&self) -> bool; }
2936 impl<T: Sized> Test for T {}
2940 (*"foo").test(); // not Sized
2942 (1u8, *"foo").test(); // not Sized
2945 56..60 'self': &Self
2946 113..228 '{ ...ized }': ()
2948 119..129 '1u8.test()': bool
2949 135..150 '(*"foo").test()': {unknown}
2950 136..142 '*"foo"': str
2951 137..142 '"foo"': &str
2952 169..179 '(1u8, 1u8)': (u8, u8)
2953 169..186 '(1u8, ...test()': bool
2956 192..205 '(1u8, *"foo")': (u8, str)
2957 192..212 '(1u8, ...test()': {unknown}
2959 198..204 '*"foo"': str
2960 199..204 '"foo"': &str
2966 fn integer_range_iterate() {
2969 //- /main.rs crate:main deps:core
2971 for x in 0..100 { x; }
2974 //- /core.rs crate:core
2976 pub struct Range<Idx> {
2983 pub trait Iterator {
2987 pub trait IntoIterator {
2989 type IntoIter: Iterator<Item = Self::Item>;
2992 impl<T> IntoIterator for T where T: Iterator {
2993 type Item = <T as Iterator>::Item;
2994 type IntoIter = Self;
2999 impl Step for i32 {}
3000 impl Step for i64 {}
3002 impl<A: Step> iter::Iterator for ops::Range<A> {
3010 fn infer_closure_arg() {
3021 let s = Option::None;
3022 let f = |x: Option<i32>| {};
3026 52..126 '{ ...)(s) }': ()
3027 62..63 's': Option<i32>
3028 66..78 'Option::None': Option<i32>
3029 88..89 'f': |Option<i32>| -> ()
3030 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
3031 93..94 'x': Option<i32>
3033 117..124 '(&f)(s)': ()
3034 118..120 '&f': &|Option<i32>| -> ()
3035 119..120 'f': |Option<i32>| -> ()
3036 122..123 's': Option<i32>
3042 fn infer_fn_trait_arg() {
3043 check_infer_with_mismatches(
3045 //- /lib.rs deps:std
3048 pub trait FnOnce<Args> {
3051 extern "rust-call" fn call_once(&self, args: Args) -> Self::Output;
3055 pub trait Fn<Args>:FnOnce<Args> {
3056 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3064 fn foo<F, T>(f: F) -> T
3066 F: Fn(Option<i32>) -> T,
3073 101..105 'self': &Self
3074 107..111 'args': Args
3075 220..224 'self': &Self
3076 226..230 'args': Args
3078 359..389 '{ ...f(s) }': T
3079 369..370 's': Option<i32>
3080 373..377 'None': Option<i32>
3083 385..386 's': Option<i32>
3089 fn infer_box_fn_arg() {
3090 // The type mismatch is because we don't define Unsize and CoerceUnsized
3091 check_infer_with_mismatches(
3093 //- /lib.rs deps:std
3096 pub trait FnOnce<Args> {
3099 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3104 type Target: ?Sized;
3106 fn deref(&self) -> &Self::Target;
3109 #[lang = "owned_box"]
3110 pub struct Box<T: ?Sized> {
3114 impl<T: ?Sized> Deref for Box<T> {
3117 fn deref(&self) -> &T {
3128 let s = Option::None;
3129 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3133 100..104 'self': Self
3134 106..110 'args': Args
3135 214..218 'self': &Self
3136 384..388 'self': &Box<T>
3137 396..423 '{ ... }': &T
3138 406..417 '&self.inner': &*mut T
3139 407..411 'self': &Box<T>
3140 407..417 'self.inner': *mut T
3141 478..576 '{ ...&s); }': ()
3142 488..489 's': Option<i32>
3143 492..504 'Option::None': Option<i32>
3144 514..515 'f': Box<dyn FnOnce(&Option<i32>)>
3145 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3146 554..561 '|ps| {}': |{unknown}| -> ()
3147 555..557 'ps': {unknown}
3149 568..569 'f': Box<dyn FnOnce(&Option<i32>)>
3150 568..573 'f(&s)': ()
3151 570..572 '&s': &Option<i32>
3152 571..572 's': Option<i32>
3153 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
3159 fn infer_dyn_fn_output() {
3163 pub trait FnOnce<Args> {
3165 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3169 pub trait Fn<Args>: FnOnce<Args> {
3170 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3174 let f: &dyn Fn() -> i32;
3182 fn infer_dyn_fn_once_output() {
3186 pub trait FnOnce<Args> {
3188 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3192 let f: dyn FnOnce() -> i32;
3200 fn variable_kinds_1() {
3203 trait Trait<T> { fn get(self, t: T) -> T; }
3205 impl Trait<u128> for S {}
3206 impl Trait<f32> for S {}
3218 fn variable_kinds_2() {
3221 trait Trait { fn get(self) -> Self; }
3222 impl Trait for u128 {}
3223 impl Trait for f32 {}
3235 fn underscore_import() {
3240 fn method(&self) -> u8 { 0 }
3245 impl crate::tr::Tr for Tr {}
3247 use crate::tr::Tr as _;
3262 fn method(&self) -> u8 { 0 }
3279 fn trait_in_scope_with_inner_item() {
3284 fn method(&self) -> u8 { 0 }
3299 46..50 'self': &Self
3302 115..185 '{ ... } }': ()
3303 132..183 '{ ... }': ()
3305 142..153 '().method()': u8
3311 fn inner_use_in_block() {
3316 fn method(&self) -> u8 { 0 }
3332 //^^^^^^^^^^^ {unknown}
3336 //^^^^^^^^^^^ {unknown}
3343 fn nested_inner_function_calling_self() {
3353 17..73 '{ ... } }': ()
3354 39..71 '{ ... }': ()
3356 57..62 'inner': fn inner() -> S
3363 fn infer_default_trait_type_parameter() {
3368 trait Op<RHS=Self> {
3371 fn do_op(self, rhs: RHS) -> Self::Output;
3377 fn do_op(self, rhs: Self) -> Self::Output {
3392 186..206 '{ ... }': bool
3393 196..200 'true': bool
3394 220..277 '{ ...(y); }': ()
3401 264..274 'x.do_op(y)': bool
3408 fn qualified_path_as_qualified_trait() {
3418 fn boo() -> Self::Output {
3425 impl foo::Foo for F {
3428 impl foo::Bar for F {
3429 type Output = <F as foo::Foo>::Target;
3434 let x = <F as Bar>::boo();
3437 132..163 '{ ... }': Bar::Output<Self>
3438 146..153 'loop {}': !
3440 306..358 '{ ...o(); }': ()
3442 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3443 338..355 '<F as ...:boo()': ()
3449 fn renamed_extern_crate_in_block() {
3452 //- /lib.rs crate:lib deps:serde
3453 use serde::Deserialize;
3458 extern crate serde as _serde;
3459 impl _serde::Deserialize for Foo {
3460 fn deserialize() -> u8 { 0 }
3466 //^^^^^^^^^^^^^^^^^^ u8
3469 //- /serde.rs crate:serde
3471 pub trait Deserialize {
3472 fn deserialize() -> u8;
3478 fn bin_op_adt_with_rhs_primitive() {
3479 check_infer_with_mismatches(
3482 pub trait Add<Rhs = Self> {
3484 fn add(self, rhs: Rhs) -> Self::Output;
3487 struct Wrapper(u32);
3488 impl Add<u32> for Wrapper {
3490 fn add(self, rhs: u32) -> Wrapper {
3495 let wrapped = Wrapper(10);
3497 let res = wrapped + num;
3503 192..196 'self': Wrapper
3505 219..247 '{ ... }': Wrapper
3506 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3507 229..241 'Wrapper(rhs)': Wrapper
3509 259..345 '{ ...um; }': ()
3510 269..276 'wrapped': Wrapper
3511 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3512 279..290 'Wrapper(10)': Wrapper
3516 322..325 'res': Wrapper
3517 328..335 'wrapped': Wrapper
3518 328..341 'wrapped + num': Wrapper
3530 fn do_thing(&self) -> Self::Output;
3533 impl T for [u8; 4] {
3534 type Output = usize;
3535 fn do_thing(&self) -> Self::Output {
3540 impl T for [u8; 2] {
3542 fn do_thing(&self) -> Self::Output {
3549 let v2 = v.do_thing();
3551 let v4 = v3.do_thing();
3555 44..48 'self': &Self
3556 133..137 'self': &[u8; 4]
3557 155..172 '{ ... }': usize
3559 236..240 'self': &[u8; 2]
3560 258..275 '{ ... }': u8
3562 289..392 '{ ...g(); }': ()
3563 299..300 'v': [u8; 2]
3564 303..311 '[0u8; 2]': [u8; 2]
3568 326..327 'v': [u8; 2]
3569 326..338 'v.do_thing()': u8
3570 348..350 'v3': [u8; 4]
3571 353..361 '[0u8; 4]': [u8; 4]
3574 371..373 'v4': usize
3575 376..378 'v3': [u8; 4]
3576 376..389 'v3.do_thing()': usize
3581 // FIXME: We should infer the length of the returned array :)
3583 fn const_generics() {
3588 fn do_thing(&self) -> Self::Output;
3591 impl<const L: usize> T for [u8; L] {
3592 type Output = [u8; L];
3593 fn do_thing(&self) -> Self::Output {
3600 let v2 = v.do_thing();
3604 44..48 'self': &Self
3605 151..155 'self': &[u8; _]
3606 173..194 '{ ... }': [u8; _]
3607 183..188 '*self': [u8; _]
3608 184..188 'self': &[u8; _]
3609 208..260 '{ ...g(); }': ()
3610 218..219 'v': [u8; 2]
3611 222..230 '[0u8; 2]': [u8; 2]
3614 240..242 'v2': [u8; _]
3615 245..246 'v': [u8; 2]
3616 245..257 'v.do_thing()': [u8; _]
3622 fn fn_returning_unit() {
3623 check_infer_with_mismatches(
3626 trait FnOnce<Args> {
3630 fn test<F: FnOnce()>(f: F) {
3635 88..112 '{ ...f(); }': ()
3644 fn trait_in_scope_of_trait_impl() {
3650 fn bar(self) -> usize { 0 }
3653 impl foo::Foo for u32 {
3655 let _x = self.bar();
3662 82..87 '{ 0 }': usize
3664 131..135 'self': u32
3665 137..173 '{ ... }': ()
3666 151..153 '_x': usize
3667 156..160 'self': u32
3668 156..166 'self.bar()': usize
3674 fn infer_async_ret_type() {
3677 //- /main.rs crate:main deps:core
3690 fn collect<B: Convert>(self) -> B {
3698 impl Convert for u32 {
3704 async fn get_accounts() -> Result<u32, ()> {
3705 let ret = Fooey.collect();
3710 //- /core.rs crate:core
3711 #[prelude_import] use future::*;
3713 #[lang = "future_trait"]
3732 impl Trait<u32> for S {
3753 impl Trait<u32> for S {
3777 impl Trait<S1> for S2 {
3778 fn foo(&self) { S1 }