1 use expect_test::expect;
3 use super::{check_infer, check_infer_with_mismatches, check_types};
12 impl core::future::Future for IntFuture {
30 async fn foo() -> u64 { 128 }
42 fn infer_desugar_async() {
46 async fn foo() -> u64 { 128 }
51 } //^ impl Future<Output = u64>
57 fn infer_async_block() {
60 //- minicore: future, option
64 // ^ impl Future<Output = i32>
68 let b = async {}.await;
76 let _: Option<u64> = c.await;
78 // ^ impl Future<Output = Option<u64>>
88 //- /main.rs crate:main deps:core
90 let r: Result<i32, u64> = Result::Ok(1);
95 //- /core.rs crate:core
104 pub enum Result<O, E> {
109 impl<O, E> crate::ops::Try for Result<O, E> {
117 pub use crate::{result::*, ops::*};
125 fn infer_try_trait_v2() {
128 //- /main.rs crate:main deps:core
130 let r: Result<i32, u64> = Result::Ok(1);
135 //- /core.rs crate:core
138 pub trait Try: FromResidual {
142 pub trait FromResidual<R = <Self as Try>::Residual> {}
145 pub use self::try_trait::FromResidual;
146 pub use self::try_trait::Try;
151 impl<T> From<T> for T {}
155 use crate::convert::From;
156 use crate::ops::{Try, FromResidual};
158 pub enum Infallible {}
159 pub enum Result<O, E> {
164 impl<O, E> Try for Result<O, E> {
166 type Error = Result<Infallible, E>;
169 impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
174 pub use crate::result::*;
182 fn infer_for_loop() {
185 //- /main.rs crate:main deps:core,alloc
187 use alloc::collections::Vec;
197 //- /core.rs crate:core
199 pub trait IntoIterator {
205 pub use crate::iter::*;
209 //- /alloc.rs crate:alloc deps:core
214 pub fn new() -> Self { Vec {} }
215 pub fn push(&mut self, t: T) { }
218 impl<T> IntoIterator for Vec<T> {
230 //- /main.rs crate:main deps:std
234 impl std::ops::Neg for Bar {
244 //- /std.rs crate:std
245 #[prelude_import] use ops::*;
260 //- /main.rs crate:main deps:std
264 impl std::ops::Not for Bar {
274 //- /std.rs crate:std
275 #[prelude_import] use ops::*;
287 fn infer_from_bound_1() {
292 impl<U> Trait<U> for S<U> {}
293 fn foo<T: Trait<u32>>(t: T) {}
301 104..143 '{ ...(s); }': ()
303 118..119 'S': S<u32>(u32) -> S<u32>
304 118..128 'S(unknown)': S<u32>
305 120..127 'unknown': u32
306 134..137 'foo': fn foo<S<u32>>(S<u32>)
307 134..140 'foo(s)': ()
314 fn infer_from_bound_2() {
319 impl<U> Trait<U> for S<U> {}
320 fn foo<U, T: Trait<U>>(t: T) -> U {}
328 110..162 '{ ...(s); }': ()
330 124..125 'S': S<u32>(u32) -> S<u32>
331 124..134 'S(unknown)': S<u32>
332 126..133 'unknown': u32
334 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32
335 153..159 'foo(s)': u32
342 fn trait_default_method_self_bound_implements_trait() {
343 cov_mark::check!(trait_self_implements_self);
347 fn foo(&self) -> i64;
358 79..89 'self.foo()': i64
364 fn trait_default_method_self_bound_implements_super_trait() {
368 fn foo(&self) -> i64;
370 trait Trait: SuperTrait {
378 94..129 '{ ... }': ()
380 112..116 'self': &Self
381 112..122 'self.foo()': i64
387 fn infer_project_associated_type() {
394 impl Iterable for S { type Item = u32; }
395 fn test<T: Iterable>() {
396 let x: <S as Iterable>::Item = 1;
397 let y: <T as Iterable>::Item = no_matter;
398 let z: T::Item = no_matter;
399 let a: <T>::Item = no_matter;
402 108..261 '{ ...ter; }': ()
405 156..157 'y': Iterable::Item<T>
406 183..192 'no_matter': Iterable::Item<T>
407 202..203 'z': Iterable::Item<T>
408 215..224 'no_matter': Iterable::Item<T>
409 234..235 'a': Iterable::Item<T>
410 249..258 'no_matter': Iterable::Item<T>
416 fn infer_return_associated_type() {
423 impl Iterable for S { type Item = u32; }
424 fn foo1<T: Iterable>(t: T) -> T::Item {}
425 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {}
426 fn foo3<T: Iterable>(t: T) -> <T>::Item {}
439 234..300 '{ ...(S); }': ()
441 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item
442 248..255 'foo1(S)': u32
445 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item
446 269..276 'foo2(S)': u32
449 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item
450 290..297 'foo3(S)': u32
457 fn infer_associated_type_bound() {
463 fn test<T: Iterable<Item=u32>>() {
464 let y: T::Item = unknown;
467 67..100 '{ ...own; }': ()
469 90..97 'unknown': u32
475 fn infer_const_body() {
478 const A: u32 = 1 + 1;
479 static B: u64 = { let x = 1; x };"#,
484 38..54 '{ let ...1; x }': u64
493 fn tuple_struct_fields() {
503 37..86 '{ ... a.1 }': u64
505 51..52 'S': S(i32, u64) -> S
519 fn tuple_struct_with_fn() {
522 struct S(fn(u32) -> u64);
529 43..101 '{ ...0(2) }': u64
531 57..58 'S': S(fn(u32) -> u64) -> S
532 57..67 'S(|i| 2*i)': S
533 59..66 '|i| 2*i': |u32| -> u64
540 81..84 'a.0': fn(u32) -> u64
544 93..96 'a.0': fn(u32) -> u64
552 fn indexing_arrays() {
554 "fn main() { &mut [9][2]; }",
556 10..26 '{ &mut...[2]; }': ()
557 12..23 '&mut [9][2]': &mut {unknown}
558 17..20 '[9]': [i32; 1]
559 17..23 '[9][2]': {unknown}
567 fn infer_ops_index() {
570 //- /main.rs crate:main deps:std
574 impl std::ops::Index<u32> for Bar {
584 //- /std.rs crate:std
585 #[prelude_import] use ops::*;
588 pub trait Index<Idx> {
597 fn infer_ops_index_int() {
600 //- /main.rs crate:main deps:std
604 impl std::ops::Index<u32> for Bar {
609 impl std::ops::Index<Range> for Bar {
620 //- /std.rs crate:std
621 #[prelude_import] use ops::*;
624 pub trait Index<Idx> {
633 fn infer_ops_index_autoderef() {
636 //- /main.rs crate:main deps:std
638 let a = &[1u32, 2, 3];
643 //- /std.rs crate:std
644 impl<T> ops::Index<u32> for [T] {
648 #[prelude_import] use ops::*;
651 pub trait Index<Idx> {
665 impl<T> core::ops::Deref for Arc<T> {
671 fn foo(&self) -> u128 {}
682 fn deref_trait_with_inference_var() {
687 fn new_arc<T>() -> Arc<T> {}
688 impl<T> core::ops::Deref for Arc<T> {
706 fn deref_trait_infinite_recursion() {
712 impl core::ops::Deref for S {
724 fn deref_trait_with_question_mark_size() {
729 impl<T: ?Sized> core::ops::Deref for Arc<T> {
735 fn foo(&self) -> u128 {}
746 fn obligation_from_function_clause() {
752 impl Trait<u32> for S {}
754 fn foo<T: Trait<U>, U>(t: T) -> U {}
764 fn obligation_from_method_clause() {
771 impl Trait<isize> for S {}
775 fn foo<T: Trait<U>, U>(&self, t: T) -> U {}
786 fn obligation_from_self_method_clause() {
792 impl Trait<i64> for S {}
795 fn foo<U>(&self) -> U where Self: Trait<U> {}
806 fn obligation_from_impl_clause() {
812 impl Trait<&str> for S {}
815 impl<U, T: Trait<U>> O<T> {
816 fn foo(&self) -> U {}
827 fn generic_param_env_1() {
831 trait Trait { fn foo(self) -> u128; }
834 impl<T> Trait for T where T: Clone {}
835 fn test<T: Clone>(t: T) { t.foo(); }
842 fn generic_param_env_1_not_met() {
847 trait Trait { fn foo(self) -> u128; }
850 impl<T> Trait for T where T: Clone {}
851 fn test<T>(t: T) { t.foo(); }
858 fn generic_param_env_2() {
861 trait Trait { fn foo(self) -> u128; }
864 fn test<T: Trait>(t: T) { t.foo(); }
871 fn generic_param_env_2_not_met() {
874 trait Trait { fn foo(self) -> u128; }
877 fn test<T>(t: T) { t.foo(); }
884 fn generic_param_env_deref() {
892 impl<T> Deref for T where T: Trait {
895 fn test<T: Trait>(t: T) { (*t); }
902 fn associated_type_placeholder() {
903 // 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].
910 pub struct RefMutL<T>;
912 impl<T> ApplyL for RefMutL<T> {
913 type Out = <T as ApplyL>::Out;
916 fn test<T: ApplyL>() {
917 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
925 fn associated_type_placeholder_2() {
931 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
933 fn test<T: ApplyL>(t: T) {
942 fn argument_impl_trait() {
943 check_infer_with_mismatches(
947 fn foo2(&self) -> i64;
949 fn bar(x: impl Trait<u16>) {}
951 impl<T> Trait<T> for S<T> {}
953 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
968 77..78 'x': impl Trait<u16>
970 154..155 'x': impl Trait<u64>
971 174..175 'y': &impl Trait<u32>
972 195..323 '{ ...2(); }': ()
973 201..202 'x': impl Trait<u64>
974 208..209 'y': &impl Trait<u32>
976 223..224 'S': S<u16>(u16) -> S<u16>
977 223..227 'S(1)': S<u16>
979 233..236 'bar': fn bar(S<u16>)
980 233..239 'bar(z)': ()
982 245..246 'x': impl Trait<u64>
983 245..252 'x.foo()': u64
984 258..259 'y': &impl Trait<u32>
985 258..265 'y.foo()': u32
987 271..278 'z.foo()': u16
988 284..285 'x': impl Trait<u64>
989 284..292 'x.foo2()': i64
990 298..299 'y': &impl Trait<u32>
991 298..306 'y.foo2()': i64
993 312..320 'z.foo2()': i64
999 fn argument_impl_trait_type_args_1() {
1000 check_infer_with_mismatches(
1004 // this function has an implicit Self param, an explicit type param,
1005 // and an implicit impl Trait param!
1006 fn bar<T>(x: impl Trait) -> T { loop {} }
1008 fn foo<T>(x: impl Trait) -> T { loop {} }
1019 <F as Foo>::bar::<u32>(S);
1023 foo::<u32, i32>(S); // we should ignore the extraneous i32
1026 155..156 'x': impl Trait
1027 175..186 '{ loop {} }': T
1028 177..184 'loop {}': !
1030 199..200 'x': impl Trait
1031 219..230 '{ loop {} }': T
1032 221..228 'loop {}': !
1034 300..509 '{ ... i32 }': ()
1035 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1036 306..317 'Foo::bar(S)': {unknown}
1038 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1039 323..341 '<F as ...bar(S)': {unknown}
1041 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1042 347..356 'F::bar(S)': {unknown}
1044 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1045 362..380 'Foo::b...32>(S)': u32
1047 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1048 386..411 '<F as ...32>(S)': u32
1050 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1051 418..424 'foo(S)': {unknown}
1053 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1054 430..443 'foo::<u32>(S)': u32
1056 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1057 449..467 'foo::<...32>(S)': u32
1064 fn argument_impl_trait_type_args_2() {
1065 check_infer_with_mismatches(
1072 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1078 F::<u32>.foo::<i32>(S);
1079 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1083 93..94 'x': impl Trait
1084 118..129 '{ loop {} }': (T, U)
1085 120..127 'loop {}': !
1087 143..283 '{ ...ored }': ()
1088 149..150 'F': F<{unknown}>
1089 149..157 'F.foo(S)': ({unknown}, {unknown})
1091 163..171 'F::<u32>': F<u32>
1092 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1094 184..192 'F::<u32>': F<u32>
1095 184..206 'F::<u3...32>(S)': (u32, i32)
1097 212..220 'F::<u32>': F<u32>
1098 212..239 'F::<u3...32>(S)': (u32, i32)
1105 fn argument_impl_trait_to_fn_pointer() {
1106 check_infer_with_mismatches(
1109 fn foo(x: impl Trait) { loop {} }
1114 let f: fn(S) -> () = foo;
1117 22..23 'x': impl Trait
1118 37..48 '{ loop {} }': ()
1121 90..123 '{ ...foo; }': ()
1123 117..120 'foo': fn foo(S)
1134 fn foo2(&self) -> i64;
1136 fn bar() -> impl Trait<u64> {}
1138 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1150 29..33 'self': &Self
1151 54..58 'self': &Self
1153 110..111 'x': impl Trait<u64>
1154 130..131 'y': &impl Trait<u64>
1155 151..268 '{ ...2(); }': ()
1156 157..158 'x': impl Trait<u64>
1157 164..165 'y': &impl Trait<u64>
1158 175..176 'z': impl Trait<u64>
1159 179..182 'bar': fn bar() -> impl Trait<u64>
1160 179..184 'bar()': impl Trait<u64>
1161 190..191 'x': impl Trait<u64>
1162 190..197 'x.foo()': u64
1163 203..204 'y': &impl Trait<u64>
1164 203..210 'y.foo()': u64
1165 216..217 'z': impl Trait<u64>
1166 216..223 'z.foo()': u64
1167 229..230 'x': impl Trait<u64>
1168 229..237 'x.foo2()': i64
1169 243..244 'y': &impl Trait<u64>
1170 243..251 'y.foo2()': i64
1171 257..258 'z': impl Trait<u64>
1172 257..265 'z.foo2()': i64
1178 fn simple_return_pos_impl_trait() {
1179 cov_mark::check!(lower_rpit);
1185 fn bar() -> impl Trait<u64> { loop {} }
1192 29..33 'self': &Self
1193 71..82 '{ loop {} }': !
1196 94..129 '{ ...o(); }': ()
1197 104..105 'a': impl Trait<u64>
1198 108..111 'bar': fn bar() -> impl Trait<u64>
1199 108..113 'bar()': impl Trait<u64>
1200 119..120 'a': impl Trait<u64>
1201 119..126 'a.foo()': u64
1207 fn more_return_pos_impl_trait() {
1212 fn next(&mut self) -> Self::Item;
1217 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1218 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1224 let (c, d) = baz(1u128);
1229 49..53 'self': &mut Self
1230 101..105 'self': &Self
1231 184..195 '{ loop {} }': ({unknown}, {unknown})
1232 186..193 'loop {}': !
1235 268..279 '{ loop {} }': ({unknown}, {unknown})
1236 270..277 'loop {}': !
1238 291..413 '{ ...o(); }': ()
1239 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1240 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1241 305..306 'b': impl Trait<u64>
1242 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1243 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1244 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1245 321..329 'a.next()': impl Trait<u32>
1246 321..335 'a.next().foo()': u32
1247 341..342 'b': impl Trait<u64>
1248 341..348 'b.foo()': u64
1249 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1250 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1251 362..363 'd': impl Trait<u128>
1252 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1253 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1254 371..376 '1u128': u128
1255 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1256 383..391 'c.next()': impl Trait<u128>
1257 383..397 'c.next().foo()': u128
1258 403..404 'd': impl Trait<u128>
1259 403..410 'd.foo()': u128
1270 fn foo2(&self) -> i64;
1272 fn bar() -> dyn Trait<u64> {}
1274 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1286 29..33 'self': &Self
1287 54..58 'self': &Self
1289 109..110 'x': dyn Trait<u64>
1290 128..129 'y': &dyn Trait<u64>
1291 148..265 '{ ...2(); }': ()
1292 154..155 'x': dyn Trait<u64>
1293 161..162 'y': &dyn Trait<u64>
1294 172..173 'z': dyn Trait<u64>
1295 176..179 'bar': fn bar() -> dyn Trait<u64>
1296 176..181 'bar()': dyn Trait<u64>
1297 187..188 'x': dyn Trait<u64>
1298 187..194 'x.foo()': u64
1299 200..201 'y': &dyn Trait<u64>
1300 200..207 'y.foo()': u64
1301 213..214 'z': dyn Trait<u64>
1302 213..220 'z.foo()': u64
1303 226..227 'x': dyn Trait<u64>
1304 226..234 'x.foo2()': i64
1305 240..241 'y': &dyn Trait<u64>
1306 240..248 'y.foo2()': i64
1307 254..255 'z': dyn Trait<u64>
1308 254..262 'z.foo2()': i64
1314 fn dyn_trait_in_impl() {
1318 fn foo(&self) -> (T, U);
1321 impl<T, U> S<T, U> {
1322 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1324 trait Trait2<T, U> {
1325 fn baz(&self) -> (T, U);
1327 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1329 fn test(s: S<u32, i32>) {
1333 32..36 'self': &Self
1334 102..106 'self': &S<T, U>
1335 128..139 '{ loop {} }': &dyn Trait<T, U>
1336 130..137 'loop {}': !
1338 175..179 'self': &Self
1339 251..252 's': S<u32, i32>
1340 267..289 '{ ...z(); }': ()
1341 273..274 's': S<u32, i32>
1342 273..280 's.bar()': &dyn Trait<u32, i32>
1343 273..286 's.bar().baz()': (u32, i32)
1349 fn dyn_trait_bare() {
1353 fn foo(&self) -> u64;
1355 fn bar() -> Trait {}
1357 fn test(x: Trait, y: &Trait) -> u64 {
1366 26..30 'self': &Self
1368 72..73 'x': dyn Trait
1369 82..83 'y': &dyn Trait
1370 100..175 '{ ...o(); }': ()
1371 106..107 'x': dyn Trait
1372 113..114 'y': &dyn Trait
1373 124..125 'z': dyn Trait
1374 128..131 'bar': fn bar() -> dyn Trait
1375 128..133 'bar()': dyn Trait
1376 139..140 'x': dyn Trait
1377 139..146 'x.foo()': u64
1378 152..153 'y': &dyn Trait
1379 152..159 'y.foo()': u64
1380 165..166 'z': dyn Trait
1381 165..172 'z.foo()': u64
1392 a: impl Trait + 'lifetime,
1395 d: impl ('lifetime),
1397 f: impl Trait + ?Sized
1401 28..29 'a': impl Trait
1403 82..83 'c': impl Trait
1406 148..149 'f': impl Trait
1413 fn error_bound_chalk() {
1417 fn foo(&self) -> u32 {}
1420 fn test(x: (impl Trait + UnknownTrait)) {
1428 fn assoc_type_bindings() {
1435 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1436 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1437 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1440 impl<T> Trait for S<T> { type Type = T; }
1442 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1460 262..263 'y': impl Trait<Type = i64>
1461 289..397 '{ ...r>); }': ()
1462 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1463 295..301 'get(x)': u32
1465 307..311 'get2': fn get2<u32, T>(T) -> u32
1466 307..314 'get2(x)': u32
1468 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1469 320..326 'get(y)': i64
1470 324..325 'y': impl Trait<Type = i64>
1471 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1472 332..339 'get2(y)': i64
1473 337..338 'y': impl Trait<Type = i64>
1474 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1475 345..356 'get(set(S))': u64
1476 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1477 349..355 'set(S)': S<u64>
1478 353..354 'S': S<u64>
1479 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1480 362..374 'get2(set(S))': u64
1481 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1482 367..373 'set(S)': S<u64>
1483 371..372 'S': S<u64>
1484 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1485 380..394 'get2(S::<str>)': str
1486 385..393 'S::<str>': S<str>
1492 fn impl_trait_assoc_binding_projection_bug() {
1495 //- /main.rs crate:main deps:std
1496 pub trait Language {
1499 pub enum RustLanguage {}
1500 impl Language for RustLanguage {
1501 type Kind = SyntaxKind;
1503 struct SyntaxNode<L> {}
1504 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1507 fn clone(&self) -> Self;
1510 fn api_walkthrough() {
1516 //- /std.rs crate:std
1517 #[prelude_import] use iter::*;
1519 trait IntoIterator {
1525 impl<T: Iterator> IntoIterator for T {
1526 type Item = <T as Iterator>::Item;
1534 fn projection_eq_within_chalk() {
1543 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1545 fn test<T: Trait1<Type = u32>>(x: T) {
1551 169..185 '{ ...o(); }': ()
1553 175..182 'x.foo()': u32
1559 fn where_clause_trait_in_scope_for_method_resolution() {
1564 fn foo(&self) -> u32 {}
1568 fn test<T: foo::Trait>(x: T) {
1576 fn super_trait_method_resolution() {
1581 fn foo(&self) -> u32 {}
1584 trait Trait1: foo::SuperTrait {}
1585 trait Trait2 where Self: foo::SuperTrait {}
1587 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1592 49..53 'self': &Self
1596 193..222 '{ ...o(); }': ()
1598 199..206 'x.foo()': u32
1600 212..219 'y.foo()': u32
1606 fn super_trait_impl_trait_method_resolution() {
1611 fn foo(&self) -> u32 {}
1614 trait Trait1: foo::SuperTrait {}
1616 fn test(x: &impl Trait1) {
1620 49..53 'self': &Self
1622 115..116 'x': &impl Trait1
1623 132..148 '{ ...o(); }': ()
1624 138..139 'x': &impl Trait1
1625 138..145 'x.foo()': u32
1631 fn super_trait_cycle() {
1632 // This just needs to not crash
1638 fn test<T: A>(x: T) {
1644 49..65 '{ ...o(); }': ()
1646 55..62 'x.foo()': {unknown}
1652 fn super_trait_assoc_type_bounds() {
1655 trait SuperTrait { type Type; }
1656 trait Trait where Self: SuperTrait {}
1658 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1659 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1662 impl<T> SuperTrait for S<T> { type Type = T; }
1663 impl<T> Trait for S<T> {}
1674 258..279 '{ ...S)); }': ()
1675 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1676 264..276 'get2(set(S))': u64
1677 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1678 269..275 'set(S)': S<u64>
1679 273..274 'S': S<u64>
1686 check_infer_with_mismatches(
1688 trait FnOnce<Args> {
1691 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1694 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1695 f.call_once((1, 2));
1701 155..183 '{ ...2)); }': ()
1703 161..180 'f.call...1, 2))': u128
1704 173..179 '(1, 2)': (u32, u64)
1712 fn fn_ptr_and_item() {
1713 check_infer_with_mismatches(
1716 trait FnOnce<Args> {
1719 fn call_once(self, args: Args) -> Self::Output;
1728 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1729 fn foo(&self) -> (A1, R) { loop {} }
1732 enum Opt<T> { None, Some(T) }
1734 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1738 let bar: Bar<fn(u8) -> u32>;
1742 let f: fn(u8) -> u32;
1748 139..143 'self': &Self
1749 243..247 'self': &Bar<F>
1750 260..271 '{ loop {} }': (A1, R)
1751 262..269 'loop {}': !
1753 355..359 'self': Opt<T>
1755 377..388 '{ loop {} }': Opt<U>
1756 379..386 'loop {}': !
1758 402..518 '{ ...(f); }': ()
1759 412..415 'bar': Bar<fn(u8) -> u32>
1760 441..444 'bar': Bar<fn(u8) -> u32>
1761 441..450 'bar.foo()': (u8, u32)
1762 461..464 'opt': Opt<u8>
1763 483..484 'f': fn(u8) -> u32
1764 505..508 'opt': Opt<u8>
1765 505..515 'opt.map(f)': Opt<u32>
1766 513..514 'f': fn(u8) -> u32
1772 fn fn_trait_deref_with_ty_default() {
1779 fn deref(&self) -> &Self::Target;
1783 trait FnOnce<Args> {
1786 fn call_once(self, args: Args) -> Self::Output;
1792 fn foo(&self) -> usize {}
1795 struct Lazy<T, F = fn() -> T>(F);
1797 impl<T, F> Lazy<T, F> {
1798 pub fn new(f: F) -> Lazy<T, F> {}
1801 impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
1806 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1807 let r1 = lazy1.foo();
1809 fn make_foo_fn() -> Foo {}
1810 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1811 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1812 let r2 = lazy2.foo();
1815 64..68 'self': &Self
1816 165..169 'self': Self
1817 171..175 'args': Args
1818 239..243 'self': &Foo
1822 443..689 '{ ...o(); }': ()
1823 453..458 'lazy1': Lazy<Foo, || -> Foo>
1824 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1825 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1826 485..491 '|| Foo': || -> Foo
1828 502..504 'r1': usize
1829 507..512 'lazy1': Lazy<Foo, || -> Foo>
1830 507..518 'lazy1.foo()': usize
1831 560..575 'make_foo_fn_ptr': fn() -> Foo
1832 591..602 'make_foo_fn': fn make_foo_fn() -> Foo
1833 612..617 'lazy2': Lazy<Foo, fn() -> Foo>
1834 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1835 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1836 644..659 'make_foo_fn_ptr': fn() -> Foo
1837 670..672 'r2': usize
1838 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1839 675..686 'lazy2.foo()': usize
1847 check_infer_with_mismatches(
1850 enum Option<T> { Some(T), None }
1852 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1856 let x = Option::Some(1u32);
1859 let y: Option<i64> = x.map(|_v| 1);
1862 86..90 'self': Option<T>
1864 111..122 '{ loop {} }': Option<U>
1865 113..120 'loop {}': !
1867 136..255 '{ ... 1); }': ()
1868 146..147 'x': Option<u32>
1869 150..162 'Option::Some': Some<u32>(u32) -> Option<u32>
1870 150..168 'Option...(1u32)': Option<u32>
1871 163..167 '1u32': u32
1872 174..175 'x': Option<u32>
1873 174..190 'x.map(...v + 1)': Option<u32>
1874 180..189 '|v| v + 1': |u32| -> u32
1877 184..189 'v + 1': u32
1879 196..197 'x': Option<u32>
1880 196..212 'x.map(... 1u64)': Option<u64>
1881 202..211 '|_v| 1u64': |u32| -> u64
1883 207..211 '1u64': u64
1884 222..223 'y': Option<i64>
1885 239..240 'x': Option<u32>
1886 239..252 'x.map(|_v| 1)': Option<i64>
1887 245..251 '|_v| 1': |u32| -> i64
1896 check_infer_with_mismatches(
1899 pub trait Add<Rhs = Self> {
1901 fn add(self, rhs: Rhs) -> Self::Output;
1904 trait FnOnce<Args> {
1910 fn add(self, rhs: u64) -> Self::Output {0}
1915 fn add(self, rhs: u128) -> Self::Output {0}
1918 fn test<F: FnOnce(u32) -> u64>(f: F) {
1922 let h = |v| 1u128 + v;
1927 203..207 'self': u64
1931 297..301 'self': u128
1932 303..306 'rhs': u128
1933 330..333 '{0}': u128
1936 374..450 '{ ...+ v; }': ()
1938 380..384 'f(1)': {unknown}
1940 394..395 'g': |u64| -> u64
1941 398..407 '|v| v + 1': |u64| -> u64
1944 402..407 'v + 1': u64
1946 413..414 'g': |u64| -> u64
1947 413..420 'g(1u64)': u64
1948 415..419 '1u64': u64
1949 430..431 'h': |u128| -> u128
1950 434..447 '|v| 1u128 + v': |u128| -> u128
1952 438..443 '1u128': u128
1953 438..447 '1u128 + v': u128
1960 fn closure_as_argument_inference_order() {
1961 check_infer_with_mismatches(
1964 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
1965 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
1969 fn method(self) -> u64;
1971 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
1972 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
1976 let x1 = foo1(S, |s| s.method());
1977 let x2 = foo2(|s| s.method(), S);
1978 let x3 = S.foo1(S, |s| s.method());
1979 let x4 = S.foo2(|s| s.method(), S);
1984 50..61 '{ loop {} }': U
1989 112..123 '{ loop {} }': U
1990 114..121 'loop {}': !
1996 233..244 '{ loop {} }': U
1997 235..242 'loop {}': !
2002 305..316 '{ loop {} }': U
2003 307..314 'loop {}': !
2005 330..489 '{ ... S); }': ()
2007 345..349 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2008 345..368 'foo1(S...hod())': u64
2010 353..367 '|s| s.method()': |S| -> u64
2013 357..367 's.method()': u64
2015 383..387 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2016 383..406 'foo2(|...(), S)': u64
2017 388..402 '|s| s.method()': |S| -> u64
2020 392..402 's.method()': u64
2024 421..446 'S.foo1...hod())': u64
2026 431..445 '|s| s.method()': |S| -> u64
2029 435..445 's.method()': u64
2032 461..486 'S.foo2...(), S)': u64
2033 468..482 '|s| s.method()': |S| -> u64
2036 472..482 's.method()': u64
2043 fn fn_item_fn_trait() {
2051 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2055 } //^^^^^^^^^^^^^^^^^^ S
2061 fn unselected_projection_in_trait_env_1() {
2070 fn foo(&self) -> u32;
2073 fn test<T: Trait>() where T::Item: Trait2 {
2074 let x: T::Item = no_matter;
2082 fn unselected_projection_in_trait_env_2() {
2090 fn foo(&self) -> u32;
2093 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2094 let x: T::Item = no_matter;
2102 fn unselected_projection_on_impl_self() {
2109 fn f(&self, x: Self::Item);
2116 fn f(&self, x: Self::Item) { let y = x; }
2123 fn f(&self, x: <Self>::Item) { let y = x; }
2126 40..44 'self': &Self
2127 46..47 'x': Trait::Item<Self>
2130 147..161 '{ let y = x; }': ()
2133 228..232 'self': &S2
2135 251..265 '{ let y = x; }': ()
2143 fn unselected_projection_on_trait_self() {
2149 fn f(&self) -> Self::Item { loop {} }
2165 fn unselected_projection_chalk_fold() {
2169 trait Fold<I: Interner, TI = I> {
2173 struct Ty<I: Interner> {}
2174 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2175 type Result = Ty<TI>;
2178 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2185 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2193 fn trait_impl_self_ty() {
2202 impl Trait<Self> for S {}
2212 fn trait_impl_self_ty_cycle() {
2221 impl Trait for S<Self> {}
2231 fn unselected_projection_in_trait_env_cycle_1() {
2232 // this is a legitimate cycle
2241 fn test<T: Trait>() where T: Trait2<T::Item> {
2242 let x: T::Item = no_matter;
2249 fn unselected_projection_in_trait_env_cycle_2() {
2250 // this is a legitimate cycle
2258 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2259 let x: T::Item = no_matter;
2266 fn unselected_projection_in_trait_env_cycle_3() {
2267 // this is a cycle for rustc; we currently accept it
2276 fn test<T>() where T: Trait<OtherItem = T::Item> {
2277 let x: T::Item = no_matter;
2278 } //^ Trait::Item<T>
2284 fn unselected_projection_in_trait_env_no_cycle() {
2285 // this is not a cycle
2293 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2295 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2298 fn len(&self) -> usize;
2301 pub trait UnificationStoreMut: UnificationStoreBase {
2302 fn push(&mut self, value: Self::Key);
2305 fn test<T>(t: T) where T: UnificationStoreMut {
2310 } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2316 fn inline_assoc_type_bounds_1() {
2322 trait OtherTrait<T> {
2326 // workaround for Chalk assoc type normalization problems
2328 impl<T: Iterator> Iterator for S<T> {
2329 type Item = <T as Iterator>::Item;
2332 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2333 let x: <S<I> as Iterator>::Item;
2341 fn inline_assoc_type_bounds_2() {
2348 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2349 let x: <<I as Iterator>::Item as Iterator>::Item;
2357 fn proc_macro_server_types() {
2360 macro_rules! with_api {
2361 ($S:ident, $self:ident, $m:ident) => {
2364 fn new() -> $S::TokenStream;
2371 macro_rules! associated_item {
2372 (type TokenStream) =>
2373 (type TokenStream: 'static;);
2375 (type Group: 'static;);
2376 ($($item:tt)*) => ($($item)*;)
2378 macro_rules! declare_server_traits {
2380 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2383 $(associated_item!(type $name);)*
2386 $(pub trait $name: Types {
2387 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2390 pub trait Server: Types $(+ $name)* {}
2391 impl<S: Types $(+ $name)*> Server for S {}
2395 with_api!(Self, self_, declare_server_traits);
2399 impl Types for Rustc {
2400 type TokenStream = T;
2404 fn make<T>() -> T { loop {} }
2405 impl TokenStream for Rustc {
2406 fn new() -> Self::TokenStream {
2407 let group: Self::Group = make();
2412 1061..1072 '{ loop {} }': T
2413 1063..1070 'loop {}': !
2415 1136..1199 '{ ... }': T
2416 1150..1155 'group': G
2417 1171..1175 'make': fn make<G>() -> G
2418 1171..1177 'make()': G
2419 1187..1191 'make': fn make<T>() -> T
2420 1187..1193 'make()': T
2426 fn unify_impl_trait() {
2427 check_infer_with_mismatches(
2431 fn foo(x: impl Trait<u32>) { loop {} }
2432 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2435 impl<T> Trait<T> for S<T> {}
2437 fn default<T>() -> T { loop {} }
2439 fn test() -> impl Trait<i32> {
2440 let s1 = S(default());
2442 let x: i32 = bar(S(default()));
2446 26..27 'x': impl Trait<u32>
2447 46..57 '{ loop {} }': ()
2450 68..69 'x': impl Trait<T>
2451 91..102 '{ loop {} }': T
2452 93..100 'loop {}': !
2454 171..182 '{ loop {} }': T
2455 173..180 'loop {}': !
2457 213..309 '{ ...t()) }': S<{unknown}>
2458 223..225 's1': S<u32>
2459 228..229 'S': S<u32>(u32) -> S<u32>
2460 228..240 'S(default())': S<u32>
2461 230..237 'default': fn default<u32>() -> u32
2462 230..239 'default()': u32
2463 246..249 'foo': fn foo(S<u32>)
2464 246..253 'foo(s1)': ()
2465 250..252 's1': S<u32>
2467 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2468 272..289 'bar(S(...lt()))': i32
2469 276..277 'S': S<i32>(i32) -> S<i32>
2470 276..288 'S(default())': S<i32>
2471 278..285 'default': fn default<i32>() -> i32
2472 278..287 'default()': i32
2473 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2474 295..307 'S(default())': S<{unknown}>
2475 297..304 'default': fn default<{unknown}>() -> {unknown}
2476 297..306 'default()': {unknown}
2482 fn assoc_types_from_bounds() {
2501 f::<(), _>(|z| { z; });
2506 132..163 '{ ... }); }': ()
2507 138..148 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2508 138..160 'f::<()... z; })': ()
2509 149..159 '|z| { z; }': |&()| -> ()
2511 153..159 '{ z; }': ()
2518 fn associated_type_bound() {
2522 type Item: OtherTrait<u32>;
2524 pub trait OtherTrait<T> {
2528 // this is just a workaround for chalk#234
2530 impl<T: Trait> Trait for S<T> {
2531 type Item = <T as Trait>::Item;
2534 fn test<T: Trait>() {
2535 let y: <S<T> as Trait>::Item = no_matter;
2543 fn dyn_trait_through_chalk() {
2548 impl<T> core::ops::Deref for Box<T> {
2555 fn test(x: Box<dyn Trait>) {
2563 fn string_to_owned() {
2569 fn to_owned(&self) -> Self::Owned;
2571 impl ToOwned for str {
2572 type Owned = String;
2582 fn iterator_chain() {
2583 check_infer_with_mismatches(
2585 //- minicore: fn, option
2586 pub trait Iterator {
2589 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2591 F: FnMut(Self::Item) -> Option<B>,
2594 fn for_each<F>(self, f: F)
2596 F: FnMut(Self::Item),
2600 pub trait IntoIterator {
2602 type IntoIter: Iterator<Item = Self::Item>;
2603 fn into_iter(self) -> Self::IntoIter;
2606 pub struct FilterMap<I, F> { }
2607 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2609 F: FnMut(I::Item) -> Option<B>,
2614 #[stable(feature = "rust1", since = "1.0.0")]
2615 impl<I: Iterator> IntoIterator for I {
2616 type Item = I::Item;
2619 fn into_iter(self) -> I {
2626 fn new() -> Self { loop {} }
2629 impl<T> IntoIterator for Vec<T> {
2631 type IntoIter = IntoIter<T>;
2634 pub struct IntoIter<T> { }
2635 impl<T> Iterator for IntoIter<T> {
2640 Vec::<i32>::new().into_iter()
2641 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2642 .for_each(|y| { y; });
2647 152..163 '{ loop {} }': FilterMap<Self, F>
2648 154..161 'loop {}': !
2650 184..188 'self': Self
2652 240..251 '{ loop {} }': ()
2653 242..249 'loop {}': !
2655 360..364 'self': Self
2657 700..720 '{ ... }': I
2659 779..790 '{ loop {} }': Vec<T>
2660 781..788 'loop {}': !
2662 977..1104 '{ ... }); }': ()
2663 983..998 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2664 983..1000 'Vec::<...:new()': Vec<i32>
2665 983..1012 'Vec::<...iter()': IntoIter<i32>
2666 983..1075 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2667 983..1101 'Vec::<... y; })': ()
2668 1029..1074 '|x| if...None }': |i32| -> Option<u32>
2670 1033..1074 'if x >...None }': Option<u32>
2672 1036..1041 'x > 0': bool
2674 1042..1060 '{ Some...u32) }': Option<u32>
2675 1044..1048 'Some': Some<u32>(u32) -> Option<u32>
2676 1044..1058 'Some(x as u32)': Option<u32>
2678 1049..1057 'x as u32': u32
2679 1066..1074 '{ None }': Option<u32>
2680 1068..1072 'None': Option<u32>
2681 1090..1100 '|y| { y; }': |u32| -> ()
2683 1094..1100 '{ y; }': ()
2706 fn foo() -> Self::Output;
2710 type Output = T::OutputA;
2711 fn foo() -> Self::Output { loop {} }
2722 fn trait_object_no_coercion() {
2723 check_infer_with_mismatches(
2727 fn foo(x: &dyn Foo) {}
2729 fn test(x: &dyn Foo) {
2733 21..22 'x': &dyn Foo
2735 46..47 'x': &dyn Foo
2736 59..74 '{ foo(x); }': ()
2737 65..68 'foo': fn foo(&dyn Foo)
2739 69..70 'x': &dyn Foo
2746 check_infer_with_mismatches(
2752 impl Copy for IsCopy {}
2755 trait Test { fn test(&self) -> bool; }
2756 impl<T: Copy> Test for T {}
2761 (IsCopy, IsCopy).test();
2762 (IsCopy, NotCopy).test();
2765 110..114 'self': &Self
2766 166..267 '{ ...t(); }': ()
2767 172..178 'IsCopy': IsCopy
2768 172..185 'IsCopy.test()': bool
2769 191..198 'NotCopy': NotCopy
2770 191..205 'NotCopy.test()': {unknown}
2771 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy)
2772 211..234 '(IsCop...test()': bool
2773 212..218 'IsCopy': IsCopy
2774 220..226 'IsCopy': IsCopy
2775 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy)
2776 240..264 '(IsCop...test()': {unknown}
2777 241..247 'IsCopy': IsCopy
2778 249..256 'NotCopy': NotCopy
2784 fn builtin_fn_def_copy() {
2785 check_infer_with_mismatches(
2791 fn bar<T: Copy>(T) -> T {}
2792 struct Struct(usize);
2793 enum Enum { Variant(usize) }
2795 trait Test { fn test(&self) -> bool; }
2796 impl<T: Copy> Test for T {}
2802 Enum::Variant.test();
2806 60..61 'T': {unknown}
2808 68..70: expected T, got ()
2809 145..149 'self': &Self
2810 201..281 '{ ...t(); }': ()
2811 207..210 'foo': fn foo()
2812 207..217 'foo.test()': bool
2813 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2814 223..233 'bar.test()': bool
2815 239..245 'Struct': Struct(usize) -> Struct
2816 239..252 'Struct.test()': bool
2817 258..271 'Enum::Variant': Variant(usize) -> Enum
2818 258..278 'Enum::...test()': bool
2824 fn builtin_fn_ptr_copy() {
2825 check_infer_with_mismatches(
2830 trait Test { fn test(&self) -> bool; }
2831 impl<T: Copy> Test for T {}
2833 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2839 54..58 'self': &Self
2841 118..120 'f2': fn(usize) -> u8
2842 139..141 'f3': fn(u8, u8) -> &u8
2843 162..210 '{ ...t(); }': ()
2845 168..177 'f1.test()': bool
2846 183..185 'f2': fn(usize) -> u8
2847 183..192 'f2.test()': bool
2848 198..200 'f3': fn(u8, u8) -> &u8
2849 198..207 'f3.test()': bool
2855 fn builtin_sized() {
2856 check_infer_with_mismatches(
2861 trait Test { fn test(&self) -> bool; }
2862 impl<T: Sized> Test for T {}
2866 (*"foo").test(); // not Sized
2868 (1u8, *"foo").test(); // not Sized
2871 56..60 'self': &Self
2872 113..228 '{ ...ized }': ()
2874 119..129 '1u8.test()': bool
2875 135..150 '(*"foo").test()': {unknown}
2876 136..142 '*"foo"': str
2877 137..142 '"foo"': &str
2878 169..179 '(1u8, 1u8)': (u8, u8)
2879 169..186 '(1u8, ...test()': bool
2882 192..205 '(1u8, *"foo")': (u8, str)
2883 192..212 '(1u8, ...test()': {unknown}
2885 198..204 '*"foo"': str
2886 199..204 '"foo"': &str
2892 fn integer_range_iterate() {
2895 //- /main.rs crate:main deps:core
2897 for x in 0..100 { x; }
2900 //- /core.rs crate:core
2902 pub struct Range<Idx> {
2909 pub trait Iterator {
2913 pub trait IntoIterator {
2915 type IntoIter: Iterator<Item = Self::Item>;
2918 impl<T> IntoIterator for T where T: Iterator {
2919 type Item = <T as Iterator>::Item;
2920 type IntoIter = Self;
2925 impl Step for i32 {}
2926 impl Step for i64 {}
2928 impl<A: Step> iter::Iterator for ops::Range<A> {
2936 fn infer_closure_arg() {
2947 let s = Option::None;
2948 let f = |x: Option<i32>| {};
2952 52..126 '{ ...)(s) }': ()
2953 62..63 's': Option<i32>
2954 66..78 'Option::None': Option<i32>
2955 88..89 'f': |Option<i32>| -> ()
2956 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
2957 93..94 'x': Option<i32>
2959 117..124 '(&f)(s)': ()
2960 118..120 '&f': &|Option<i32>| -> ()
2961 119..120 'f': |Option<i32>| -> ()
2962 122..123 's': Option<i32>
2968 fn infer_fn_trait_arg() {
2969 check_infer_with_mismatches(
2971 //- minicore: fn, option
2972 fn foo<F, T>(f: F) -> T
2974 F: Fn(Option<i32>) -> T,
2982 59..89 '{ ...f(s) }': T
2983 69..70 's': Option<i32>
2984 73..77 'None': Option<i32>
2987 85..86 's': Option<i32>
2993 fn infer_box_fn_arg() {
2994 // The type mismatch is because we don't define Unsize and CoerceUnsized
2995 check_infer_with_mismatches(
2997 //- /lib.rs deps:std
3000 pub trait FnOnce<Args> {
3003 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3008 type Target: ?Sized;
3010 fn deref(&self) -> &Self::Target;
3013 #[lang = "owned_box"]
3014 pub struct Box<T: ?Sized> {
3018 impl<T: ?Sized> Deref for Box<T> {
3021 fn deref(&self) -> &T {
3032 let s = Option::None;
3033 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3037 100..104 'self': Self
3038 106..110 'args': Args
3039 214..218 'self': &Self
3040 384..388 'self': &Box<T>
3041 396..423 '{ ... }': &T
3042 406..417 '&self.inner': &*mut T
3043 407..411 'self': &Box<T>
3044 407..417 'self.inner': *mut T
3045 478..576 '{ ...&s); }': ()
3046 488..489 's': Option<i32>
3047 492..504 'Option::None': Option<i32>
3048 514..515 'f': Box<dyn FnOnce(&Option<i32>)>
3049 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3050 554..561 '|ps| {}': |{unknown}| -> ()
3051 555..557 'ps': {unknown}
3053 568..569 'f': Box<dyn FnOnce(&Option<i32>)>
3054 568..573 'f(&s)': ()
3055 570..572 '&s': &Option<i32>
3056 571..572 's': Option<i32>
3057 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
3063 fn infer_dyn_fn_output() {
3068 let f: &dyn Fn() -> i32;
3076 fn infer_dyn_fn_once_output() {
3081 let f: dyn FnOnce() -> i32;
3089 fn variable_kinds_1() {
3092 trait Trait<T> { fn get(self, t: T) -> T; }
3094 impl Trait<u128> for S {}
3095 impl Trait<f32> for S {}
3107 fn variable_kinds_2() {
3110 trait Trait { fn get(self) -> Self; }
3111 impl Trait for u128 {}
3112 impl Trait for f32 {}
3124 fn underscore_import() {
3129 fn method(&self) -> u8 { 0 }
3134 impl crate::tr::Tr for Tr {}
3136 use crate::tr::Tr as _;
3151 fn method(&self) -> u8 { 0 }
3168 fn trait_in_scope_with_inner_item() {
3173 fn method(&self) -> u8 { 0 }
3188 46..50 'self': &Self
3191 115..185 '{ ... } }': ()
3192 132..183 '{ ... }': ()
3194 142..153 '().method()': u8
3200 fn inner_use_in_block() {
3205 fn method(&self) -> u8 { 0 }
3221 //^^^^^^^^^^^ {unknown}
3225 //^^^^^^^^^^^ {unknown}
3232 fn nested_inner_function_calling_self() {
3242 17..73 '{ ... } }': ()
3243 39..71 '{ ... }': ()
3245 57..62 'inner': fn inner() -> S
3252 fn infer_default_trait_type_parameter() {
3257 trait Op<RHS=Self> {
3260 fn do_op(self, rhs: RHS) -> Self::Output;
3266 fn do_op(self, rhs: Self) -> Self::Output {
3281 186..206 '{ ... }': bool
3282 196..200 'true': bool
3283 220..277 '{ ...(y); }': ()
3290 264..274 'x.do_op(y)': bool
3297 fn qualified_path_as_qualified_trait() {
3307 fn boo() -> Self::Output {
3314 impl foo::Foo for F {
3317 impl foo::Bar for F {
3318 type Output = <F as foo::Foo>::Target;
3323 let x = <F as Bar>::boo();
3326 132..163 '{ ... }': Bar::Output<Self>
3327 146..153 'loop {}': !
3329 306..358 '{ ...o(); }': ()
3331 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3332 338..355 '<F as ...:boo()': ()
3338 fn renamed_extern_crate_in_block() {
3341 //- /lib.rs crate:lib deps:serde
3342 use serde::Deserialize;
3347 extern crate serde as _serde;
3348 impl _serde::Deserialize for Foo {
3349 fn deserialize() -> u8 { 0 }
3355 //^^^^^^^^^^^^^^^^^^ u8
3358 //- /serde.rs crate:serde
3360 pub trait Deserialize {
3361 fn deserialize() -> u8;
3367 fn bin_op_adt_with_rhs_primitive() {
3368 check_infer_with_mismatches(
3371 pub trait Add<Rhs = Self> {
3373 fn add(self, rhs: Rhs) -> Self::Output;
3376 struct Wrapper(u32);
3377 impl Add<u32> for Wrapper {
3379 fn add(self, rhs: u32) -> Wrapper {
3384 let wrapped = Wrapper(10);
3386 let res = wrapped + num;
3392 192..196 'self': Wrapper
3394 219..247 '{ ... }': Wrapper
3395 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3396 229..241 'Wrapper(rhs)': Wrapper
3398 259..345 '{ ...um; }': ()
3399 269..276 'wrapped': Wrapper
3400 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3401 279..290 'Wrapper(10)': Wrapper
3405 322..325 'res': Wrapper
3406 328..335 'wrapped': Wrapper
3407 328..341 'wrapped + num': Wrapper
3419 fn do_thing(&self) -> Self::Output;
3422 impl T for [u8; 4] {
3423 type Output = usize;
3424 fn do_thing(&self) -> Self::Output {
3429 impl T for [u8; 2] {
3431 fn do_thing(&self) -> Self::Output {
3438 let v2 = v.do_thing();
3440 let v4 = v3.do_thing();
3444 44..48 'self': &Self
3445 133..137 'self': &[u8; 4]
3446 155..172 '{ ... }': usize
3448 236..240 'self': &[u8; 2]
3449 258..275 '{ ... }': u8
3451 289..392 '{ ...g(); }': ()
3452 299..300 'v': [u8; 2]
3453 303..311 '[0u8; 2]': [u8; 2]
3457 326..327 'v': [u8; 2]
3458 326..338 'v.do_thing()': u8
3459 348..350 'v3': [u8; 4]
3460 353..361 '[0u8; 4]': [u8; 4]
3463 371..373 'v4': usize
3464 376..378 'v3': [u8; 4]
3465 376..389 'v3.do_thing()': usize
3470 // FIXME: We should infer the length of the returned array :)
3472 fn const_generics() {
3477 fn do_thing(&self) -> Self::Output;
3480 impl<const L: usize> T for [u8; L] {
3481 type Output = [u8; L];
3482 fn do_thing(&self) -> Self::Output {
3489 let v2 = v.do_thing();
3493 44..48 'self': &Self
3494 151..155 'self': &[u8; _]
3495 173..194 '{ ... }': [u8; _]
3496 183..188 '*self': [u8; _]
3497 184..188 'self': &[u8; _]
3498 208..260 '{ ...g(); }': ()
3499 218..219 'v': [u8; 2]
3500 222..230 '[0u8; 2]': [u8; 2]
3503 240..242 'v2': [u8; _]
3504 245..246 'v': [u8; 2]
3505 245..257 'v.do_thing()': [u8; _]
3511 fn fn_returning_unit() {
3512 check_infer_with_mismatches(
3515 fn test<F: FnOnce()>(f: F) {
3520 27..51 '{ ...f(); }': ()
3529 fn trait_in_scope_of_trait_impl() {
3535 fn bar(self) -> usize { 0 }
3538 impl foo::Foo for u32 {
3540 let _x = self.bar();
3547 82..87 '{ 0 }': usize
3549 131..135 'self': u32
3550 137..173 '{ ... }': ()
3551 151..153 '_x': usize
3552 156..160 'self': u32
3553 156..166 'self.bar()': usize
3559 fn infer_async_ret_type() {
3562 //- minicore: future, result
3566 fn collect<B: Convert>(self) -> B {
3574 impl Convert for u32 {
3580 async fn get_accounts() -> Result<u32, ()> {
3581 let ret = Fooey.collect();
3599 impl Trait<u32> for S {
3620 impl Trait<u32> for S {
3644 impl Trait<S1> for S2 {
3645 fn foo(&self) { S1 }