2 use expect_test::expect;
4 use super::{check, check_infer, check_infer_with_mismatches, check_no_mismatches, check_types};
13 impl core::future::Future for IntFuture {
31 async fn foo() -> u64 { 128 }
43 fn infer_desugar_async() {
46 //- minicore: future, sized
47 async fn foo() -> u64 { 128 }
52 } //^ impl Future<Output = u64>
58 fn infer_async_block() {
61 //- minicore: future, option
65 // ^ impl Future<Output = i32>
69 let b = async {}.await;
77 let _: Option<u64> = c.await;
79 // ^ impl Future<Output = Option<u64>>
86 fn auto_sized_async_block() {
89 //- minicore: future, sized
91 use core::future::Future;
92 struct MyFut<Fut>(Fut);
94 impl<Fut> Future for MyFut<Fut>
97 type Output = Fut::Output;
99 async fn reproduction() -> usize {
100 let f = async {999usize};
113 pub trait Unsize<T: ?Sized> {}
115 #[lang = "coerce_unsized"]
116 pub trait CoerceUnsized<T> {}
118 pub unsafe trait Allocator {}
121 unsafe impl Allocator for Global {}
123 #[lang = "owned_box"]
125 pub struct Box<T: ?Sized, A: Allocator = Global>;
127 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
129 fn send() -> Box<dyn Future<Output = ()> + Send + 'static>{
133 fn not_send() -> Box<dyn Future<Output = ()> + 'static> {
141 fn into_future_trait() {
146 impl core::future::IntoFuture for Futurable {
148 type IntoFuture = IntFuture;
152 impl core::future::Future for IntFuture {
169 //- /main.rs crate:main deps:core
171 let r: Result<i32, u64> = Result::Ok(1);
176 //- /core.rs crate:core
185 pub enum Result<O, E> {
190 impl<O, E> crate::ops::Try for Result<O, E> {
198 pub use crate::{result::*, ops::*};
206 fn infer_try_trait_v2() {
209 //- /main.rs crate:main deps:core
211 let r: Result<i32, u64> = Result::Ok(1);
216 //- /core.rs crate:core
219 pub trait Try: FromResidual {
223 pub trait FromResidual<R = <Self as Try>::Residual> {}
226 pub use self::try_trait::FromResidual;
227 pub use self::try_trait::Try;
232 impl<T> From<T> for T {}
236 use crate::convert::From;
237 use crate::ops::{Try, FromResidual};
239 pub enum Infallible {}
240 pub enum Result<O, E> {
245 impl<O, E> Try for Result<O, E> {
247 type Error = Result<Infallible, E>;
250 impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
255 pub use crate::result::*;
263 fn infer_for_loop() {
266 //- /main.rs crate:main deps:core,alloc
268 use alloc::collections::Vec;
278 //- /core.rs crate:core
280 pub trait IntoIterator {
286 pub use crate::iter::*;
290 //- /alloc.rs crate:alloc deps:core
292 pub mod collections {
295 pub fn new() -> Self { Vec {} }
296 pub fn push(&mut self, t: T) { }
299 impl<T> IntoIterator for Vec<T> {
311 //- /main.rs crate:main deps:std
315 impl std::ops::Neg for Bar {
325 //- /std.rs crate:std
326 #[prelude_import] use ops::*;
341 //- /main.rs crate:main deps:std
345 impl std::ops::Not for Bar {
355 //- /std.rs crate:std
356 #[prelude_import] use ops::*;
368 fn infer_from_bound_1() {
373 impl<U> Trait<U> for S<U> {}
374 fn foo<T: Trait<u32>>(t: T) {}
384 fn infer_from_bound_2() {
389 impl<U> Trait<U> for S<U> {}
390 fn foo<U, T: Trait<U>>(t: T) -> U { loop {} }
400 fn trait_default_method_self_bound_implements_trait() {
401 cov_mark::check!(trait_self_implements_self);
405 fn foo(&self) -> i64;
406 fn bar(&self) -> () {
408 // ^^^^^^^^^^ type: i64
415 fn trait_default_method_self_bound_implements_super_trait() {
419 fn foo(&self) -> i64;
421 trait Trait: SuperTrait {
422 fn bar(&self) -> () {
424 // ^^^^^^^^^^ type: 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;
442 let y: <T as Iterable>::Item = u;
443 // ^ Iterable::Item<T>
445 // ^ Iterable::Item<T>
446 let a: <T>::Item = u;
447 // ^ Iterable::Item<T>
453 fn infer_return_associated_type() {
460 impl Iterable for S { type Item = u32; }
461 fn foo1<T: Iterable>(t: T) -> T::Item { loop {} }
462 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item { loop {} }
463 fn foo3<T: Iterable>(t: T) -> <T>::Item { loop {} }
476 fn associated_type_shorthand_from_method_bound() {
484 fn foo(self) -> T::Item where T: Iterable { loop {} }
486 fn test<T: Iterable>() {
489 // ^^^^^^^ Iterable::Item<T>
495 fn associated_type_shorthand_from_self_issue_12484() {
503 fn test(a: Self::A, _: impl Bar) {
512 fn infer_associated_type_bound() {
518 fn test<T: Iterable<Item=u32>>() {
519 let y: T::Item = unknown;
526 fn infer_const_body() {
527 // FIXME make check_types work with other bodies
530 const A: u32 = 1 + 1;
531 static B: u64 = { let x = 1; x };
537 38..54 '{ let ...1; x }': u64
546 fn tuple_struct_fields() {
556 37..86 '{ ... a.1 }': u64
558 51..52 'S': S(i32, u64) -> S
572 fn tuple_struct_with_fn() {
575 struct S(fn(u32) -> u64);
582 43..101 '{ ...0(2) }': u64
584 57..58 'S': S(fn(u32) -> u64) -> S
585 57..67 'S(|i| 2*i)': S
586 59..66 '|i| 2*i': |u32| -> u64
593 81..84 'a.0': fn(u32) -> u64
597 93..96 'a.0': fn(u32) -> u64
605 fn indexing_arrays() {
607 "fn main() { &mut [9][2]; }",
609 10..26 '{ &mut...[2]; }': ()
610 12..23 '&mut [9][2]': &mut {unknown}
611 17..20 '[9]': [i32; 1]
612 17..23 '[9][2]': {unknown}
620 fn infer_ops_index() {
627 impl core::ops::Index<u32> for Bar {
641 fn infer_ops_index_field() {
650 impl core::ops::Index<u32> for Bar {
656 let b = a[1u32].field;
664 fn infer_ops_index_field_autoderef() {
673 impl core::ops::Index<u32> for Bar {
679 let b = (&a[1u32]).field;
687 fn infer_ops_index_int() {
694 impl core::ops::Index<u32> for Bar {
699 impl core::ops::Index<Range> for Bar {
714 fn infer_ops_index_autoderef() {
717 //- minicore: index, slice
719 let a = &[1u32, 2, 3];
732 struct Arc<T: ?Sized>;
733 impl<T: ?Sized> core::ops::Deref for Arc<T> {
739 fn foo(&self) -> u128 { 0 }
744 } //^^^^^^^^^^^^^ (S, u128)
750 fn deref_trait_with_inference_var() {
754 struct Arc<T: ?Sized>;
755 fn new_arc<T: ?Sized>() -> Arc<T> { Arc }
756 impl<T: ?Sized> core::ops::Deref for Arc<T> {
774 fn deref_trait_infinite_recursion() {
780 impl core::ops::Deref for S {
786 } //^^^^^^^ {unknown}
792 fn deref_trait_with_question_mark_size() {
796 struct Arc<T: ?Sized>;
797 impl<T: ?Sized> core::ops::Deref for Arc<T> {
803 fn foo(&self) -> u128 { 0 }
808 } //^^^^^^^^^^^^^ (S, u128)
814 fn deref_trait_with_implicit_sized_requirement_on_inference_var() {
819 impl<T> core::ops::Deref for Foo<T> {
826 let _: Foo<u8> = foo;
833 fn obligation_from_function_clause() {
839 impl Trait<u32> for S {}
841 fn foo<T: Trait<U>, U>(t: T) -> U { loop {} }
851 fn obligation_from_method_clause() {
858 impl Trait<isize> for S {}
862 fn foo<T: Trait<U>, U>(&self, t: T) -> U { loop {} }
873 fn obligation_from_self_method_clause() {
879 impl Trait<i64> for S {}
882 fn foo<U>(&self) -> U where Self: Trait<U> { loop {} }
893 fn obligation_from_impl_clause() {
899 impl Trait<&str> for S {}
902 impl<U, T: Trait<U>> O<T> {
903 fn foo(&self) -> U { loop {} }
914 fn generic_param_env_1() {
918 trait Trait { fn foo(self) -> u128; }
921 impl<T> Trait for T where T: Clone {}
922 fn test<T: Clone>(t: T) { t.foo(); }
929 fn generic_param_env_1_not_met() {
934 trait Trait { fn foo(self) -> u128; }
937 impl<T> Trait for T where T: Clone {}
938 fn test<T>(t: T) { t.foo(); }
945 fn generic_param_env_2() {
948 trait Trait { fn foo(self) -> u128; }
951 fn test<T: Trait>(t: T) { t.foo(); }
958 fn generic_param_env_2_not_met() {
961 trait Trait { fn foo(self) -> u128; }
964 fn test<T>(t: T) { t.foo(); }
971 fn generic_param_env_deref() {
976 impl<T> core::ops::Deref for T where T: Trait {
979 fn test<T: Trait>(t: T) { *t; }
986 fn associated_type_placeholder() {
987 // 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].
994 pub struct RefMutL<T>;
996 impl<T> ApplyL for RefMutL<T> {
997 type Out = <T as ApplyL>::Out;
1000 fn test<T: ApplyL>() {
1001 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
1003 } //^ ApplyL::Out<T>
1009 fn associated_type_placeholder_2() {
1015 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
1017 fn test<T: ApplyL>(t: T) {
1020 } //^ ApplyL::Out<T>
1026 fn argument_impl_trait() {
1027 check_infer_with_mismatches(
1032 fn foo2(&self) -> i64;
1034 fn bar(x: impl Trait<u16>) {}
1036 impl<T> Trait<T> for S<T> {}
1038 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
1051 29..33 'self': &Self
1052 54..58 'self': &Self
1053 77..78 'x': impl Trait<u16>
1055 154..155 'x': impl Trait<u64>
1056 174..175 'y': &impl Trait<u32>
1057 195..323 '{ ...2(); }': ()
1058 201..202 'x': impl Trait<u64>
1059 208..209 'y': &impl Trait<u32>
1060 219..220 'z': S<u16>
1061 223..224 'S': S<u16>(u16) -> S<u16>
1062 223..227 'S(1)': S<u16>
1064 233..236 'bar': fn bar(S<u16>)
1065 233..239 'bar(z)': ()
1066 237..238 'z': S<u16>
1067 245..246 'x': impl Trait<u64>
1068 245..252 'x.foo()': u64
1069 258..259 'y': &impl Trait<u32>
1070 258..265 'y.foo()': u32
1071 271..272 'z': S<u16>
1072 271..278 'z.foo()': u16
1073 284..285 'x': impl Trait<u64>
1074 284..292 'x.foo2()': i64
1075 298..299 'y': &impl Trait<u32>
1076 298..306 'y.foo2()': i64
1077 312..313 'z': S<u16>
1078 312..320 'z.foo2()': i64
1084 fn argument_impl_trait_type_args_1() {
1085 check_infer_with_mismatches(
1090 // this function has an implicit Self param, an explicit type param,
1091 // and an implicit impl Trait param!
1092 fn bar<T>(x: impl Trait) -> T { loop {} }
1094 fn foo<T>(x: impl Trait) -> T { loop {} }
1105 <F as Foo>::bar::<u32>(S);
1109 foo::<u32, i32>(S); // we should ignore the extraneous i32
1112 155..156 'x': impl Trait
1113 175..186 '{ loop {} }': T
1114 177..184 'loop {}': !
1116 199..200 'x': impl Trait
1117 219..230 '{ loop {} }': T
1118 221..228 'loop {}': !
1120 300..509 '{ ... i32 }': ()
1121 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1122 306..317 'Foo::bar(S)': {unknown}
1124 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1125 323..341 '<F as ...bar(S)': {unknown}
1127 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1128 347..356 'F::bar(S)': {unknown}
1130 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1131 362..380 'Foo::b...32>(S)': u32
1133 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1134 386..411 '<F as ...32>(S)': u32
1136 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1137 418..424 'foo(S)': {unknown}
1139 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1140 430..443 'foo::<u32>(S)': u32
1142 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1143 449..467 'foo::<...32>(S)': u32
1150 fn argument_impl_trait_type_args_2() {
1151 check_infer_with_mismatches(
1159 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1165 F::<u32>.foo::<i32>(S);
1166 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1170 93..94 'x': impl Trait
1171 118..129 '{ loop {} }': (T, U)
1172 120..127 'loop {}': !
1174 143..283 '{ ...ored }': ()
1175 149..150 'F': F<{unknown}>
1176 149..157 'F.foo(S)': ({unknown}, {unknown})
1178 163..171 'F::<u32>': F<u32>
1179 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1181 184..192 'F::<u32>': F<u32>
1182 184..206 'F::<u3...32>(S)': (u32, i32)
1184 212..220 'F::<u32>': F<u32>
1185 212..239 'F::<u3...32>(S)': (u32, i32)
1192 fn argument_impl_trait_to_fn_pointer() {
1193 check_infer_with_mismatches(
1197 fn foo(x: impl Trait) { loop {} }
1202 let f: fn(S) -> () = foo;
1205 22..23 'x': impl Trait
1206 37..48 '{ loop {} }': ()
1209 90..123 '{ ...foo; }': ()
1211 117..120 'foo': fn foo(S)
1223 fn foo2(&self) -> i64;
1225 fn bar() -> impl Trait<u64> {}
1227 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1239 29..33 'self': &Self
1240 54..58 'self': &Self
1242 110..111 'x': impl Trait<u64>
1243 130..131 'y': &impl Trait<u64>
1244 151..268 '{ ...2(); }': ()
1245 157..158 'x': impl Trait<u64>
1246 164..165 'y': &impl Trait<u64>
1247 175..176 'z': impl Trait<u64>
1248 179..182 'bar': fn bar() -> impl Trait<u64>
1249 179..184 'bar()': impl Trait<u64>
1250 190..191 'x': impl Trait<u64>
1251 190..197 'x.foo()': u64
1252 203..204 'y': &impl Trait<u64>
1253 203..210 'y.foo()': u64
1254 216..217 'z': impl Trait<u64>
1255 216..223 'z.foo()': u64
1256 229..230 'x': impl Trait<u64>
1257 229..237 'x.foo2()': i64
1258 243..244 'y': &impl Trait<u64>
1259 243..251 'y.foo2()': i64
1260 257..258 'z': impl Trait<u64>
1261 257..265 'z.foo2()': i64
1267 fn simple_return_pos_impl_trait() {
1268 cov_mark::check!(lower_rpit);
1275 fn bar() -> impl Trait<u64> { loop {} }
1282 29..33 'self': &Self
1283 71..82 '{ loop {} }': !
1286 94..129 '{ ...o(); }': ()
1287 104..105 'a': impl Trait<u64>
1288 108..111 'bar': fn bar() -> impl Trait<u64>
1289 108..113 'bar()': impl Trait<u64>
1290 119..120 'a': impl Trait<u64>
1291 119..126 'a.foo()': u64
1297 fn more_return_pos_impl_trait() {
1303 fn next(&mut self) -> Self::Item;
1308 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1309 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1315 let (c, d) = baz(1u128);
1320 49..53 'self': &mut Self
1321 101..105 'self': &Self
1322 184..195 '{ loop {} }': ({unknown}, {unknown})
1323 186..193 'loop {}': !
1326 268..279 '{ loop {} }': ({unknown}, {unknown})
1327 270..277 'loop {}': !
1329 291..413 '{ ...o(); }': ()
1330 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1331 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1332 305..306 'b': impl Trait<u64>
1333 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1334 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1335 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1336 321..329 'a.next()': impl Trait<u32>
1337 321..335 'a.next().foo()': u32
1338 341..342 'b': impl Trait<u64>
1339 341..348 'b.foo()': u64
1340 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1341 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1342 362..363 'd': impl Trait<u128>
1343 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1344 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1345 371..376 '1u128': u128
1346 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1347 383..391 'c.next()': impl Trait<u128>
1348 383..397 'c.next().foo()': u128
1349 403..404 'd': impl Trait<u128>
1350 403..410 'd.foo()': u128
1356 fn infer_from_return_pos_impl_trait() {
1357 check_infer_with_mismatches(
1359 //- minicore: fn, sized
1362 impl<T> Trait<T> for Bar<T> {}
1363 fn foo<const C: u8, T>() -> (impl FnOnce(&str, T), impl Trait<u8>) {
1364 (|input, t| {}, Bar(C))
1368 134..165 '{ ...(C)) }': (|&str, T| -> (), Bar<u8>)
1369 140..163 '(|inpu...ar(C))': (|&str, T| -> (), Bar<u8>)
1370 141..154 '|input, t| {}': |&str, T| -> ()
1371 142..147 'input': &str
1374 156..159 'Bar': Bar<u8>(u8) -> Bar<u8>
1375 156..162 'Bar(C)': Bar<u8>
1388 fn foo2(&self) -> i64;
1390 fn bar() -> dyn Trait<u64> {}
1392 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1404 29..33 'self': &Self
1405 54..58 'self': &Self
1406 97..99 '{}': dyn Trait<u64>
1407 109..110 'x': dyn Trait<u64>
1408 128..129 'y': &dyn Trait<u64>
1409 148..265 '{ ...2(); }': ()
1410 154..155 'x': dyn Trait<u64>
1411 161..162 'y': &dyn Trait<u64>
1412 172..173 'z': dyn Trait<u64>
1413 176..179 'bar': fn bar() -> dyn Trait<u64>
1414 176..181 'bar()': dyn Trait<u64>
1415 187..188 'x': dyn Trait<u64>
1416 187..194 'x.foo()': u64
1417 200..201 'y': &dyn Trait<u64>
1418 200..207 'y.foo()': u64
1419 213..214 'z': dyn Trait<u64>
1420 213..220 'z.foo()': u64
1421 226..227 'x': dyn Trait<u64>
1422 226..234 'x.foo2()': i64
1423 240..241 'y': &dyn Trait<u64>
1424 240..248 'y.foo2()': i64
1425 254..255 'z': dyn Trait<u64>
1426 254..262 'z.foo2()': i64
1432 fn dyn_trait_in_impl() {
1437 fn foo(&self) -> (T, U);
1440 impl<T, U> S<T, U> {
1441 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1443 trait Trait2<T, U> {
1444 fn baz(&self) -> (T, U);
1446 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1448 fn test(s: S<u32, i32>) {
1452 32..36 'self': &Self
1453 102..106 'self': &S<T, U>
1454 128..139 '{ loop {} }': &dyn Trait<T, U>
1455 130..137 'loop {}': !
1457 175..179 'self': &Self
1458 251..252 's': S<u32, i32>
1459 267..289 '{ ...z(); }': ()
1460 273..274 's': S<u32, i32>
1461 273..280 's.bar()': &dyn Trait<u32, i32>
1462 273..286 's.bar().baz()': (u32, i32)
1468 fn dyn_trait_bare() {
1473 fn foo(&self) -> u64;
1475 fn bar() -> Trait {}
1477 fn test(x: Trait, y: &Trait) -> u64 {
1486 26..30 'self': &Self
1487 60..62 '{}': dyn Trait
1488 72..73 'x': dyn Trait
1489 82..83 'y': &dyn Trait
1490 100..175 '{ ...o(); }': u64
1491 106..107 'x': dyn Trait
1492 113..114 'y': &dyn Trait
1493 124..125 'z': dyn Trait
1494 128..131 'bar': fn bar() -> dyn Trait
1495 128..133 'bar()': dyn Trait
1496 139..140 'x': dyn Trait
1497 139..146 'x.foo()': u64
1498 152..153 'y': &dyn Trait
1499 152..159 'y.foo()': u64
1500 165..166 'z': dyn Trait
1501 165..172 'z.foo()': u64
1505 check_infer_with_mismatches(
1507 //- minicore: fn, coerce_unsized
1514 f(&|number| number.foo());
1520 47..48 '_': &dyn Fn(S)
1522 71..105 '{ ...()); }': ()
1523 77..78 'f': fn f(&dyn Fn(S))
1524 77..102 'f(&|nu...foo())': ()
1525 79..101 '&|numb....foo()': &|S| -> ()
1526 80..101 '|numbe....foo()': |S| -> ()
1529 89..101 'number.foo()': ()
1541 a: impl Trait + 'lifetime,
1544 d: impl ('lifetime),
1546 f: impl Trait + ?Sized
1550 28..29 'a': impl Trait
1551 59..60 'b': impl Sized
1552 82..83 'c': impl Trait
1553 103..104 'd': impl Sized
1554 128..129 'e': impl ?Sized
1555 148..149 'f': impl Trait + ?Sized
1562 fn error_bound_chalk() {
1566 fn foo(&self) -> u32 { 0 }
1569 fn test(x: (impl Trait + UnknownTrait)) {
1577 fn assoc_type_bindings() {
1585 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1586 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1587 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1590 impl<T> Trait for S<T> { type Type = T; }
1592 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1603 77..79 '{}': Trait::Type<T>
1610 262..263 'y': impl Trait<Type = i64>
1611 289..397 '{ ...r>); }': ()
1612 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1613 295..301 'get(x)': u32
1615 307..311 'get2': fn get2<u32, T>(T) -> u32
1616 307..314 'get2(x)': u32
1618 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1619 320..326 'get(y)': i64
1620 324..325 'y': impl Trait<Type = i64>
1621 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1622 332..339 'get2(y)': i64
1623 337..338 'y': impl Trait<Type = i64>
1624 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1625 345..356 'get(set(S))': u64
1626 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1627 349..355 'set(S)': S<u64>
1628 353..354 'S': S<u64>
1629 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1630 362..374 'get2(set(S))': u64
1631 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1632 367..373 'set(S)': S<u64>
1633 371..372 'S': S<u64>
1634 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1635 380..394 'get2(S::<str>)': str
1636 385..393 'S::<str>': S<str>
1642 fn impl_trait_assoc_binding_projection_bug() {
1645 //- minicore: iterator
1646 pub trait Language {
1649 pub enum RustLanguage {}
1650 impl Language for RustLanguage {
1651 type Kind = SyntaxKind;
1653 struct SyntaxNode<L> {}
1654 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1657 fn clone(&self) -> Self;
1660 fn api_walkthrough() {
1663 } //^^^^^^^^^^^^ {unknown}
1670 fn projection_eq_within_chalk() {
1679 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1681 fn test<T: Trait1<Type = u32>>(x: T) {
1687 169..185 '{ ...o(); }': ()
1689 175..182 'x.foo()': u32
1695 fn where_clause_trait_in_scope_for_method_resolution() {
1700 fn foo(&self) -> u32 { 0 }
1704 fn test<T: foo::Trait>(x: T) {
1712 fn super_trait_method_resolution() {
1717 fn foo(&self) -> u32 {}
1720 trait Trait1: foo::SuperTrait {}
1721 trait Trait2 where Self: foo::SuperTrait {}
1723 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1728 49..53 'self': &Self
1732 193..222 '{ ...o(); }': ()
1734 199..206 'x.foo()': u32
1736 212..219 'y.foo()': u32
1742 fn super_trait_impl_trait_method_resolution() {
1748 fn foo(&self) -> u32 {}
1751 trait Trait1: foo::SuperTrait {}
1753 fn test(x: &impl Trait1) {
1757 49..53 'self': &Self
1759 115..116 'x': &impl Trait1
1760 132..148 '{ ...o(); }': ()
1761 138..139 'x': &impl Trait1
1762 138..145 'x.foo()': u32
1768 fn super_trait_cycle() {
1769 // This just needs to not crash
1775 fn test<T: A>(x: T) {
1781 49..65 '{ ...o(); }': ()
1783 55..62 'x.foo()': {unknown}
1789 fn super_trait_assoc_type_bounds() {
1792 trait SuperTrait { type Type; }
1793 trait Trait where Self: SuperTrait {}
1795 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1796 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1799 impl<T> SuperTrait for S<T> { type Type = T; }
1800 impl<T> Trait for S<T> {}
1811 258..279 '{ ...S)); }': ()
1812 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1813 264..276 'get2(set(S))': u64
1814 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1815 269..275 'set(S)': S<u64>
1816 273..274 'S': S<u64>
1823 check_infer_with_mismatches(
1825 trait FnOnce<Args> {
1828 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1831 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1832 f.call_once((1, 2));
1838 155..183 '{ ...2)); }': ()
1840 161..180 'f.call...1, 2))': u128
1841 173..179 '(1, 2)': (u32, u64)
1849 fn fn_ptr_and_item() {
1850 check_infer_with_mismatches(
1853 trait FnOnce<Args> {
1856 fn call_once(self, args: Args) -> Self::Output;
1865 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1866 fn foo(&self) -> (A1, R) { loop {} }
1869 enum Opt<T> { None, Some(T) }
1871 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1875 let bar: Bar<fn(u8) -> u32>;
1879 let f: fn(u8) -> u32;
1885 139..143 'self': &Self
1886 243..247 'self': &Bar<F>
1887 260..271 '{ loop {} }': (A1, R)
1888 262..269 'loop {}': !
1890 355..359 'self': Opt<T>
1892 377..388 '{ loop {} }': Opt<U>
1893 379..386 'loop {}': !
1895 402..518 '{ ...(f); }': ()
1896 412..415 'bar': Bar<fn(u8) -> u32>
1897 441..444 'bar': Bar<fn(u8) -> u32>
1898 441..450 'bar.foo()': (u8, u32)
1899 461..464 'opt': Opt<u8>
1900 483..484 'f': fn(u8) -> u32
1901 505..508 'opt': Opt<u8>
1902 505..515 'opt.map(f)': Opt<u32>
1903 513..514 'f': fn(u8) -> u32
1909 fn fn_trait_deref_with_ty_default() {
1912 //- minicore: deref, fn
1916 fn foo(&self) -> usize {}
1919 struct Lazy<T, F = fn() -> T>(F);
1921 impl<T, F> Lazy<T, F> {
1922 pub fn new(f: F) -> Lazy<T, F> {}
1925 impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> {
1930 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1931 let r1 = lazy1.foo();
1933 fn make_foo_fn() -> Foo {}
1934 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1935 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1936 let r2 = lazy2.foo();
1942 151..153 '{}': Lazy<T, F>
1943 251..497 '{ ...o(); }': ()
1944 261..266 'lazy1': Lazy<Foo, || -> Foo>
1945 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1946 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1947 293..299 '|| Foo': || -> Foo
1949 310..312 'r1': usize
1950 315..320 'lazy1': Lazy<Foo, || -> Foo>
1951 315..326 'lazy1.foo()': usize
1952 368..383 'make_foo_fn_ptr': fn() -> Foo
1953 399..410 'make_foo_fn': fn make_foo_fn() -> Foo
1954 420..425 'lazy2': Lazy<Foo, fn() -> Foo>
1955 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1956 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1957 452..467 'make_foo_fn_ptr': fn() -> Foo
1958 478..480 'r2': usize
1959 483..488 'lazy2': Lazy<Foo, fn() -> Foo>
1960 483..494 'lazy2.foo()': usize
1968 check_infer_with_mismatches(
1971 enum Option<T> { Some(T), None }
1973 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1977 let x = Option::Some(1u32);
1980 let y: Option<i64> = x.map(|_v| 1);
1983 86..90 'self': Option<T>
1985 111..122 '{ loop {} }': Option<U>
1986 113..120 'loop {}': !
1988 136..255 '{ ... 1); }': ()
1989 146..147 'x': Option<u32>
1990 150..162 'Option::Some': Some<u32>(u32) -> Option<u32>
1991 150..168 'Option...(1u32)': Option<u32>
1992 163..167 '1u32': u32
1993 174..175 'x': Option<u32>
1994 174..190 'x.map(...v + 1)': Option<u32>
1995 180..189 '|v| v + 1': |u32| -> u32
1998 184..189 'v + 1': u32
2000 196..197 'x': Option<u32>
2001 196..212 'x.map(... 1u64)': Option<u64>
2002 202..211 '|_v| 1u64': |u32| -> u64
2004 207..211 '1u64': u64
2005 222..223 'y': Option<i64>
2006 239..240 'x': Option<u32>
2007 239..252 'x.map(|_v| 1)': Option<i64>
2008 245..251 '|_v| 1': |u32| -> i64
2019 //- minicore: add, fn
2021 impl core::ops::Add for u64 {
2023 fn add(self, rhs: u64) -> Self::Output {0}
2026 impl core::ops::Add for u128 {
2028 fn add(self, rhs: u128) -> Self::Output {0}
2031 fn test<F: FnOnce(u32) -> u64>(f: F) {
2037 //^^^^^^^^^ |u64| -> u64
2040 let h = |v| 1u128 + v;
2041 //^^^^^^^^^^^^^ |u128| -> u128
2047 fn closure_as_argument_inference_order() {
2048 check_infer_with_mismatches(
2051 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
2052 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
2056 fn method(self) -> u64;
2058 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
2059 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
2063 let x1 = foo1(S, |s| s.method());
2064 let x2 = foo2(|s| s.method(), S);
2065 let x3 = S.foo1(S, |s| s.method());
2066 let x4 = S.foo2(|s| s.method(), S);
2071 50..61 '{ loop {} }': U
2076 112..123 '{ loop {} }': U
2077 114..121 'loop {}': !
2083 233..244 '{ loop {} }': U
2084 235..242 'loop {}': !
2089 305..316 '{ loop {} }': U
2090 307..314 'loop {}': !
2092 330..489 '{ ... S); }': ()
2094 345..349 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2095 345..368 'foo1(S...hod())': u64
2097 353..367 '|s| s.method()': |S| -> u64
2100 357..367 's.method()': u64
2102 383..387 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2103 383..406 'foo2(|...(), S)': u64
2104 388..402 '|s| s.method()': |S| -> u64
2107 392..402 's.method()': u64
2111 421..446 'S.foo1...hod())': u64
2113 431..445 '|s| s.method()': |S| -> u64
2116 435..445 's.method()': u64
2119 461..486 'S.foo2...(), S)': u64
2120 468..482 '|s| s.method()': |S| -> u64
2123 472..482 's.method()': u64
2130 fn fn_item_fn_trait() {
2138 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2142 } //^^^^^^^^^^^^^^^^^^ S
2148 fn unselected_projection_in_trait_env_1() {
2157 fn foo(&self) -> u32;
2160 fn test<T: Trait>() where T::Item: Trait2 {
2161 let x: T::Item = no_matter;
2169 fn unselected_projection_in_trait_env_2() {
2177 fn foo(&self) -> u32;
2180 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2181 let x: T::Item = no_matter;
2189 fn unselected_projection_on_impl_self() {
2196 fn f(&self, x: Self::Item);
2203 fn f(&self, x: Self::Item) { let y = x; }
2210 fn f(&self, x: <Self>::Item) { let y = x; }
2213 40..44 'self': &Self
2214 46..47 'x': Trait::Item<Self>
2217 147..161 '{ let y = x; }': ()
2220 228..232 'self': &S2
2222 251..265 '{ let y = x; }': ()
2230 fn unselected_projection_on_trait_self() {
2236 fn f(&self) -> Self::Item { loop {} }
2252 fn unselected_projection_chalk_fold() {
2256 trait Fold<I: Interner, TI = I> {
2260 struct Ty<I: Interner> {}
2261 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2262 type Result = Ty<TI>;
2265 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2272 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2274 } //^^^^^^^^^^^^^^^^^ Ty<I>
2280 fn trait_impl_self_ty() {
2289 impl Trait<Self> for S {}
2299 fn trait_impl_self_ty_cycle() {
2308 impl Trait for S<Self> {}
2312 } //^^^^^^^ {unknown}
2318 fn unselected_projection_in_trait_env_cycle_1() {
2319 // This is not a cycle, because the `T: Trait2<T::Item>` bound depends only on the `T: Trait`
2320 // bound, not on itself (since only `Trait` can define `Item`).
2329 fn test<T: Trait>() where T: Trait2<T::Item> {
2330 let x: T::Item = no_matter;
2331 } //^^^^^^^^^ Trait::Item<T>
2337 fn unselected_projection_in_trait_env_cycle_2() {
2338 // this is a legitimate cycle
2346 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2347 let x: T::Item = no_matter;
2348 } //^^^^^^^^^ {unknown}
2354 fn unselected_projection_in_trait_env_cycle_3() {
2355 // this is a cycle for rustc; we currently accept it
2364 fn test<T>() where T: Trait<OtherItem = T::Item> {
2365 let x: T::Item = no_matter;
2366 } //^^^^^^^^^ Trait::Item<T>
2372 fn unselected_projection_in_trait_env_no_cycle() {
2373 // this is not a cycle
2381 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2383 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2386 fn len(&self) -> usize;
2389 pub trait UnificationStoreMut: UnificationStoreBase {
2390 fn push(&mut self, value: Self::Key);
2393 fn test<T>(t: T) where T: UnificationStoreMut {
2398 } //^^^^^^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2404 fn inline_assoc_type_bounds_1() {
2410 trait OtherTrait<T> {
2414 // workaround for Chalk assoc type normalization problems
2416 impl<T: Iterator> Iterator for S<T> {
2417 type Item = <T as Iterator>::Item;
2420 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2421 let x: <S<I> as Iterator>::Item;
2429 fn inline_assoc_type_bounds_2() {
2436 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2437 let x: <<I as Iterator>::Item as Iterator>::Item;
2445 fn proc_macro_server_types() {
2448 macro_rules! with_api {
2449 ($S:ident, $self:ident, $m:ident) => {
2452 fn new() -> $S::TokenStream;
2459 macro_rules! associated_item {
2460 (type TokenStream) =>
2461 (type TokenStream: 'static;);
2463 (type Group: 'static;);
2464 ($($item:tt)*) => ($($item)*;)
2466 macro_rules! declare_server_traits {
2468 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2471 $(associated_item!(type $name);)*
2474 $(pub trait $name: Types {
2475 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2478 pub trait Server: Types $(+ $name)* {}
2479 impl<S: Types $(+ $name)*> Server for S {}
2483 with_api!(Self, self_, declare_server_traits);
2486 struct RustAnalyzer;
2487 impl Types for RustAnalyzer {
2488 type TokenStream = T;
2492 fn make<T>() -> T { loop {} }
2493 impl TokenStream for RustAnalyzer {
2494 fn new() -> Self::TokenStream {
2495 let group: Self::Group = make();
2500 1075..1086 '{ loop {} }': T
2501 1077..1084 'loop {}': !
2503 1157..1220 '{ ... }': T
2504 1171..1176 'group': G
2505 1192..1196 'make': fn make<G>() -> G
2506 1192..1198 'make()': G
2507 1208..1212 'make': fn make<T>() -> T
2508 1208..1214 'make()': T
2514 fn unify_impl_trait() {
2515 check_infer_with_mismatches(
2520 fn foo(x: impl Trait<u32>) { loop {} }
2521 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2524 impl<T> Trait<T> for S<T> {}
2526 fn default<T>() -> T { loop {} }
2528 fn test() -> impl Trait<i32> {
2529 let s1 = S(default());
2531 let x: i32 = bar(S(default()));
2535 26..27 'x': impl Trait<u32>
2536 46..57 '{ loop {} }': ()
2539 68..69 'x': impl Trait<T>
2540 91..102 '{ loop {} }': T
2541 93..100 'loop {}': !
2543 171..182 '{ loop {} }': T
2544 173..180 'loop {}': !
2546 213..309 '{ ...t()) }': S<i32>
2547 223..225 's1': S<u32>
2548 228..229 'S': S<u32>(u32) -> S<u32>
2549 228..240 'S(default())': S<u32>
2550 230..237 'default': fn default<u32>() -> u32
2551 230..239 'default()': u32
2552 246..249 'foo': fn foo(S<u32>)
2553 246..253 'foo(s1)': ()
2554 250..252 's1': S<u32>
2556 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2557 272..289 'bar(S(...lt()))': i32
2558 276..277 'S': S<i32>(i32) -> S<i32>
2559 276..288 'S(default())': S<i32>
2560 278..285 'default': fn default<i32>() -> i32
2561 278..287 'default()': i32
2562 295..296 'S': S<i32>(i32) -> S<i32>
2563 295..307 'S(default())': S<i32>
2564 297..304 'default': fn default<i32>() -> i32
2565 297..306 'default()': i32
2571 fn assoc_types_from_bounds() {
2590 f::<(), _>(|z| { z; });
2595 132..163 '{ ... }); }': ()
2596 138..148 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2597 138..160 'f::<()... z; })': ()
2598 149..159 '|z| { z; }': |&()| -> ()
2600 153..159 '{ z; }': ()
2607 fn associated_type_bound() {
2611 type Item: OtherTrait<u32>;
2613 pub trait OtherTrait<T> {
2617 // this is just a workaround for chalk#234
2619 impl<T: Trait> Trait for S<T> {
2620 type Item = <T as Trait>::Item;
2623 fn test<T: Trait>() {
2624 let y: <S<T> as Trait>::Item = no_matter;
2632 fn dyn_trait_through_chalk() {
2636 struct Box<T: ?Sized> {}
2637 impl<T: ?Sized> core::ops::Deref for Box<T> {
2644 fn test(x: Box<dyn Trait>) {
2652 fn string_to_owned() {
2658 fn to_owned(&self) -> Self::Owned;
2660 impl ToOwned for str {
2661 type Owned = String;
2665 } //^^^^^^^^^^^^^^^^ String
2671 fn iterator_chain() {
2672 check_infer_with_mismatches(
2674 //- minicore: fn, option
2675 pub trait Iterator {
2678 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2680 F: FnMut(Self::Item) -> Option<B>,
2683 fn for_each<F>(self, f: F)
2685 F: FnMut(Self::Item),
2689 pub trait IntoIterator {
2691 type IntoIter: Iterator<Item = Self::Item>;
2692 fn into_iter(self) -> Self::IntoIter;
2695 pub struct FilterMap<I, F> { }
2696 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2698 F: FnMut(I::Item) -> Option<B>,
2703 #[stable(feature = "rust1", since = "1.0.0")]
2704 impl<I: Iterator> IntoIterator for I {
2705 type Item = I::Item;
2708 fn into_iter(self) -> I {
2715 fn new() -> Self { loop {} }
2718 impl<T> IntoIterator for Vec<T> {
2720 type IntoIter = IntoIter<T>;
2723 pub struct IntoIter<T> { }
2724 impl<T> Iterator for IntoIter<T> {
2729 Vec::<i32>::new().into_iter()
2730 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2731 .for_each(|y| { y; });
2736 152..163 '{ loop {} }': FilterMap<Self, F>
2737 154..161 'loop {}': !
2739 184..188 'self': Self
2741 240..251 '{ loop {} }': ()
2742 242..249 'loop {}': !
2744 360..364 'self': Self
2746 700..720 '{ ... }': I
2748 779..790 '{ loop {} }': Vec<T>
2749 781..788 'loop {}': !
2751 977..1104 '{ ... }); }': ()
2752 983..998 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2753 983..1000 'Vec::<...:new()': Vec<i32>
2754 983..1012 'Vec::<...iter()': IntoIter<i32>
2755 983..1075 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2756 983..1101 'Vec::<... y; })': ()
2757 1029..1074 '|x| if...None }': |i32| -> Option<u32>
2759 1033..1074 'if x >...None }': Option<u32>
2761 1036..1041 'x > 0': bool
2763 1042..1060 '{ Some...u32) }': Option<u32>
2764 1044..1048 'Some': Some<u32>(u32) -> Option<u32>
2765 1044..1058 'Some(x as u32)': Option<u32>
2767 1049..1057 'x as u32': u32
2768 1066..1074 '{ None }': Option<u32>
2769 1068..1072 'None': Option<u32>
2770 1090..1100 '|y| { y; }': |u32| -> ()
2772 1094..1100 '{ y; }': ()
2795 fn foo() -> Self::Output;
2799 type Output = T::OutputA;
2800 fn foo() -> Self::Output { loop {} }
2811 fn trait_object_no_coercion() {
2812 check_infer_with_mismatches(
2816 fn foo(x: &dyn Foo) {}
2818 fn test(x: &dyn Foo) {
2822 21..22 'x': &dyn Foo
2824 46..47 'x': &dyn Foo
2825 59..74 '{ foo(x); }': ()
2826 65..68 'foo': fn foo(&dyn Foo)
2828 69..70 'x': &dyn Foo
2835 check_infer_with_mismatches(
2839 impl Copy for IsCopy {}
2842 trait Test { fn test(&self) -> bool; }
2843 impl<T: Copy> Test for T {}
2848 (IsCopy, IsCopy).test();
2849 (IsCopy, NotCopy).test();
2852 78..82 'self': &Self
2853 134..235 '{ ...t(); }': ()
2854 140..146 'IsCopy': IsCopy
2855 140..153 'IsCopy.test()': bool
2856 159..166 'NotCopy': NotCopy
2857 159..173 'NotCopy.test()': {unknown}
2858 179..195 '(IsCop...sCopy)': (IsCopy, IsCopy)
2859 179..202 '(IsCop...test()': bool
2860 180..186 'IsCopy': IsCopy
2861 188..194 'IsCopy': IsCopy
2862 208..225 '(IsCop...tCopy)': (IsCopy, NotCopy)
2863 208..232 '(IsCop...test()': {unknown}
2864 209..215 'IsCopy': IsCopy
2865 217..224 'NotCopy': NotCopy
2871 fn builtin_fn_def_copy() {
2872 check_infer_with_mismatches(
2876 fn bar<T: Copy>(T) -> T {}
2877 struct Struct(usize);
2878 enum Enum { Variant(usize) }
2880 trait Test { fn test(&self) -> bool; }
2881 impl<T: Copy> Test for T {}
2887 Enum::Variant.test();
2891 28..29 'T': {unknown}
2893 36..38: expected T, got ()
2894 113..117 'self': &Self
2895 169..249 '{ ...t(); }': ()
2896 175..178 'foo': fn foo()
2897 175..185 'foo.test()': bool
2898 191..194 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2899 191..201 'bar.test()': bool
2900 207..213 'Struct': Struct(usize) -> Struct
2901 207..220 'Struct.test()': bool
2902 226..239 'Enum::Variant': Variant(usize) -> Enum
2903 226..246 'Enum::...test()': bool
2909 fn builtin_fn_ptr_copy() {
2910 check_infer_with_mismatches(
2913 trait Test { fn test(&self) -> bool; }
2914 impl<T: Copy> Test for T {}
2916 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2922 22..26 'self': &Self
2924 86..88 'f2': fn(usize) -> u8
2925 107..109 'f3': fn(u8, u8) -> &u8
2926 130..178 '{ ...t(); }': ()
2928 136..145 'f1.test()': bool
2929 151..153 'f2': fn(usize) -> u8
2930 151..160 'f2.test()': bool
2931 166..168 'f3': fn(u8, u8) -> &u8
2932 166..175 'f3.test()': bool
2938 fn builtin_sized() {
2939 check_infer_with_mismatches(
2942 trait Test { fn test(&self) -> bool; }
2943 impl<T: Sized> Test for T {}
2947 (*"foo").test(); // not Sized
2949 (1u8, *"foo").test(); // not Sized
2952 22..26 'self': &Self
2953 79..194 '{ ...ized }': ()
2955 85..95 '1u8.test()': bool
2956 101..116 '(*"foo").test()': {unknown}
2957 102..108 '*"foo"': str
2958 103..108 '"foo"': &str
2959 135..145 '(1u8, 1u8)': (u8, u8)
2960 135..152 '(1u8, ...test()': bool
2963 158..171 '(1u8, *"foo")': (u8, str)
2964 158..178 '(1u8, ...test()': {unknown}
2966 164..170 '*"foo"': str
2967 165..170 '"foo"': &str
2973 fn integer_range_iterate() {
2976 //- /main.rs crate:main deps:core
2978 for x in 0..100 { x; }
2981 //- /core.rs crate:core
2983 pub struct Range<Idx> {
2990 pub trait Iterator {
2994 pub trait IntoIterator {
2996 type IntoIter: Iterator<Item = Self::Item>;
2999 impl<T> IntoIterator for T where T: Iterator {
3000 type Item = <T as Iterator>::Item;
3001 type IntoIter = Self;
3006 impl Step for i32 {}
3007 impl Step for i64 {}
3009 impl<A: Step> iter::Iterator for ops::Range<A> {
3017 fn infer_closure_arg() {
3028 let s = Option::None;
3029 let f = |x: Option<i32>| {};
3033 52..126 '{ ...)(s) }': ()
3034 62..63 's': Option<i32>
3035 66..78 'Option::None': Option<i32>
3036 88..89 'f': |Option<i32>| -> ()
3037 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
3038 93..94 'x': Option<i32>
3040 117..124 '(&f)(s)': ()
3041 118..120 '&f': &|Option<i32>| -> ()
3042 119..120 'f': |Option<i32>| -> ()
3043 122..123 's': Option<i32>
3049 fn dyn_fn_param_informs_call_site_closure_signature() {
3050 cov_mark::check!(dyn_fn_param_informs_call_site_closure_signature);
3053 //- minicore: fn, coerce_unsized
3056 fn inherent(&self) -> u8 { 0 }
3058 fn take_dyn_fn(f: &dyn Fn(S)) {}
3061 take_dyn_fn(&|x| { x.inherent(); });
3069 fn infer_fn_trait_arg() {
3070 check_infer_with_mismatches(
3072 //- minicore: fn, option
3073 fn foo<F, T>(f: F) -> T
3075 F: Fn(Option<i32>) -> T,
3083 59..89 '{ ...f(s) }': T
3084 69..70 's': Option<i32>
3085 73..77 'None': Option<i32>
3088 85..86 's': Option<i32>
3094 fn infer_box_fn_arg() {
3095 // The type mismatch is because we don't define Unsize and CoerceUnsized
3096 check_infer_with_mismatches(
3098 //- minicore: fn, deref, option
3099 #[lang = "owned_box"]
3100 pub struct Box<T: ?Sized> {
3104 impl<T: ?Sized> core::ops::Deref for Box<T> {
3107 fn deref(&self) -> &T {
3114 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3118 154..158 'self': &Box<T>
3119 166..193 '{ ... }': &T
3120 176..187 '&self.inner': &*mut T
3121 177..181 'self': &Box<T>
3122 177..187 'self.inner': *mut T
3123 206..296 '{ ...&s); }': ()
3124 216..217 's': Option<i32>
3125 220..224 'None': Option<i32>
3126 234..235 'f': Box<dyn FnOnce(&Option<i32>)>
3127 269..282 'box (|ps| {})': Box<|&Option<i32>| -> ()>
3128 274..281 '|ps| {}': |&Option<i32>| -> ()
3129 275..277 'ps': &Option<i32>
3131 288..289 'f': Box<dyn FnOnce(&Option<i32>)>
3132 288..293 'f(&s)': ()
3133 290..292 '&s': &Option<i32>
3134 291..292 's': Option<i32>
3135 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|&Option<i32>| -> ()>
3141 fn infer_dyn_fn_output() {
3146 let f: &dyn Fn() -> i32;
3154 fn infer_dyn_fn_once_output() {
3159 let f: dyn FnOnce() -> i32;
3167 fn variable_kinds_1() {
3170 trait Trait<T> { fn get(self, t: T) -> T; }
3172 impl Trait<u128> for S {}
3173 impl Trait<f32> for S {}
3185 fn variable_kinds_2() {
3188 trait Trait { fn get(self) -> Self; }
3189 impl Trait for u128 {}
3190 impl Trait for f32 {}
3202 fn underscore_import() {
3207 fn method(&self) -> u8 { 0 }
3212 impl crate::tr::Tr for Tr {}
3214 use crate::tr::Tr as _;
3229 fn method(&self) -> u8 { 0 }
3246 fn trait_in_scope_with_inner_item() {
3251 fn method(&self) -> u8 { 0 }
3266 46..50 'self': &Self
3269 115..185 '{ ... } }': ()
3270 132..183 '{ ... }': ()
3272 142..153 '().method()': u8
3278 fn inner_use_in_block() {
3283 fn method(&self) -> u8 { 0 }
3299 //^^^^^^^^^^^ {unknown}
3303 //^^^^^^^^^^^ {unknown}
3310 fn nested_inner_function_calling_self() {
3320 17..73 '{ ... } }': ()
3323 57..62 'inner': fn inner() -> S
3330 fn infer_default_trait_type_parameter() {
3335 trait Op<RHS=Self> {
3338 fn do_op(self, rhs: RHS) -> Self::Output;
3344 fn do_op(self, rhs: Self) -> Self::Output {
3359 186..206 '{ ... }': bool
3360 196..200 'true': bool
3361 220..277 '{ ...(y); }': ()
3368 264..274 'x.do_op(y)': bool
3375 fn qualified_path_as_qualified_trait() {
3385 fn boo() -> Self::Output {
3392 impl foo::Foo for F {
3395 impl foo::Bar for F {
3396 type Output = <F as foo::Foo>::Target;
3401 let x = <F as Bar>::boo();
3404 132..163 '{ ... }': Bar::Output<Self>
3405 146..153 'loop {}': !
3407 306..358 '{ ...o(); }': ()
3409 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3410 338..355 '<F as ...:boo()': ()
3416 fn renamed_extern_crate_in_block() {
3419 //- /lib.rs crate:lib deps:serde
3420 use serde::Deserialize;
3425 extern crate serde as _serde;
3426 impl _serde::Deserialize for Foo {
3427 fn deserialize() -> u8 { 0 }
3433 //^^^^^^^^^^^^^^^^^^ u8
3436 //- /serde.rs crate:serde
3438 pub trait Deserialize {
3439 fn deserialize() -> u8;
3445 fn bin_op_with_rhs_is_self_for_assoc_bound() {
3446 check_no_mismatches(
3448 fn repro<T>(t: T) -> bool
3451 T::Output: Convertable,
3453 let a = execute(&t).convert();
3454 let b = execute(&t).convert();
3456 let a = execute(&t).convert2();
3457 let b = execute(&t).convert2();
3460 fn execute<T>(t: &T) -> T::Output
3464 <T as Request>::output()
3467 type TraitSelf: PartialEq<Self::TraitSelf>;
3468 type AssocAsDefaultSelf: PartialEq;
3469 fn convert(self) -> Self::AssocAsDefaultSelf;
3470 fn convert2(self) -> Self::TraitSelf;
3474 fn output() -> Self::Output;
3481 fn bin_op_adt_with_rhs_primitive() {
3482 check_infer_with_mismatches(
3485 pub trait Add<Rhs = Self> {
3487 fn add(self, rhs: Rhs) -> Self::Output;
3490 struct Wrapper(u32);
3491 impl Add<u32> for Wrapper {
3493 fn add(self, rhs: u32) -> Wrapper {
3498 let wrapped = Wrapper(10);
3500 let res = wrapped + num;
3506 192..196 'self': Wrapper
3508 219..247 '{ ... }': Wrapper
3509 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3510 229..241 'Wrapper(rhs)': Wrapper
3512 259..345 '{ ...um; }': ()
3513 269..276 'wrapped': Wrapper
3514 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3515 279..290 'Wrapper(10)': Wrapper
3519 322..325 'res': Wrapper
3520 328..335 'wrapped': Wrapper
3521 328..341 'wrapped + num': Wrapper
3533 fn do_thing(&self) -> Self::Output;
3536 impl T for [u8; 4] {
3537 type Output = usize;
3538 fn do_thing(&self) -> Self::Output {
3543 impl T for [u8; 2] {
3545 fn do_thing(&self) -> Self::Output {
3552 let v2 = v.do_thing();
3554 let v4 = v3.do_thing();
3558 44..48 'self': &Self
3559 133..137 'self': &[u8; 4]
3560 155..172 '{ ... }': usize
3562 236..240 'self': &[u8; 2]
3563 258..275 '{ ... }': u8
3565 289..392 '{ ...g(); }': ()
3566 299..300 'v': [u8; 2]
3567 303..311 '[0u8; 2]': [u8; 2]
3571 326..327 'v': [u8; 2]
3572 326..338 'v.do_thing()': u8
3573 348..350 'v3': [u8; 4]
3574 353..361 '[0u8; 4]': [u8; 4]
3577 371..373 'v4': usize
3578 376..378 'v3': [u8; 4]
3579 376..389 'v3.do_thing()': usize
3585 fn const_generics() {
3590 fn do_thing(&self) -> Self::Output;
3593 impl<const L: usize> T for [u8; L] {
3594 type Output = [u8; L];
3595 fn do_thing(&self) -> Self::Output {
3602 let v2 = v.do_thing();
3606 44..48 'self': &Self
3607 151..155 'self': &[u8; L]
3608 173..194 '{ ... }': [u8; L]
3609 183..188 '*self': [u8; L]
3610 184..188 'self': &[u8; L]
3611 208..260 '{ ...g(); }': ()
3612 218..219 'v': [u8; 2]
3613 222..230 '[0u8; 2]': [u8; 2]
3616 240..242 'v2': [u8; 2]
3617 245..246 'v': [u8; 2]
3618 245..257 'v.do_thing()': [u8; 2]
3624 fn fn_returning_unit() {
3625 check_infer_with_mismatches(
3628 fn test<F: FnOnce()>(f: F) {
3633 27..51 '{ ...f(); }': ()
3642 fn trait_in_scope_of_trait_impl() {
3648 fn bar(self) -> usize { 0 }
3651 impl foo::Foo for u32 {
3653 let _x = self.bar();
3660 82..87 '{ 0 }': usize
3662 131..135 'self': u32
3663 137..173 '{ ... }': ()
3664 151..153 '_x': usize
3665 156..160 'self': u32
3666 156..166 'self.bar()': usize
3672 fn infer_async_ret_type() {
3675 //- minicore: future, result
3679 fn collect<B: Convert>(self) -> B {
3687 impl Convert for u32 {
3688 fn new() -> Self { 0 }
3691 async fn get_accounts() -> Result<u32, ()> {
3692 let ret = Fooey.collect();
3693 // ^^^^^^^^^^^^^^^ u32
3702 check!(block_local_impls);
3711 impl Trait<u32> for S {
3712 fn foo(&self) -> u32 { 0 }
3724 check!(block_local_impls);
3733 impl Trait<u32> for S {
3734 fn foo(&self) -> u32 { 0 }
3746 check!(block_local_impls);
3758 impl Trait<S1> for S2 {
3759 fn foo(&self) -> S1 { S1 }
3771 fn associated_type_sized_bounds() {
3776 trait IsSized { const IS_SIZED: Yes; }
3777 impl<T: Sized> IsSized for T { const IS_SIZED: Yes = Yes; }
3780 type Explicit: Sized;
3782 type Relaxed: ?Sized;
3785 F::Explicit::IS_SIZED;
3786 F::Implicit::IS_SIZED;
3787 F::Relaxed::IS_SIZED;
3792 212..295 '{ ...ZED; }': ()
3793 218..239 'F::Exp..._SIZED': Yes
3794 245..266 'F::Imp..._SIZED': Yes
3795 272..292 'F::Rel..._SIZED': {unknown}
3804 pub struct Key<K, V, P = (K, V)> {}
3811 impl<K, V> Policy for (K, V) {
3816 pub struct KeyMap<KEY> {}
3818 impl<P: Policy> KeyMap<Key<P::K, P::V, P>> {
3819 pub fn get(&self, key: &P::K) -> P::V {
3825 struct FunctionId {}
3828 let key_map: &KeyMap<Key<Fn, FunctionId>> = loop {};
3830 let result = key_map.get(key);
3838 fn dyn_multiple_auto_traits_in_different_order() {
3839 check_no_mismatches(
3844 fn f(t: &(dyn Sync + Send)) {}
3845 fn g(t: &(dyn Send + Sync)) {
3851 check_no_mismatches(
3857 fn f(t: &(dyn T + Send + Sync)) {}
3858 fn g(t: &(dyn Sync + T + Send)) {
3864 check_infer_with_mismatches(
3871 fn f(t: &(dyn T1 + T2 + Send + Sync)) {}
3872 fn g(t: &(dyn Sync + T2 + T1 + Send)) {
3877 68..69 't': &{unknown}
3879 109..110 't': &{unknown}
3880 142..155 '{ f(t); }': ()
3881 148..149 'f': fn f(&{unknown})
3883 150..151 't': &{unknown}
3887 check_no_mismatches(
3892 type Proj: Send + Sync;
3895 fn f(t: &(dyn T<Proj = ()> + Send + Sync)) {}
3896 fn g(t: &(dyn Sync + T<Proj = ()> + Send)) {
3904 fn dyn_multiple_projection_bounds() {
3905 check_no_mismatches(
3912 fn f(t: &dyn Trait<T = (), U = ()>) {}
3913 fn g(t: &dyn Trait<U = (), T = ()>) {
3925 fn f(t: &dyn Trait<T = (), T = ()>) {}
3932 fn dyn_duplicate_auto_trait() {
3933 check_no_mismatches(
3937 fn f(t: &(dyn Send + Send)) {}
3938 fn g(t: &(dyn Send)) {
3944 check_no_mismatches(
3949 fn f(t: &(dyn T + Send + Send)) {}
3950 fn g(t: &(dyn T + Send)) {