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
23 #[prelude_import] use future::*;
25 #[lang = "future_trait"]
38 //- /main.rs crate:main deps:core
39 async fn foo() -> u64 {
49 //- /core.rs crate:core
50 #[prelude_import] use future::*;
52 #[lang = "future_trait"]
62 fn infer_desugar_async() {
65 //- /main.rs crate:main deps:core
66 async fn foo() -> u64 {
73 } //^ impl Future<Output = u64>
75 //- /core.rs crate:core
76 #[prelude_import] use future::*;
88 fn infer_async_block() {
91 //- /main.rs crate:main deps:core
95 // ^ impl Future<Output = i32>
99 let b = async {}.await;
103 let y = Option::None;
107 let _: Option<u64> = c.await;
109 // ^ impl Future<Output = Option<u64>>
112 enum Option<T> { None, Some(T) }
114 //- /core.rs crate:core
115 #[prelude_import] use future::*;
117 #[lang = "future_trait"]
131 //- /main.rs crate:main deps:core
133 let r: Result<i32, u64> = Result::Ok(1);
138 //- /core.rs crate:core
139 #[prelude_import] use ops::*;
147 #[prelude_import] use result::*;
154 impl<O, E> crate::ops::Try for Result<O, E> {
164 fn infer_for_loop() {
167 //- /main.rs crate:main deps:core,alloc
168 use alloc::collections::Vec;
178 //- /core.rs crate:core
179 #[prelude_import] use iter::*;
186 //- /alloc.rs crate:alloc deps:core
190 pub fn new() -> Self { Vec {} }
191 pub fn push(&mut self, t: T) { }
194 impl<T> IntoIterator for Vec<T> {
206 //- /main.rs crate:main deps:std
210 impl std::ops::Neg for Bar {
220 //- /std.rs crate:std
221 #[prelude_import] use ops::*;
236 //- /main.rs crate:main deps:std
240 impl std::ops::Not for Bar {
250 //- /std.rs crate:std
251 #[prelude_import] use ops::*;
263 fn infer_from_bound_1() {
268 impl<U> Trait<U> for S<U> {}
269 fn foo<T: Trait<u32>>(t: T) {}
277 104..143 '{ ...(s); }': ()
279 118..119 'S': S<u32>(u32) -> S<u32>
280 118..128 'S(unknown)': S<u32>
281 120..127 'unknown': u32
282 134..137 'foo': fn foo<S<u32>>(S<u32>)
283 134..140 'foo(s)': ()
290 fn infer_from_bound_2() {
295 impl<U> Trait<U> for S<U> {}
296 fn foo<U, T: Trait<U>>(t: T) -> U {}
304 110..162 '{ ...(s); }': ()
306 124..125 'S': S<u32>(u32) -> S<u32>
307 124..134 'S(unknown)': S<u32>
308 126..133 'unknown': u32
310 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32
311 153..159 'foo(s)': u32
318 fn trait_default_method_self_bound_implements_trait() {
319 cov_mark::check!(trait_self_implements_self);
323 fn foo(&self) -> i64;
334 79..89 'self.foo()': i64
340 fn trait_default_method_self_bound_implements_super_trait() {
344 fn foo(&self) -> i64;
346 trait Trait: SuperTrait {
354 94..129 '{ ... }': ()
356 112..116 'self': &Self
357 112..122 'self.foo()': i64
363 fn infer_project_associated_type() {
370 impl Iterable for S { type Item = u32; }
371 fn test<T: Iterable>() {
372 let x: <S as Iterable>::Item = 1;
373 let y: <T as Iterable>::Item = no_matter;
374 let z: T::Item = no_matter;
375 let a: <T>::Item = no_matter;
378 108..261 '{ ...ter; }': ()
381 156..157 'y': Iterable::Item<T>
382 183..192 'no_matter': Iterable::Item<T>
383 202..203 'z': Iterable::Item<T>
384 215..224 'no_matter': Iterable::Item<T>
385 234..235 'a': Iterable::Item<T>
386 249..258 'no_matter': Iterable::Item<T>
392 fn infer_return_associated_type() {
399 impl Iterable for S { type Item = u32; }
400 fn foo1<T: Iterable>(t: T) -> T::Item {}
401 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {}
402 fn foo3<T: Iterable>(t: T) -> <T>::Item {}
415 234..300 '{ ...(S); }': ()
417 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item
418 248..255 'foo1(S)': u32
421 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item
422 269..276 'foo2(S)': u32
425 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item
426 290..297 'foo3(S)': u32
433 fn infer_associated_type_bound() {
439 fn test<T: Iterable<Item=u32>>() {
440 let y: T::Item = unknown;
443 67..100 '{ ...own; }': ()
445 90..97 'unknown': u32
451 fn infer_const_body() {
454 const A: u32 = 1 + 1;
455 static B: u64 = { let x = 1; x };"#,
460 38..54 '{ let ...1; x }': u64
469 fn tuple_struct_fields() {
479 37..86 '{ ... a.1 }': u64
481 51..52 'S': S(i32, u64) -> S
495 fn tuple_struct_with_fn() {
498 struct S(fn(u32) -> u64);
505 43..101 '{ ...0(2) }': u64
507 57..58 'S': S(fn(u32) -> u64) -> S
508 57..67 'S(|i| 2*i)': S
509 59..66 '|i| 2*i': |u32| -> u64
516 81..84 'a.0': fn(u32) -> u64
520 93..96 'a.0': fn(u32) -> u64
528 fn indexing_arrays() {
530 "fn main() { &mut [9][2]; }",
532 10..26 '{ &mut...[2]; }': ()
533 12..23 '&mut [9][2]': &mut {unknown}
534 17..20 '[9]': [i32; _]
535 17..23 '[9][2]': {unknown}
543 fn infer_ops_index() {
546 //- /main.rs crate:main deps:std
550 impl std::ops::Index<u32> for Bar {
560 //- /std.rs crate:std
561 #[prelude_import] use ops::*;
564 pub trait Index<Idx> {
573 fn infer_ops_index_int() {
576 //- /main.rs crate:main deps:std
580 impl std::ops::Index<u32> for Bar {
585 impl std::ops::Index<Range> for Bar {
596 //- /std.rs crate:std
597 #[prelude_import] use ops::*;
600 pub trait Index<Idx> {
609 fn infer_ops_index_autoderef() {
612 //- /main.rs crate:main deps:std
614 let a = &[1u32, 2, 3];
619 //- /std.rs crate:std
620 impl<T> ops::Index<u32> for [T] {
624 #[prelude_import] use ops::*;
627 pub trait Index<Idx> {
642 fn deref(&self) -> &Self::Target;
646 impl<T> Deref for Arc<T> {
652 fn foo(&self) -> u128 {}
663 fn deref_trait_with_inference_var() {
670 fn deref(&self) -> &Self::Target;
674 fn new_arc<T>() -> Arc<T> {}
675 impl<T> Deref for Arc<T> {
693 fn deref_trait_infinite_recursion() {
699 fn deref(&self) -> &Self::Target;
716 fn deref_trait_with_question_mark_size() {
722 fn deref(&self) -> &Self::Target;
726 impl<T> Deref for Arc<T> {
732 fn foo(&self) -> u128 {}
743 fn obligation_from_function_clause() {
749 impl Trait<u32> for S {}
751 fn foo<T: Trait<U>, U>(t: T) -> U {}
761 fn obligation_from_method_clause() {
768 impl Trait<isize> for S {}
772 fn foo<T: Trait<U>, U>(&self, t: T) -> U {}
783 fn obligation_from_self_method_clause() {
789 impl Trait<i64> for S {}
792 fn foo<U>(&self) -> U where Self: Trait<U> {}
803 fn obligation_from_impl_clause() {
809 impl Trait<&str> for S {}
812 impl<U, T: Trait<U>> O<T> {
813 fn foo(&self) -> U {}
824 fn generic_param_env_1() {
828 trait Trait { fn foo(self) -> u128; }
831 impl<T> Trait for T where T: Clone {}
832 fn test<T: Clone>(t: T) { t.foo(); }
839 fn generic_param_env_1_not_met() {
844 trait Trait { fn foo(self) -> u128; }
847 impl<T> Trait for T where T: Clone {}
848 fn test<T>(t: T) { t.foo(); }
855 fn generic_param_env_2() {
858 trait Trait { fn foo(self) -> u128; }
861 fn test<T: Trait>(t: T) { t.foo(); }
868 fn generic_param_env_2_not_met() {
871 trait Trait { fn foo(self) -> u128; }
874 fn test<T>(t: T) { t.foo(); }
881 fn generic_param_env_deref() {
889 impl<T> Deref for T where T: Trait {
892 fn test<T: Trait>(t: T) { (*t); }
899 fn associated_type_placeholder() {
900 // 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].
907 pub struct RefMutL<T>;
909 impl<T> ApplyL for RefMutL<T> {
910 type Out = <T as ApplyL>::Out;
913 fn test<T: ApplyL>() {
914 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
922 fn associated_type_placeholder_2() {
928 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
930 fn test<T: ApplyL>(t: T) {
939 fn argument_impl_trait() {
940 check_infer_with_mismatches(
944 fn foo2(&self) -> i64;
946 fn bar(x: impl Trait<u16>) {}
948 impl<T> Trait<T> for S<T> {}
950 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
965 77..78 'x': impl Trait<u16>
967 154..155 'x': impl Trait<u64>
968 174..175 'y': &impl Trait<u32>
969 195..323 '{ ...2(); }': ()
970 201..202 'x': impl Trait<u64>
971 208..209 'y': &impl Trait<u32>
973 223..224 'S': S<u16>(u16) -> S<u16>
974 223..227 'S(1)': S<u16>
976 233..236 'bar': fn bar(S<u16>)
977 233..239 'bar(z)': ()
979 245..246 'x': impl Trait<u64>
980 245..252 'x.foo()': u64
981 258..259 'y': &impl Trait<u32>
982 258..265 'y.foo()': u32
984 271..278 'z.foo()': u16
985 284..285 'x': impl Trait<u64>
986 284..292 'x.foo2()': i64
987 298..299 'y': &impl Trait<u32>
988 298..306 'y.foo2()': i64
990 312..320 'z.foo2()': i64
996 fn argument_impl_trait_type_args_1() {
997 check_infer_with_mismatches(
1001 // this function has an implicit Self param, an explicit type param,
1002 // and an implicit impl Trait param!
1003 fn bar<T>(x: impl Trait) -> T { loop {} }
1005 fn foo<T>(x: impl Trait) -> T { loop {} }
1016 <F as Foo>::bar::<u32>(S);
1020 foo::<u32, i32>(S); // we should ignore the extraneous i32
1023 155..156 'x': impl Trait
1024 175..186 '{ loop {} }': T
1025 177..184 'loop {}': !
1027 199..200 'x': impl Trait
1028 219..230 '{ loop {} }': T
1029 221..228 'loop {}': !
1031 300..509 '{ ... i32 }': ()
1032 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1033 306..317 'Foo::bar(S)': {unknown}
1035 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1036 323..341 '<F as ...bar(S)': {unknown}
1038 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1039 347..356 'F::bar(S)': {unknown}
1041 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1042 362..380 'Foo::b...32>(S)': u32
1044 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1045 386..411 '<F as ...32>(S)': u32
1047 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1048 418..424 'foo(S)': {unknown}
1050 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1051 430..443 'foo::<u32>(S)': u32
1053 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1054 449..467 'foo::<...32>(S)': u32
1061 fn argument_impl_trait_type_args_2() {
1062 check_infer_with_mismatches(
1069 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1075 F::<u32>.foo::<i32>(S);
1076 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1080 93..94 'x': impl Trait
1081 118..129 '{ loop {} }': (T, U)
1082 120..127 'loop {}': !
1084 143..283 '{ ...ored }': ()
1085 149..150 'F': F<{unknown}>
1086 149..157 'F.foo(S)': ({unknown}, {unknown})
1088 163..171 'F::<u32>': F<u32>
1089 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1091 184..192 'F::<u32>': F<u32>
1092 184..206 'F::<u3...32>(S)': (u32, i32)
1094 212..220 'F::<u32>': F<u32>
1095 212..239 'F::<u3...32>(S)': (u32, i32)
1102 fn argument_impl_trait_to_fn_pointer() {
1103 check_infer_with_mismatches(
1106 fn foo(x: impl Trait) { loop {} }
1111 let f: fn(S) -> () = foo;
1114 22..23 'x': impl Trait
1115 37..48 '{ loop {} }': ()
1118 90..123 '{ ...foo; }': ()
1120 117..120 'foo': fn foo(S)
1131 fn foo2(&self) -> i64;
1133 fn bar() -> impl Trait<u64> {}
1135 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1147 29..33 'self': &Self
1148 54..58 'self': &Self
1150 110..111 'x': impl Trait<u64>
1151 130..131 'y': &impl Trait<u64>
1152 151..268 '{ ...2(); }': ()
1153 157..158 'x': impl Trait<u64>
1154 164..165 'y': &impl Trait<u64>
1155 175..176 'z': impl Trait<u64>
1156 179..182 'bar': fn bar() -> impl Trait<u64>
1157 179..184 'bar()': impl Trait<u64>
1158 190..191 'x': impl Trait<u64>
1159 190..197 'x.foo()': u64
1160 203..204 'y': &impl Trait<u64>
1161 203..210 'y.foo()': u64
1162 216..217 'z': impl Trait<u64>
1163 216..223 'z.foo()': u64
1164 229..230 'x': impl Trait<u64>
1165 229..237 'x.foo2()': i64
1166 243..244 'y': &impl Trait<u64>
1167 243..251 'y.foo2()': i64
1168 257..258 'z': impl Trait<u64>
1169 257..265 'z.foo2()': i64
1175 fn simple_return_pos_impl_trait() {
1176 cov_mark::check!(lower_rpit);
1182 fn bar() -> impl Trait<u64> { loop {} }
1189 29..33 'self': &Self
1190 71..82 '{ loop {} }': !
1193 94..129 '{ ...o(); }': ()
1194 104..105 'a': impl Trait<u64>
1195 108..111 'bar': fn bar() -> impl Trait<u64>
1196 108..113 'bar()': impl Trait<u64>
1197 119..120 'a': impl Trait<u64>
1198 119..126 'a.foo()': u64
1204 fn more_return_pos_impl_trait() {
1209 fn next(&mut self) -> Self::Item;
1214 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1215 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1221 let (c, d) = baz(1u128);
1226 49..53 'self': &mut Self
1227 101..105 'self': &Self
1228 184..195 '{ loop {} }': ({unknown}, {unknown})
1229 186..193 'loop {}': !
1232 268..279 '{ loop {} }': ({unknown}, {unknown})
1233 270..277 'loop {}': !
1235 291..413 '{ ...o(); }': ()
1236 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1237 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1238 305..306 'b': impl Trait<u64>
1239 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1240 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1241 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1242 321..329 'a.next()': impl Trait<u32>
1243 321..335 'a.next().foo()': u32
1244 341..342 'b': impl Trait<u64>
1245 341..348 'b.foo()': u64
1246 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1247 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1248 362..363 'd': impl Trait<u128>
1249 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1250 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1251 371..376 '1u128': u128
1252 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1253 383..391 'c.next()': impl Trait<u128>
1254 383..397 'c.next().foo()': u128
1255 403..404 'd': impl Trait<u128>
1256 403..410 'd.foo()': u128
1267 fn foo2(&self) -> i64;
1269 fn bar() -> dyn Trait<u64> {}
1271 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1283 29..33 'self': &Self
1284 54..58 'self': &Self
1286 109..110 'x': dyn Trait<u64>
1287 128..129 'y': &dyn Trait<u64>
1288 148..265 '{ ...2(); }': ()
1289 154..155 'x': dyn Trait<u64>
1290 161..162 'y': &dyn Trait<u64>
1291 172..173 'z': dyn Trait<u64>
1292 176..179 'bar': fn bar() -> dyn Trait<u64>
1293 176..181 'bar()': dyn Trait<u64>
1294 187..188 'x': dyn Trait<u64>
1295 187..194 'x.foo()': u64
1296 200..201 'y': &dyn Trait<u64>
1297 200..207 'y.foo()': u64
1298 213..214 'z': dyn Trait<u64>
1299 213..220 'z.foo()': u64
1300 226..227 'x': dyn Trait<u64>
1301 226..234 'x.foo2()': i64
1302 240..241 'y': &dyn Trait<u64>
1303 240..248 'y.foo2()': i64
1304 254..255 'z': dyn Trait<u64>
1305 254..262 'z.foo2()': i64
1311 fn dyn_trait_in_impl() {
1315 fn foo(&self) -> (T, U);
1318 impl<T, U> S<T, U> {
1319 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1321 trait Trait2<T, U> {
1322 fn baz(&self) -> (T, U);
1324 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1326 fn test(s: S<u32, i32>) {
1330 32..36 'self': &Self
1331 102..106 'self': &S<T, U>
1332 128..139 '{ loop {} }': &dyn Trait<T, U>
1333 130..137 'loop {}': !
1335 175..179 'self': &Self
1336 251..252 's': S<u32, i32>
1337 267..289 '{ ...z(); }': ()
1338 273..274 's': S<u32, i32>
1339 273..280 's.bar()': &dyn Trait<u32, i32>
1340 273..286 's.bar().baz()': (u32, i32)
1346 fn dyn_trait_bare() {
1350 fn foo(&self) -> u64;
1352 fn bar() -> Trait {}
1354 fn test(x: Trait, y: &Trait) -> u64 {
1363 26..30 'self': &Self
1365 72..73 'x': dyn Trait
1366 82..83 'y': &dyn Trait
1367 100..175 '{ ...o(); }': ()
1368 106..107 'x': dyn Trait
1369 113..114 'y': &dyn Trait
1370 124..125 'z': dyn Trait
1371 128..131 'bar': fn bar() -> dyn Trait
1372 128..133 'bar()': dyn Trait
1373 139..140 'x': dyn Trait
1374 139..146 'x.foo()': u64
1375 152..153 'y': &dyn Trait
1376 152..159 'y.foo()': u64
1377 165..166 'z': dyn Trait
1378 165..172 'z.foo()': u64
1389 a: impl Trait + 'lifetime,
1392 d: impl ('lifetime),
1394 f: impl Trait + ?Sized
1398 28..29 'a': impl Trait
1400 82..83 'c': impl Trait
1403 148..149 'f': impl Trait
1411 fn error_bound_chalk() {
1415 fn foo(&self) -> u32 {}
1418 fn test(x: (impl Trait + UnknownTrait)) {
1426 fn assoc_type_bindings() {
1433 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1434 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1435 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1438 impl<T> Trait for S<T> { type Type = T; }
1440 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1458 262..263 'y': impl Trait<Type = i64>
1459 289..397 '{ ...r>); }': ()
1460 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1461 295..301 'get(x)': u32
1463 307..311 'get2': fn get2<u32, T>(T) -> u32
1464 307..314 'get2(x)': u32
1466 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1467 320..326 'get(y)': i64
1468 324..325 'y': impl Trait<Type = i64>
1469 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1470 332..339 'get2(y)': i64
1471 337..338 'y': impl Trait<Type = i64>
1472 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1473 345..356 'get(set(S))': u64
1474 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1475 349..355 'set(S)': S<u64>
1476 353..354 'S': S<u64>
1477 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1478 362..374 'get2(set(S))': u64
1479 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1480 367..373 'set(S)': S<u64>
1481 371..372 'S': S<u64>
1482 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1483 380..394 'get2(S::<str>)': str
1484 385..393 'S::<str>': S<str>
1490 fn impl_trait_assoc_binding_projection_bug() {
1493 //- /main.rs crate:main deps:std
1494 pub trait Language {
1497 pub enum RustLanguage {}
1498 impl Language for RustLanguage {
1499 type Kind = SyntaxKind;
1501 struct SyntaxNode<L> {}
1502 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1505 fn clone(&self) -> Self;
1508 fn api_walkthrough() {
1514 //- /std.rs crate:std
1515 #[prelude_import] use iter::*;
1517 trait IntoIterator {
1523 impl<T: Iterator> IntoIterator for T {
1524 type Item = <T as Iterator>::Item;
1532 fn projection_eq_within_chalk() {
1541 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1543 fn test<T: Trait1<Type = u32>>(x: T) {
1549 169..185 '{ ...o(); }': ()
1551 175..182 'x.foo()': u32
1557 fn where_clause_trait_in_scope_for_method_resolution() {
1562 fn foo(&self) -> u32 {}
1566 fn test<T: foo::Trait>(x: T) {
1574 fn super_trait_method_resolution() {
1579 fn foo(&self) -> u32 {}
1582 trait Trait1: foo::SuperTrait {}
1583 trait Trait2 where Self: foo::SuperTrait {}
1585 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1590 49..53 'self': &Self
1594 193..222 '{ ...o(); }': ()
1596 199..206 'x.foo()': u32
1598 212..219 'y.foo()': u32
1604 fn super_trait_impl_trait_method_resolution() {
1609 fn foo(&self) -> u32 {}
1612 trait Trait1: foo::SuperTrait {}
1614 fn test(x: &impl Trait1) {
1618 49..53 'self': &Self
1620 115..116 'x': &impl Trait1
1621 132..148 '{ ...o(); }': ()
1622 138..139 'x': &impl Trait1
1623 138..145 'x.foo()': u32
1629 fn super_trait_cycle() {
1630 // This just needs to not crash
1636 fn test<T: A>(x: T) {
1642 49..65 '{ ...o(); }': ()
1644 55..62 'x.foo()': {unknown}
1650 fn super_trait_assoc_type_bounds() {
1653 trait SuperTrait { type Type; }
1654 trait Trait where Self: SuperTrait {}
1656 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1657 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1660 impl<T> SuperTrait for S<T> { type Type = T; }
1661 impl<T> Trait for S<T> {}
1672 258..279 '{ ...S)); }': ()
1673 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1674 264..276 'get2(set(S))': u64
1675 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1676 269..275 'set(S)': S<u64>
1677 273..274 'S': S<u64>
1684 check_infer_with_mismatches(
1686 trait FnOnce<Args> {
1689 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1692 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1693 f.call_once((1, 2));
1699 155..183 '{ ...2)); }': ()
1701 161..180 'f.call...1, 2))': u128
1702 173..179 '(1, 2)': (u32, u64)
1710 fn fn_ptr_and_item() {
1711 check_infer_with_mismatches(
1714 trait FnOnce<Args> {
1717 fn call_once(self, args: Args) -> Self::Output;
1726 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1727 fn foo(&self) -> (A1, R) { loop {} }
1730 enum Opt<T> { None, Some(T) }
1732 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1736 let bar: Bar<fn(u8) -> u32>;
1740 let f: fn(u8) -> u32;
1746 139..143 'self': &Self
1747 243..247 'self': &Bar<F>
1748 260..271 '{ loop {} }': (A1, R)
1749 262..269 'loop {}': !
1751 355..359 'self': Opt<T>
1753 377..388 '{ loop {} }': Opt<U>
1754 379..386 'loop {}': !
1756 402..518 '{ ...(f); }': ()
1757 412..415 'bar': Bar<fn(u8) -> u32>
1758 441..444 'bar': Bar<fn(u8) -> u32>
1759 441..450 'bar.foo()': (u8, u32)
1760 461..464 'opt': Opt<u8>
1761 483..484 'f': fn(u8) -> u32
1762 505..508 'opt': Opt<u8>
1763 505..515 'opt.map(f)': Opt<u32>
1764 513..514 'f': fn(u8) -> u32
1770 fn fn_trait_deref_with_ty_default() {
1777 fn deref(&self) -> &Self::Target;
1781 trait FnOnce<Args> {
1784 fn call_once(self, args: Args) -> Self::Output;
1790 fn foo(&self) -> usize {}
1793 struct Lazy<T, F = fn() -> T>(F);
1795 impl<T, F> Lazy<T, F> {
1796 pub fn new(f: F) -> Lazy<T, F> {}
1799 impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
1804 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1805 let r1 = lazy1.foo();
1807 fn make_foo_fn() -> Foo {}
1808 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1809 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1810 let r2 = lazy2.foo();
1813 64..68 'self': &Self
1814 165..169 'self': Self
1815 171..175 'args': Args
1816 239..243 'self': &Foo
1820 443..689 '{ ...o(); }': ()
1821 453..458 'lazy1': Lazy<Foo, || -> Foo>
1822 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1823 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1824 485..491 '|| Foo': || -> Foo
1826 502..504 'r1': usize
1827 507..512 'lazy1': Lazy<Foo, || -> Foo>
1828 507..518 'lazy1.foo()': usize
1829 560..575 'make_foo_fn_ptr': fn() -> Foo
1830 591..602 'make_foo_fn': fn make_foo_fn() -> Foo
1831 612..617 'lazy2': Lazy<Foo, fn() -> Foo>
1832 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1833 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1834 644..659 'make_foo_fn_ptr': fn() -> Foo
1835 670..672 'r2': usize
1836 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1837 675..686 'lazy2.foo()': usize
1845 check_infer_with_mismatches(
1848 trait FnOnce<Args> {
1852 enum Option<T> { Some(T), None }
1854 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1858 let x = Option::Some(1u32);
1861 let y: Option<i64> = x.map(|_v| 1);
1864 147..151 'self': Option<T>
1866 172..183 '{ loop {} }': Option<U>
1867 174..181 'loop {}': !
1869 197..316 '{ ... 1); }': ()
1870 207..208 'x': Option<u32>
1871 211..223 'Option::Some': Some<u32>(u32) -> Option<u32>
1872 211..229 'Option...(1u32)': Option<u32>
1873 224..228 '1u32': u32
1874 235..236 'x': Option<u32>
1875 235..251 'x.map(...v + 1)': Option<u32>
1876 241..250 '|v| v + 1': |u32| -> u32
1879 245..250 'v + 1': u32
1881 257..258 'x': Option<u32>
1882 257..273 'x.map(... 1u64)': Option<u64>
1883 263..272 '|_v| 1u64': |u32| -> u64
1885 268..272 '1u64': u64
1886 283..284 'y': Option<i64>
1887 300..301 'x': Option<u32>
1888 300..313 'x.map(|_v| 1)': Option<i64>
1889 306..312 '|_v| 1': |u32| -> i64
1898 check_infer_with_mismatches(
1901 pub trait Add<Rhs = Self> {
1903 fn add(self, rhs: Rhs) -> Self::Output;
1906 trait FnOnce<Args> {
1912 fn add(self, rhs: u64) -> Self::Output {0}
1917 fn add(self, rhs: u128) -> Self::Output {0}
1920 fn test<F: FnOnce(u32) -> u64>(f: F) {
1924 let h = |v| 1u128 + v;
1929 203..207 'self': u64
1933 297..301 'self': u128
1934 303..306 'rhs': u128
1935 330..333 '{0}': u128
1938 374..450 '{ ...+ v; }': ()
1940 380..384 'f(1)': {unknown}
1942 394..395 'g': |u64| -> u64
1943 398..407 '|v| v + 1': |u64| -> u64
1946 402..407 'v + 1': u64
1948 413..414 'g': |u64| -> u64
1949 413..420 'g(1u64)': u64
1950 415..419 '1u64': u64
1951 430..431 'h': |u128| -> u128
1952 434..447 '|v| 1u128 + v': |u128| -> u128
1954 438..443 '1u128': u128
1955 438..447 '1u128 + v': u128
1962 fn closure_as_argument_inference_order() {
1963 check_infer_with_mismatches(
1966 trait FnOnce<Args> {
1970 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
1971 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
1975 fn method(self) -> u64;
1977 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
1978 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
1982 let x1 = foo1(S, |s| s.method());
1983 let x2 = foo2(|s| s.method(), S);
1984 let x3 = S.foo1(S, |s| s.method());
1985 let x4 = S.foo2(|s| s.method(), S);
1990 111..122 '{ loop {} }': U
1991 113..120 'loop {}': !
1995 173..184 '{ loop {} }': U
1996 175..182 'loop {}': !
2002 294..305 '{ loop {} }': U
2003 296..303 'loop {}': !
2008 366..377 '{ loop {} }': U
2009 368..375 'loop {}': !
2011 391..550 '{ ... S); }': ()
2013 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2014 406..429 'foo1(S...hod())': u64
2016 414..428 '|s| s.method()': |S| -> u64
2019 418..428 's.method()': u64
2021 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2022 444..467 'foo2(|...(), S)': u64
2023 449..463 '|s| s.method()': |S| -> u64
2026 453..463 's.method()': u64
2030 482..507 'S.foo1...hod())': u64
2032 492..506 '|s| s.method()': |S| -> u64
2035 496..506 's.method()': u64
2038 522..547 'S.foo2...(), S)': u64
2039 529..543 '|s| s.method()': |S| -> u64
2042 533..543 's.method()': u64
2049 fn fn_item_fn_trait() {
2053 trait FnOnce<Args> {
2061 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2065 } //^^^^^^^^^^^^^^^^^^ S
2071 fn unselected_projection_in_trait_env_1() {
2080 fn foo(&self) -> u32;
2083 fn test<T: Trait>() where T::Item: Trait2 {
2084 let x: T::Item = no_matter;
2092 fn unselected_projection_in_trait_env_2() {
2100 fn foo(&self) -> u32;
2103 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2104 let x: T::Item = no_matter;
2112 fn unselected_projection_on_impl_self() {
2119 fn f(&self, x: Self::Item);
2126 fn f(&self, x: Self::Item) { let y = x; }
2133 fn f(&self, x: <Self>::Item) { let y = x; }
2136 40..44 'self': &Self
2137 46..47 'x': Trait::Item<Self>
2140 147..161 '{ let y = x; }': ()
2143 228..232 'self': &S2
2145 251..265 '{ let y = x; }': ()
2153 fn unselected_projection_on_trait_self() {
2159 fn f(&self) -> Self::Item { loop {} }
2175 fn unselected_projection_chalk_fold() {
2179 trait Fold<I: Interner, TI = I> {
2183 struct Ty<I: Interner> {}
2184 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2185 type Result = Ty<TI>;
2188 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2195 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2203 fn trait_impl_self_ty() {
2212 impl Trait<Self> for S {}
2222 fn trait_impl_self_ty_cycle() {
2231 impl Trait for S<Self> {}
2241 fn unselected_projection_in_trait_env_cycle_1() {
2242 // this is a legitimate cycle
2251 fn test<T: Trait>() where T: Trait2<T::Item> {
2252 let x: T::Item = no_matter;
2259 fn unselected_projection_in_trait_env_cycle_2() {
2260 // this is a legitimate cycle
2268 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2269 let x: T::Item = no_matter;
2276 fn unselected_projection_in_trait_env_cycle_3() {
2277 // this is a cycle for rustc; we currently accept it
2286 fn test<T>() where T: Trait<OtherItem = T::Item> {
2287 let x: T::Item = no_matter;
2288 } //^ Trait::Item<T>
2294 fn unselected_projection_in_trait_env_no_cycle() {
2295 // this is not a cycle
2303 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2305 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2308 fn len(&self) -> usize;
2311 pub trait UnificationStoreMut: UnificationStoreBase {
2312 fn push(&mut self, value: Self::Key);
2315 fn test<T>(t: T) where T: UnificationStoreMut {
2320 } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2326 fn inline_assoc_type_bounds_1() {
2332 trait OtherTrait<T> {
2336 // workaround for Chalk assoc type normalization problems
2338 impl<T: Iterator> Iterator for S<T> {
2339 type Item = <T as Iterator>::Item;
2342 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2343 let x: <S<I> as Iterator>::Item;
2351 fn inline_assoc_type_bounds_2() {
2358 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2359 let x: <<I as Iterator>::Item as Iterator>::Item;
2367 fn proc_macro_server_types() {
2370 macro_rules! with_api {
2371 ($S:ident, $self:ident, $m:ident) => {
2374 fn new() -> $S::TokenStream;
2381 macro_rules! associated_item {
2382 (type TokenStream) =>
2383 (type TokenStream: 'static;);
2385 (type Group: 'static;);
2386 ($($item:tt)*) => ($($item)*;)
2388 macro_rules! declare_server_traits {
2390 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2393 $(associated_item!(type $name);)*
2396 $(pub trait $name: Types {
2397 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2400 pub trait Server: Types $(+ $name)* {}
2401 impl<S: Types $(+ $name)*> Server for S {}
2405 with_api!(Self, self_, declare_server_traits);
2409 impl Types for Rustc {
2410 type TokenStream = T;
2414 fn make<T>() -> T { loop {} }
2415 impl TokenStream for Rustc {
2416 fn new() -> Self::TokenStream {
2417 let group: Self::Group = make();
2422 1061..1072 '{ loop {} }': T
2423 1063..1070 'loop {}': !
2425 1136..1199 '{ ... }': T
2426 1150..1155 'group': G
2427 1171..1175 'make': fn make<G>() -> G
2428 1171..1177 'make()': G
2429 1187..1191 'make': fn make<T>() -> T
2430 1187..1193 'make()': T
2436 fn unify_impl_trait() {
2437 check_infer_with_mismatches(
2441 fn foo(x: impl Trait<u32>) { loop {} }
2442 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2445 impl<T> Trait<T> for S<T> {}
2447 fn default<T>() -> T { loop {} }
2449 fn test() -> impl Trait<i32> {
2450 let s1 = S(default());
2452 let x: i32 = bar(S(default()));
2456 26..27 'x': impl Trait<u32>
2457 46..57 '{ loop {} }': ()
2460 68..69 'x': impl Trait<T>
2461 91..102 '{ loop {} }': T
2462 93..100 'loop {}': !
2464 171..182 '{ loop {} }': T
2465 173..180 'loop {}': !
2467 213..309 '{ ...t()) }': S<{unknown}>
2468 223..225 's1': S<u32>
2469 228..229 'S': S<u32>(u32) -> S<u32>
2470 228..240 'S(default())': S<u32>
2471 230..237 'default': fn default<u32>() -> u32
2472 230..239 'default()': u32
2473 246..249 'foo': fn foo(S<u32>)
2474 246..253 'foo(s1)': ()
2475 250..252 's1': S<u32>
2477 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2478 272..289 'bar(S(...lt()))': i32
2479 276..277 'S': S<i32>(i32) -> S<i32>
2480 276..288 'S(default())': S<i32>
2481 278..285 'default': fn default<i32>() -> i32
2482 278..287 'default()': i32
2483 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2484 295..307 'S(default())': S<{unknown}>
2485 297..304 'default': fn default<{unknown}>() -> {unknown}
2486 297..306 'default()': {unknown}
2492 fn assoc_types_from_bounds() {
2497 trait FnOnce<Args> {
2516 f::<(), _>(|z| { z; });
2521 193..224 '{ ... }); }': ()
2522 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2523 199..221 'f::<()... z; })': ()
2524 210..220 '|z| { z; }': |&()| -> ()
2526 214..220 '{ z; }': ()
2533 fn associated_type_bound() {
2537 type Item: OtherTrait<u32>;
2539 pub trait OtherTrait<T> {
2543 // this is just a workaround for chalk#234
2545 impl<T: Trait> Trait for S<T> {
2546 type Item = <T as Trait>::Item;
2549 fn test<T: Trait>() {
2550 let y: <S<T> as Trait>::Item = no_matter;
2558 fn dyn_trait_through_chalk() {
2566 impl<T> Deref for Box<T> {
2573 fn test(x: Box<dyn Trait>) {
2581 fn string_to_owned() {
2587 fn to_owned(&self) -> Self::Owned;
2589 impl ToOwned for str {
2590 type Owned = String;
2600 fn iterator_chain() {
2601 check_infer_with_mismatches(
2605 trait FnOnce<Args> {
2609 trait FnMut<Args>: FnOnce<Args> { }
2611 enum Option<T> { Some(T), None }
2614 pub trait Iterator {
2617 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2619 F: FnMut(Self::Item) -> Option<B>,
2622 fn for_each<F>(self, f: F)
2624 F: FnMut(Self::Item),
2628 pub trait IntoIterator {
2630 type IntoIter: Iterator<Item = Self::Item>;
2631 fn into_iter(self) -> Self::IntoIter;
2634 pub struct FilterMap<I, F> { }
2635 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2637 F: FnMut(I::Item) -> Option<B>,
2642 #[stable(feature = "rust1", since = "1.0.0")]
2643 impl<I: Iterator> IntoIterator for I {
2644 type Item = I::Item;
2647 fn into_iter(self) -> I {
2654 fn new() -> Self { loop {} }
2657 impl<T> IntoIterator for Vec<T> {
2659 type IntoIter = IntoIter<T>;
2662 pub struct IntoIter<T> { }
2663 impl<T> Iterator for IntoIter<T> {
2668 Vec::<i32>::new().into_iter()
2669 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2670 .for_each(|y| { y; });
2673 226..230 'self': Self
2675 317..328 '{ loop {} }': FilterMap<Self, F>
2676 319..326 'loop {}': !
2678 349..353 'self': Self
2680 405..416 '{ loop {} }': ()
2681 407..414 'loop {}': !
2683 525..529 'self': Self
2685 865..885 '{ ... }': I
2687 944..955 '{ loop {} }': Vec<T>
2688 946..953 'loop {}': !
2690 1142..1269 '{ ... }); }': ()
2691 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2692 1148..1165 'Vec::<...:new()': Vec<i32>
2693 1148..1177 'Vec::<...iter()': IntoIter<i32>
2694 1148..1240 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2695 1148..1266 'Vec::<... y; })': ()
2696 1194..1239 '|x| if...None }': |i32| -> Option<u32>
2698 1198..1239 'if x >...None }': Option<u32>
2700 1201..1206 'x > 0': bool
2702 1207..1225 '{ Some...u32) }': Option<u32>
2703 1209..1213 'Some': Some<u32>(u32) -> Option<u32>
2704 1209..1223 'Some(x as u32)': Option<u32>
2706 1214..1222 'x as u32': u32
2707 1231..1239 '{ None }': Option<u32>
2708 1233..1237 'None': Option<u32>
2709 1255..1265 '|y| { y; }': |u32| -> ()
2711 1259..1265 '{ y; }': ()
2734 fn foo() -> Self::Output;
2738 type Output = T::OutputA;
2739 fn foo() -> Self::Output { loop {} }
2750 fn trait_object_no_coercion() {
2751 check_infer_with_mismatches(
2755 fn foo(x: &dyn Foo) {}
2757 fn test(x: &dyn Foo) {
2761 21..22 'x': &dyn Foo
2763 46..47 'x': &dyn Foo
2764 59..74 '{ foo(x); }': ()
2765 65..68 'foo': fn foo(&dyn Foo)
2767 69..70 'x': &dyn Foo
2774 check_infer_with_mismatches(
2780 impl Copy for IsCopy {}
2783 trait Test { fn test(&self) -> bool; }
2784 impl<T: Copy> Test for T {}
2789 (IsCopy, IsCopy).test();
2790 (IsCopy, NotCopy).test();
2793 110..114 'self': &Self
2794 166..267 '{ ...t(); }': ()
2795 172..178 'IsCopy': IsCopy
2796 172..185 'IsCopy.test()': bool
2797 191..198 'NotCopy': NotCopy
2798 191..205 'NotCopy.test()': {unknown}
2799 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy)
2800 211..234 '(IsCop...test()': bool
2801 212..218 'IsCopy': IsCopy
2802 220..226 'IsCopy': IsCopy
2803 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy)
2804 240..264 '(IsCop...test()': {unknown}
2805 241..247 'IsCopy': IsCopy
2806 249..256 'NotCopy': NotCopy
2812 fn builtin_fn_def_copy() {
2813 check_infer_with_mismatches(
2819 fn bar<T: Copy>(T) -> T {}
2820 struct Struct(usize);
2821 enum Enum { Variant(usize) }
2823 trait Test { fn test(&self) -> bool; }
2824 impl<T: Copy> Test for T {}
2830 Enum::Variant.test();
2834 60..61 'T': {unknown}
2836 68..70: expected T, got ()
2837 145..149 'self': &Self
2838 201..281 '{ ...t(); }': ()
2839 207..210 'foo': fn foo()
2840 207..217 'foo.test()': bool
2841 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2842 223..233 'bar.test()': bool
2843 239..245 'Struct': Struct(usize) -> Struct
2844 239..252 'Struct.test()': bool
2845 258..271 'Enum::Variant': Variant(usize) -> Enum
2846 258..278 'Enum::...test()': bool
2852 fn builtin_fn_ptr_copy() {
2853 check_infer_with_mismatches(
2858 trait Test { fn test(&self) -> bool; }
2859 impl<T: Copy> Test for T {}
2861 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2867 54..58 'self': &Self
2869 118..120 'f2': fn(usize) -> u8
2870 139..141 'f3': fn(u8, u8) -> &u8
2871 162..210 '{ ...t(); }': ()
2873 168..177 'f1.test()': bool
2874 183..185 'f2': fn(usize) -> u8
2875 183..192 'f2.test()': bool
2876 198..200 'f3': fn(u8, u8) -> &u8
2877 198..207 'f3.test()': bool
2883 fn builtin_sized() {
2884 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 56..60 'self': &Self
2900 113..228 '{ ...ized }': ()
2902 119..129 '1u8.test()': bool
2903 135..150 '(*"foo").test()': {unknown}
2904 136..142 '*"foo"': str
2905 137..142 '"foo"': &str
2906 169..179 '(1u8, 1u8)': (u8, u8)
2907 169..186 '(1u8, ...test()': bool
2910 192..205 '(1u8, *"foo")': (u8, str)
2911 192..212 '(1u8, ...test()': {unknown}
2913 198..204 '*"foo"': str
2914 199..204 '"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 infer_fn_trait_arg() {
2997 check_infer_with_mismatches(
2999 //- /lib.rs deps:std
3002 pub trait FnOnce<Args> {
3005 extern "rust-call" fn call_once(&self, args: Args) -> Self::Output;
3009 pub trait Fn<Args>:FnOnce<Args> {
3010 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3018 fn foo<F, T>(f: F) -> T
3020 F: Fn(Option<i32>) -> T,
3027 101..105 'self': &Self
3028 107..111 'args': Args
3029 220..224 'self': &Self
3030 226..230 'args': Args
3032 359..389 '{ ...f(s) }': T
3033 369..370 's': Option<i32>
3034 373..377 'None': Option<i32>
3037 385..386 's': Option<i32>
3043 fn infer_box_fn_arg() {
3044 // The type mismatch is a bug
3045 check_infer_with_mismatches(
3047 //- /lib.rs deps:std
3050 pub trait FnOnce<Args> {
3053 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3058 type Target: ?Sized;
3060 fn deref(&self) -> &Self::Target;
3063 #[lang = "owned_box"]
3064 pub struct Box<T: ?Sized> {
3068 impl<T: ?Sized> Deref for Box<T> {
3071 fn deref(&self) -> &T {
3082 let s = Option::None;
3083 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3087 100..104 'self': Self
3088 106..110 'args': Args
3089 214..218 'self': &Self
3090 384..388 'self': &Box<T>
3091 396..423 '{ ... }': &T
3092 406..417 '&self.inner': &*mut T
3093 407..411 'self': &Box<T>
3094 407..417 'self.inner': *mut T
3095 478..576 '{ ...&s); }': ()
3096 488..489 's': Option<i32>
3097 492..504 'Option::None': Option<i32>
3098 514..515 'f': Box<dyn FnOnce(&Option<i32>)>
3099 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3100 554..561 '|ps| {}': |{unknown}| -> ()
3101 555..557 'ps': {unknown}
3103 568..569 'f': Box<dyn FnOnce(&Option<i32>)>
3104 568..573 'f(&s)': FnOnce::Output<dyn FnOnce(&Option<i32>), (&Option<i32>,)>
3105 570..572 '&s': &Option<i32>
3106 571..572 's': Option<i32>
3107 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|_| -> ()>
3113 fn infer_dyn_fn_output() {
3117 pub trait FnOnce<Args> {
3119 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3123 pub trait Fn<Args>: FnOnce<Args> {
3124 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3128 let f: &dyn Fn() -> i32;
3136 fn infer_dyn_fn_once_output() {
3140 pub trait FnOnce<Args> {
3142 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3146 let f: dyn FnOnce() -> i32;
3154 fn variable_kinds_1() {
3157 trait Trait<T> { fn get(self, t: T) -> T; }
3159 impl Trait<u128> for S {}
3160 impl Trait<f32> for S {}
3172 fn variable_kinds_2() {
3175 trait Trait { fn get(self) -> Self; }
3176 impl Trait for u128 {}
3177 impl Trait for f32 {}
3189 fn underscore_import() {
3194 fn method(&self) -> u8 { 0 }
3199 impl crate::tr::Tr for Tr {}
3201 use crate::tr::Tr as _;
3216 fn method(&self) -> u8 { 0 }
3233 fn trait_in_scope_with_inner_item() {
3238 fn method(&self) -> u8 { 0 }
3253 46..50 'self': &Self
3256 115..185 '{ ... } }': ()
3257 132..183 '{ ... }': ()
3259 142..153 '().method()': u8
3265 fn inner_use_in_block() {
3270 fn method(&self) -> u8 { 0 }
3286 //^^^^^^^^^^^ {unknown}
3290 //^^^^^^^^^^^ {unknown}
3297 fn nested_inner_function_calling_self() {
3307 17..73 '{ ... } }': ()
3308 39..71 '{ ... }': ()
3310 57..62 'inner': fn inner() -> S
3317 fn infer_default_trait_type_parameter() {
3322 trait Op<RHS=Self> {
3325 fn do_op(self, rhs: RHS) -> Self::Output;
3331 fn do_op(self, rhs: Self) -> Self::Output {
3346 186..206 '{ ... }': bool
3347 196..200 'true': bool
3348 220..277 '{ ...(y); }': ()
3355 264..274 'x.do_op(y)': bool
3362 fn qualified_path_as_qualified_trait() {
3372 fn boo() -> Self::Output {
3379 impl foo::Foo for F {
3382 impl foo::Bar for F {
3383 type Output = <F as foo::Foo>::Target;
3388 let x = <F as Bar>::boo();
3391 132..163 '{ ... }': Bar::Output<Self>
3392 146..153 'loop {}': !
3394 306..358 '{ ...o(); }': ()
3396 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3397 338..355 '<F as ...:boo()': ()
3403 fn renamed_extern_crate_in_block() {
3406 //- /lib.rs crate:lib deps:serde
3407 use serde::Deserialize;
3412 extern crate serde as _serde;
3413 impl _serde::Deserialize for Foo {
3414 fn deserialize() -> u8 { 0 }
3420 //^^^^^^^^^^^^^^^^^^ u8
3423 //- /serde.rs crate:serde
3425 pub trait Deserialize {
3426 fn deserialize() -> u8;
3432 fn bin_op_adt_with_rhs_primitive() {
3433 check_infer_with_mismatches(
3436 pub trait Add<Rhs = Self> {
3438 fn add(self, rhs: Rhs) -> Self::Output;
3441 struct Wrapper(u32);
3442 impl Add<u32> for Wrapper {
3444 fn add(self, rhs: u32) -> Wrapper {
3449 let wrapped = Wrapper(10);
3451 let res = wrapped + num;
3457 192..196 'self': Wrapper
3459 219..247 '{ ... }': Wrapper
3460 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3461 229..241 'Wrapper(rhs)': Wrapper
3463 259..345 '{ ...um; }': ()
3464 269..276 'wrapped': Wrapper
3465 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3466 279..290 'Wrapper(10)': Wrapper
3470 322..325 'res': Wrapper
3471 328..335 'wrapped': Wrapper
3472 328..341 'wrapped + num': Wrapper