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 {
282 type IntoIter: Iterator<Item = Self::Item>;
290 pub use crate::iter::*;
294 //- /alloc.rs crate:alloc deps:core
296 pub mod collections {
299 pub fn new() -> Self { Vec {} }
300 pub fn push(&mut self, t: T) { }
303 impl<T> IntoIterator for Vec<T> {
305 type IntoIter = IntoIter<T>;
308 struct IntoIter<T> {}
309 impl<T> Iterator for IntoIter<T> {
321 //- /main.rs crate:main deps:std
325 impl std::ops::Neg for Bar {
335 //- /std.rs crate:std
336 #[prelude_import] use ops::*;
351 //- /main.rs crate:main deps:std
355 impl std::ops::Not for Bar {
365 //- /std.rs crate:std
366 #[prelude_import] use ops::*;
378 fn infer_from_bound_1() {
383 impl<U> Trait<U> for S<U> {}
384 fn foo<T: Trait<u32>>(t: T) {}
394 fn infer_from_bound_2() {
399 impl<U> Trait<U> for S<U> {}
400 fn foo<U, T: Trait<U>>(t: T) -> U { loop {} }
410 fn trait_default_method_self_bound_implements_trait() {
411 cov_mark
::check
!(trait_self_implements_self
);
415 fn foo(&self) -> i64;
416 fn bar(&self) -> () {
418 // ^^^^^^^^^^ type: i64
425 fn trait_default_method_self_bound_implements_super_trait() {
429 fn foo(&self) -> i64;
431 trait Trait: SuperTrait {
432 fn bar(&self) -> () {
434 // ^^^^^^^^^^ type: i64
441 fn infer_project_associated_type() {
448 impl Iterable for S { type Item = u32; }
449 fn test<T: Iterable>() {
450 let x: <S as Iterable>::Item = 1;
452 let y: <T as Iterable>::Item = u;
453 // ^ Iterable::Item<T>
455 // ^ Iterable::Item<T>
456 let a: <T>::Item = u;
457 // ^ Iterable::Item<T>
463 fn infer_return_associated_type() {
470 impl Iterable for S { type Item = u32; }
471 fn foo1<T: Iterable>(t: T) -> T::Item { loop {} }
472 fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item { loop {} }
473 fn foo3<T: Iterable>(t: T) -> <T>::Item { loop {} }
486 fn associated_type_shorthand_from_method_bound() {
494 fn foo(self) -> T::Item where T: Iterable { loop {} }
496 fn test<T: Iterable>() {
499 // ^^^^^^^ Iterable::Item<T>
505 fn associated_type_shorthand_from_self_issue_12484() {
513 fn test(a: Self::A, _: impl Bar) {
522 fn infer_associated_type_bound() {
528 fn test<T: Iterable<Item=u32>>() {
529 let y: T::Item = unknown;
536 fn infer_const_body() {
537 // FIXME make check_types work with other bodies
540 const A: u32 = 1 + 1;
541 static B: u64 = { let x = 1; x };
547 38..54 '{ let ...1; x }': u64
556 fn tuple_struct_fields() {
566 37..86 '{ ... a.1 }': u64
568 51..52 'S': S(i32, u64) -> S
582 fn tuple_struct_with_fn() {
585 struct S(fn(u32) -> u64);
592 43..101 '{ ...0(2) }': u64
594 57..58 'S': S(fn(u32) -> u64) -> S
595 57..67 'S(|i| 2*i)': S
596 59..66 '|i| 2*i': |u32| -> u64
603 81..84 'a.0': fn(u32) -> u64
607 93..96 'a.0': fn(u32) -> u64
615 fn indexing_arrays() {
617 "fn main() { &mut [9][2]; }",
619 10..26 '{ &mut...[2]; }': ()
620 12..23 '&mut [9][2]': &mut {unknown}
621 17..20 '[9]': [i32; 1]
622 17..23 '[9][2]': {unknown}
630 fn infer_ops_index() {
637 impl core::ops::Index<u32> for Bar {
651 fn infer_ops_index_field() {
660 impl core::ops::Index<u32> for Bar {
666 let b = a[1u32].field;
674 fn infer_ops_index_field_autoderef() {
683 impl core::ops::Index<u32> for Bar {
689 let b = (&a[1u32]).field;
697 fn infer_ops_index_int() {
704 impl core::ops::Index<u32> for Bar {
709 impl core::ops::Index<Range> for Bar {
724 fn infer_ops_index_autoderef() {
727 //- minicore: index, slice
729 let a = &[1u32, 2, 3];
742 struct Arc<T: ?Sized>;
743 impl<T: ?Sized> core::ops::Deref for Arc<T> {
749 fn foo(&self) -> u128 { 0 }
754 } //^^^^^^^^^^^^^ (S, u128)
760 fn deref_trait_with_inference_var() {
764 struct Arc<T: ?Sized>;
765 fn new_arc<T: ?Sized>() -> Arc<T> { Arc }
766 impl<T: ?Sized> core::ops::Deref for Arc<T> {
784 fn deref_trait_infinite_recursion() {
790 impl core::ops::Deref for S {
796 } //^^^^^^^ {unknown}
802 fn deref_trait_with_question_mark_size() {
806 struct Arc<T: ?Sized>;
807 impl<T: ?Sized> core::ops::Deref for Arc<T> {
813 fn foo(&self) -> u128 { 0 }
818 } //^^^^^^^^^^^^^ (S, u128)
824 fn deref_trait_with_implicit_sized_requirement_on_inference_var() {
829 impl<T> core::ops::Deref for Foo<T> {
836 let _: Foo<u8> = foo;
843 fn obligation_from_function_clause() {
849 impl Trait<u32> for S {}
851 fn foo<T: Trait<U>, U>(t: T) -> U { loop {} }
861 fn obligation_from_method_clause() {
868 impl Trait<isize> for S {}
872 fn foo<T: Trait<U>, U>(&self, t: T) -> U { loop {} }
883 fn obligation_from_self_method_clause() {
889 impl Trait<i64> for S {}
892 fn foo<U>(&self) -> U where Self: Trait<U> { loop {} }
903 fn obligation_from_impl_clause() {
909 impl Trait<&str> for S {}
912 impl<U, T: Trait<U>> O<T> {
913 fn foo(&self) -> U { loop {} }
924 fn generic_param_env_1() {
928 trait Trait { fn foo(self) -> u128; }
931 impl<T> Trait for T where T: Clone {}
932 fn test<T: Clone>(t: T) { t.foo(); }
939 fn generic_param_env_1_not_met() {
944 trait Trait { fn foo(self) -> u128; }
947 impl<T> Trait for T where T: Clone {}
948 fn test<T>(t: T) { t.foo(); }
955 fn generic_param_env_2() {
958 trait Trait { fn foo(self) -> u128; }
961 fn test<T: Trait>(t: T) { t.foo(); }
968 fn generic_param_env_2_not_met() {
971 trait Trait { fn foo(self) -> u128; }
974 fn test<T>(t: T) { t.foo(); }
981 fn generic_param_env_deref() {
986 impl<T> core::ops::Deref for T where T: Trait {
989 fn test<T: Trait>(t: T) { *t; }
996 fn associated_type_placeholder() {
997 // 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].
1004 pub struct RefMutL<T>;
1006 impl<T> ApplyL for RefMutL<T> {
1007 type Out = <T as ApplyL>::Out;
1010 fn test<T: ApplyL>() {
1011 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
1013 } //^ ApplyL::Out<T>
1019 fn associated_type_placeholder_2() {
1025 fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
1027 fn test<T: ApplyL>(t: T) {
1030 } //^ ApplyL::Out<T>
1036 fn argument_impl_trait() {
1037 check_infer_with_mismatches(
1042 fn foo2(&self) -> i64;
1044 fn bar(x: impl Trait<u16>) {}
1046 impl<T> Trait<T> for S<T> {}
1048 fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
1061 29..33 'self': &Self
1062 54..58 'self': &Self
1063 77..78 'x': impl Trait<u16>
1065 154..155 'x': impl Trait<u64>
1066 174..175 'y': &impl Trait<u32>
1067 195..323 '{ ...2(); }': ()
1068 201..202 'x': impl Trait<u64>
1069 208..209 'y': &impl Trait<u32>
1070 219..220 'z': S<u16>
1071 223..224 'S': S<u16>(u16) -> S<u16>
1072 223..227 'S(1)': S<u16>
1074 233..236 'bar': fn bar(S<u16>)
1075 233..239 'bar(z)': ()
1076 237..238 'z': S<u16>
1077 245..246 'x': impl Trait<u64>
1078 245..252 'x.foo()': u64
1079 258..259 'y': &impl Trait<u32>
1080 258..265 'y.foo()': u32
1081 271..272 'z': S<u16>
1082 271..278 'z.foo()': u16
1083 284..285 'x': impl Trait<u64>
1084 284..292 'x.foo2()': i64
1085 298..299 'y': &impl Trait<u32>
1086 298..306 'y.foo2()': i64
1087 312..313 'z': S<u16>
1088 312..320 'z.foo2()': i64
1094 fn argument_impl_trait_type_args_1() {
1095 check_infer_with_mismatches(
1100 // this function has an implicit Self param, an explicit type param,
1101 // and an implicit impl Trait param!
1102 fn bar<T>(x: impl Trait) -> T { loop {} }
1104 fn foo<T>(x: impl Trait) -> T { loop {} }
1115 <F as Foo>::bar::<u32>(S);
1119 foo::<u32, i32>(S); // we should ignore the extraneous i32
1122 155..156 'x': impl Trait
1123 175..186 '{ loop {} }': T
1124 177..184 'loop {}': !
1126 199..200 'x': impl Trait
1127 219..230 '{ loop {} }': T
1128 221..228 'loop {}': !
1130 300..509 '{ ... i32 }': ()
1131 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1132 306..317 'Foo::bar(S)': {unknown}
1134 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1135 323..341 '<F as ...bar(S)': {unknown}
1137 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1138 347..356 'F::bar(S)': {unknown}
1140 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1141 362..380 'Foo::b...32>(S)': u32
1143 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1144 386..411 '<F as ...32>(S)': u32
1146 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1147 418..424 'foo(S)': {unknown}
1149 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1150 430..443 'foo::<u32>(S)': u32
1152 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1153 449..467 'foo::<...32>(S)': u32
1160 fn argument_impl_trait_type_args_2() {
1161 check_infer_with_mismatches(
1169 fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
1175 F::<u32>.foo::<i32>(S);
1176 F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
1180 93..94 'x': impl Trait
1181 118..129 '{ loop {} }': (T, U)
1182 120..127 'loop {}': !
1184 143..283 '{ ...ored }': ()
1185 149..150 'F': F<{unknown}>
1186 149..157 'F.foo(S)': ({unknown}, {unknown})
1188 163..171 'F::<u32>': F<u32>
1189 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1191 184..192 'F::<u32>': F<u32>
1192 184..206 'F::<u3...32>(S)': (u32, i32)
1194 212..220 'F::<u32>': F<u32>
1195 212..239 'F::<u3...32>(S)': (u32, i32)
1202 fn argument_impl_trait_to_fn_pointer() {
1203 check_infer_with_mismatches(
1207 fn foo(x: impl Trait) { loop {} }
1212 let f: fn(S) -> () = foo;
1215 22..23 'x': impl Trait
1216 37..48 '{ loop {} }': ()
1219 90..123 '{ ...foo; }': ()
1221 117..120 'foo': fn foo(S)
1233 fn foo2(&self) -> i64;
1235 fn bar() -> impl Trait<u64> {}
1237 fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1249 29..33 'self': &Self
1250 54..58 'self': &Self
1252 110..111 'x': impl Trait<u64>
1253 130..131 'y': &impl Trait<u64>
1254 151..268 '{ ...2(); }': ()
1255 157..158 'x': impl Trait<u64>
1256 164..165 'y': &impl Trait<u64>
1257 175..176 'z': impl Trait<u64>
1258 179..182 'bar': fn bar() -> impl Trait<u64>
1259 179..184 'bar()': impl Trait<u64>
1260 190..191 'x': impl Trait<u64>
1261 190..197 'x.foo()': u64
1262 203..204 'y': &impl Trait<u64>
1263 203..210 'y.foo()': u64
1264 216..217 'z': impl Trait<u64>
1265 216..223 'z.foo()': u64
1266 229..230 'x': impl Trait<u64>
1267 229..237 'x.foo2()': i64
1268 243..244 'y': &impl Trait<u64>
1269 243..251 'y.foo2()': i64
1270 257..258 'z': impl Trait<u64>
1271 257..265 'z.foo2()': i64
1277 fn simple_return_pos_impl_trait() {
1278 cov_mark
::check
!(lower_rpit
);
1285 fn bar() -> impl Trait<u64> { loop {} }
1292 29..33 'self': &Self
1293 71..82 '{ loop {} }': !
1296 94..129 '{ ...o(); }': ()
1297 104..105 'a': impl Trait<u64>
1298 108..111 'bar': fn bar() -> impl Trait<u64>
1299 108..113 'bar()': impl Trait<u64>
1300 119..120 'a': impl Trait<u64>
1301 119..126 'a.foo()': u64
1307 fn more_return_pos_impl_trait() {
1313 fn next(&mut self) -> Self::Item;
1318 fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1319 fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1325 let (c, d) = baz(1u128);
1330 49..53 'self': &mut Self
1331 101..105 'self': &Self
1332 184..195 '{ loop {} }': ({unknown}, {unknown})
1333 186..193 'loop {}': !
1336 268..279 '{ loop {} }': ({unknown}, {unknown})
1337 270..277 'loop {}': !
1339 291..413 '{ ...o(); }': ()
1340 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1341 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1342 305..306 'b': impl Trait<u64>
1343 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1344 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1345 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1346 321..329 'a.next()': impl Trait<u32>
1347 321..335 'a.next().foo()': u32
1348 341..342 'b': impl Trait<u64>
1349 341..348 'b.foo()': u64
1350 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1351 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1352 362..363 'd': impl Trait<u128>
1353 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1354 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1355 371..376 '1u128': u128
1356 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1357 383..391 'c.next()': impl Trait<u128>
1358 383..397 'c.next().foo()': u128
1359 403..404 'd': impl Trait<u128>
1360 403..410 'd.foo()': u128
1366 fn infer_from_return_pos_impl_trait() {
1367 check_infer_with_mismatches(
1369 //- minicore: fn, sized
1372 impl<T> Trait<T> for Bar<T> {}
1373 fn foo<const C: u8, T>() -> (impl FnOnce(&str, T), impl Trait<u8>) {
1374 (|input, t| {}, Bar(C))
1378 134..165 '{ ...(C)) }': (|&str, T| -> (), Bar<u8>)
1379 140..163 '(|inpu...ar(C))': (|&str, T| -> (), Bar<u8>)
1380 141..154 '|input, t| {}': |&str, T| -> ()
1381 142..147 'input': &str
1384 156..159 'Bar': Bar<u8>(u8) -> Bar<u8>
1385 156..162 'Bar(C)': Bar<u8>
1398 fn foo2(&self) -> i64;
1400 fn bar() -> dyn Trait<u64> {}
1402 fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1414 29..33 'self': &Self
1415 54..58 'self': &Self
1416 97..99 '{}': dyn Trait<u64>
1417 109..110 'x': dyn Trait<u64>
1418 128..129 'y': &dyn Trait<u64>
1419 148..265 '{ ...2(); }': ()
1420 154..155 'x': dyn Trait<u64>
1421 161..162 'y': &dyn Trait<u64>
1422 172..173 'z': dyn Trait<u64>
1423 176..179 'bar': fn bar() -> dyn Trait<u64>
1424 176..181 'bar()': dyn Trait<u64>
1425 187..188 'x': dyn Trait<u64>
1426 187..194 'x.foo()': u64
1427 200..201 'y': &dyn Trait<u64>
1428 200..207 'y.foo()': u64
1429 213..214 'z': dyn Trait<u64>
1430 213..220 'z.foo()': u64
1431 226..227 'x': dyn Trait<u64>
1432 226..234 'x.foo2()': i64
1433 240..241 'y': &dyn Trait<u64>
1434 240..248 'y.foo2()': i64
1435 254..255 'z': dyn Trait<u64>
1436 254..262 'z.foo2()': i64
1442 fn dyn_trait_in_impl() {
1447 fn foo(&self) -> (T, U);
1450 impl<T, U> S<T, U> {
1451 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1453 trait Trait2<T, U> {
1454 fn baz(&self) -> (T, U);
1456 impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1458 fn test(s: S<u32, i32>) {
1462 32..36 'self': &Self
1463 102..106 'self': &S<T, U>
1464 128..139 '{ loop {} }': &dyn Trait<T, U>
1465 130..137 'loop {}': !
1467 175..179 'self': &Self
1468 251..252 's': S<u32, i32>
1469 267..289 '{ ...z(); }': ()
1470 273..274 's': S<u32, i32>
1471 273..280 's.bar()': &dyn Trait<u32, i32>
1472 273..286 's.bar().baz()': (u32, i32)
1478 fn dyn_trait_bare() {
1483 fn foo(&self) -> u64;
1485 fn bar() -> Trait {}
1487 fn test(x: Trait, y: &Trait) -> u64 {
1496 26..30 'self': &Self
1497 60..62 '{}': dyn Trait
1498 72..73 'x': dyn Trait
1499 82..83 'y': &dyn Trait
1500 100..175 '{ ...o(); }': u64
1501 106..107 'x': dyn Trait
1502 113..114 'y': &dyn Trait
1503 124..125 'z': dyn Trait
1504 128..131 'bar': fn bar() -> dyn Trait
1505 128..133 'bar()': dyn Trait
1506 139..140 'x': dyn Trait
1507 139..146 'x.foo()': u64
1508 152..153 'y': &dyn Trait
1509 152..159 'y.foo()': u64
1510 165..166 'z': dyn Trait
1511 165..172 'z.foo()': u64
1515 check_infer_with_mismatches(
1517 //- minicore: fn, coerce_unsized
1524 f(&|number| number.foo());
1530 47..48 '_': &dyn Fn(S)
1532 71..105 '{ ...()); }': ()
1533 77..78 'f': fn f(&dyn Fn(S))
1534 77..102 'f(&|nu...foo())': ()
1535 79..101 '&|numb....foo()': &|S| -> ()
1536 80..101 '|numbe....foo()': |S| -> ()
1539 89..101 'number.foo()': ()
1551 a: impl Trait + 'lifetime,
1554 d: impl ('lifetime),
1556 f: impl Trait + ?Sized
1560 28..29 'a': impl Trait
1561 59..60 'b': impl Sized
1562 82..83 'c': impl Trait
1563 103..104 'd': impl Sized
1564 128..129 'e': impl ?Sized
1565 148..149 'f': impl Trait + ?Sized
1572 fn error_bound_chalk() {
1576 fn foo(&self) -> u32 { 0 }
1579 fn test(x: (impl Trait + UnknownTrait)) {
1587 fn assoc_type_bindings() {
1595 fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
1596 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1597 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1600 impl<T> Trait for S<T> { type Type = T; }
1602 fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1613 77..79 '{}': Trait::Type<T>
1620 262..263 'y': impl Trait<Type = i64>
1621 289..397 '{ ...r>); }': ()
1622 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1623 295..301 'get(x)': u32
1625 307..311 'get2': fn get2<u32, T>(T) -> u32
1626 307..314 'get2(x)': u32
1628 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1629 320..326 'get(y)': i64
1630 324..325 'y': impl Trait<Type = i64>
1631 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1632 332..339 'get2(y)': i64
1633 337..338 'y': impl Trait<Type = i64>
1634 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1635 345..356 'get(set(S))': u64
1636 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1637 349..355 'set(S)': S<u64>
1638 353..354 'S': S<u64>
1639 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1640 362..374 'get2(set(S))': u64
1641 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1642 367..373 'set(S)': S<u64>
1643 371..372 'S': S<u64>
1644 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1645 380..394 'get2(S::<str>)': str
1646 385..393 'S::<str>': S<str>
1652 fn impl_trait_assoc_binding_projection_bug() {
1655 //- minicore: iterator
1656 pub trait Language {
1659 pub enum RustLanguage {}
1660 impl Language for RustLanguage {
1661 type Kind = SyntaxKind;
1663 struct SyntaxNode<L> {}
1664 fn foo() -> impl Iterator<Item = SyntaxNode<RustLanguage>> {}
1667 fn clone(&self) -> Self;
1670 fn api_walkthrough() {
1673 } //^^^^^^^^^^^^ {unknown}
1680 fn projection_eq_within_chalk() {
1689 impl<T, U> Trait2<T> for U where U: Trait1<Type = T> {}
1691 fn test<T: Trait1<Type = u32>>(x: T) {
1697 169..185 '{ ...o(); }': ()
1699 175..182 'x.foo()': u32
1705 fn where_clause_trait_in_scope_for_method_resolution() {
1710 fn foo(&self) -> u32 { 0 }
1714 fn test<T: foo::Trait>(x: T) {
1722 fn super_trait_method_resolution() {
1727 fn foo(&self) -> u32 {}
1730 trait Trait1: foo::SuperTrait {}
1731 trait Trait2 where Self: foo::SuperTrait {}
1733 fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1738 49..53 'self': &Self
1742 193..222 '{ ...o(); }': ()
1744 199..206 'x.foo()': u32
1746 212..219 'y.foo()': u32
1752 fn super_trait_impl_trait_method_resolution() {
1758 fn foo(&self) -> u32 {}
1761 trait Trait1: foo::SuperTrait {}
1763 fn test(x: &impl Trait1) {
1767 49..53 'self': &Self
1769 115..116 'x': &impl Trait1
1770 132..148 '{ ...o(); }': ()
1771 138..139 'x': &impl Trait1
1772 138..145 'x.foo()': u32
1778 fn super_trait_cycle() {
1779 // This just needs to not crash
1785 fn test<T: A>(x: T) {
1791 49..65 '{ ...o(); }': ()
1793 55..62 'x.foo()': {unknown}
1799 fn super_trait_assoc_type_bounds() {
1802 trait SuperTrait { type Type; }
1803 trait Trait where Self: SuperTrait {}
1805 fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
1806 fn set<T: Trait<Type = u64>>(t: T) -> T {t}
1809 impl<T> SuperTrait for S<T> { type Type = T; }
1810 impl<T> Trait for S<T> {}
1821 258..279 '{ ...S)); }': ()
1822 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1823 264..276 'get2(set(S))': u64
1824 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1825 269..275 'set(S)': S<u64>
1826 273..274 'S': S<u64>
1833 check_infer_with_mismatches(
1835 trait FnOnce<Args> {
1838 fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
1841 fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1842 f.call_once((1, 2));
1848 155..183 '{ ...2)); }': ()
1850 161..180 'f.call...1, 2))': u128
1851 173..179 '(1, 2)': (u32, u64)
1859 fn fn_ptr_and_item() {
1860 check_infer_with_mismatches(
1863 trait FnOnce<Args> {
1866 fn call_once(self, args: Args) -> Self::Output;
1875 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1876 fn foo(&self) -> (A1, R) { loop {} }
1879 enum Opt<T> { None, Some(T) }
1881 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1885 let bar: Bar<fn(u8) -> u32>;
1889 let f: fn(u8) -> u32;
1895 139..143 'self': &Self
1896 243..247 'self': &Bar<F>
1897 260..271 '{ loop {} }': (A1, R)
1898 262..269 'loop {}': !
1900 355..359 'self': Opt<T>
1902 377..388 '{ loop {} }': Opt<U>
1903 379..386 'loop {}': !
1905 402..518 '{ ...(f); }': ()
1906 412..415 'bar': Bar<fn(u8) -> u32>
1907 441..444 'bar': Bar<fn(u8) -> u32>
1908 441..450 'bar.foo()': (u8, u32)
1909 461..464 'opt': Opt<u8>
1910 483..484 'f': fn(u8) -> u32
1911 505..508 'opt': Opt<u8>
1912 505..515 'opt.map(f)': Opt<u32>
1913 513..514 'f': fn(u8) -> u32
1919 fn fn_trait_deref_with_ty_default() {
1922 //- minicore: deref, fn
1926 fn foo(&self) -> usize {}
1929 struct Lazy<T, F = fn() -> T>(F);
1931 impl<T, F> Lazy<T, F> {
1932 pub fn new(f: F) -> Lazy<T, F> {}
1935 impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> {
1940 let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo);
1941 let r1 = lazy1.foo();
1943 fn make_foo_fn() -> Foo {}
1944 let make_foo_fn_ptr: fn() -> Foo = make_foo_fn;
1945 let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr);
1946 let r2 = lazy2.foo();
1952 151..153 '{}': Lazy<T, F>
1953 251..497 '{ ...o(); }': ()
1954 261..266 'lazy1': Lazy<Foo, || -> Foo>
1955 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1956 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1957 293..299 '|| Foo': || -> Foo
1959 310..312 'r1': usize
1960 315..320 'lazy1': Lazy<Foo, || -> Foo>
1961 315..326 'lazy1.foo()': usize
1962 368..383 'make_foo_fn_ptr': fn() -> Foo
1963 399..410 'make_foo_fn': fn make_foo_fn() -> Foo
1964 420..425 'lazy2': Lazy<Foo, fn() -> Foo>
1965 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1966 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1967 452..467 'make_foo_fn_ptr': fn() -> Foo
1968 478..480 'r2': usize
1969 483..488 'lazy2': Lazy<Foo, fn() -> Foo>
1970 483..494 'lazy2.foo()': usize
1978 check_infer_with_mismatches(
1981 enum Option<T> { Some(T), None }
1983 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1987 let x = Option::Some(1u32);
1990 let y: Option<i64> = x.map(|_v| 1);
1993 86..90 'self': Option<T>
1995 111..122 '{ loop {} }': Option<U>
1996 113..120 'loop {}': !
1998 136..255 '{ ... 1); }': ()
1999 146..147 'x': Option<u32>
2000 150..162 'Option::Some': Some<u32>(u32) -> Option<u32>
2001 150..168 'Option...(1u32)': Option<u32>
2002 163..167 '1u32': u32
2003 174..175 'x': Option<u32>
2004 174..190 'x.map(...v + 1)': Option<u32>
2005 180..189 '|v| v + 1': |u32| -> u32
2008 184..189 'v + 1': u32
2010 196..197 'x': Option<u32>
2011 196..212 'x.map(... 1u64)': Option<u64>
2012 202..211 '|_v| 1u64': |u32| -> u64
2014 207..211 '1u64': u64
2015 222..223 'y': Option<i64>
2016 239..240 'x': Option<u32>
2017 239..252 'x.map(|_v| 1)': Option<i64>
2018 245..251 '|_v| 1': |u32| -> i64
2029 //- minicore: add, fn
2031 impl core::ops::Add for u64 {
2033 fn add(self, rhs: u64) -> Self::Output {0}
2036 impl core::ops::Add for u128 {
2038 fn add(self, rhs: u128) -> Self::Output {0}
2041 fn test<F: FnOnce(u32) -> u64>(f: F) {
2047 //^^^^^^^^^ |u64| -> u64
2050 let h = |v| 1u128 + v;
2051 //^^^^^^^^^^^^^ |u128| -> u128
2057 fn closure_as_argument_inference_order() {
2058 check_infer_with_mismatches(
2061 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
2062 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
2066 fn method(self) -> u64;
2068 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
2069 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
2073 let x1 = foo1(S, |s| s.method());
2074 let x2 = foo2(|s| s.method(), S);
2075 let x3 = S.foo1(S, |s| s.method());
2076 let x4 = S.foo2(|s| s.method(), S);
2081 50..61 '{ loop {} }': U
2086 112..123 '{ loop {} }': U
2087 114..121 'loop {}': !
2093 233..244 '{ loop {} }': U
2094 235..242 'loop {}': !
2099 305..316 '{ loop {} }': U
2100 307..314 'loop {}': !
2102 330..489 '{ ... S); }': ()
2104 345..349 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2105 345..368 'foo1(S...hod())': u64
2107 353..367 '|s| s.method()': |S| -> u64
2110 357..367 's.method()': u64
2112 383..387 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2113 383..406 'foo2(|...(), S)': u64
2114 388..402 '|s| s.method()': |S| -> u64
2117 392..402 's.method()': u64
2121 421..446 'S.foo1...hod())': u64
2123 431..445 '|s| s.method()': |S| -> u64
2126 435..445 's.method()': u64
2129 461..486 'S.foo2...(), S)': u64
2130 468..482 '|s| s.method()': |S| -> u64
2133 472..482 's.method()': u64
2140 fn fn_item_fn_trait() {
2148 fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2152 } //^^^^^^^^^^^^^^^^^^ S
2158 fn unselected_projection_in_trait_env_1() {
2167 fn foo(&self) -> u32;
2170 fn test<T: Trait>() where T::Item: Trait2 {
2171 let x: T::Item = no_matter;
2179 fn unselected_projection_in_trait_env_2() {
2187 fn foo(&self) -> u32;
2190 fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
2191 let x: T::Item = no_matter;
2199 fn unselected_projection_on_impl_self() {
2206 fn f(&self, x: Self::Item);
2213 fn f(&self, x: Self::Item) { let y = x; }
2220 fn f(&self, x: <Self>::Item) { let y = x; }
2223 40..44 'self': &Self
2224 46..47 'x': Trait::Item<Self>
2227 147..161 '{ let y = x; }': ()
2230 228..232 'self': &S2
2232 251..265 '{ let y = x; }': ()
2240 fn unselected_projection_on_trait_self() {
2246 fn f(&self) -> Self::Item { loop {} }
2262 fn unselected_projection_chalk_fold() {
2266 trait Fold<I: Interner, TI = I> {
2270 struct Ty<I: Interner> {}
2271 impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> {
2272 type Result = Ty<TI>;
2275 fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result
2282 fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2284 } //^^^^^^^^^^^^^^^^^ Ty<I>
2290 fn trait_impl_self_ty() {
2299 impl Trait<Self> for S {}
2309 fn trait_impl_self_ty_cycle() {
2318 impl Trait for S<Self> {}
2322 } //^^^^^^^ {unknown}
2328 fn unselected_projection_in_trait_env_cycle_1() {
2329 // This is not a cycle, because the `T: Trait2<T::Item>` bound depends only on the `T: Trait`
2330 // bound, not on itself (since only `Trait` can define `Item`).
2339 fn test<T: Trait>() where T: Trait2<T::Item> {
2340 let x: T::Item = no_matter;
2341 } //^^^^^^^^^ Trait::Item<T>
2347 fn unselected_projection_in_trait_env_cycle_2() {
2348 // this is a legitimate cycle
2356 fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2357 let x: T::Item = no_matter;
2358 } //^^^^^^^^^ {unknown}
2364 fn unselected_projection_in_trait_env_cycle_3() {
2365 // this is a cycle for rustc; we currently accept it
2374 fn test<T>() where T: Trait<OtherItem = T::Item> {
2375 let x: T::Item = no_matter;
2376 } //^^^^^^^^^ Trait::Item<T>
2382 fn unselected_projection_in_trait_env_no_cycle() {
2383 // this is not a cycle
2391 type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
2393 pub trait UnificationStoreBase: Index<Output = Key<Self>> {
2396 fn len(&self) -> usize;
2399 pub trait UnificationStoreMut: UnificationStoreBase {
2400 fn push(&mut self, value: Self::Key);
2403 fn test<T>(t: T) where T: UnificationStoreMut {
2408 } //^^^^^^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>)
2414 fn inline_assoc_type_bounds_1() {
2420 trait OtherTrait<T> {
2424 // workaround for Chalk assoc type normalization problems
2426 impl<T: Iterator> Iterator for S<T> {
2427 type Item = <T as Iterator>::Item;
2430 fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2431 let x: <S<I> as Iterator>::Item;
2439 fn inline_assoc_type_bounds_2() {
2446 fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2447 let x: <<I as Iterator>::Item as Iterator>::Item;
2455 fn proc_macro_server_types() {
2458 macro_rules! with_api {
2459 ($S:ident, $self:ident, $m:ident) => {
2462 fn new() -> $S::TokenStream;
2469 macro_rules! associated_item {
2470 (type TokenStream) =>
2471 (type TokenStream: 'static;);
2473 (type Group: 'static;);
2474 ($($item:tt)*) => ($($item)*;)
2476 macro_rules! declare_server_traits {
2478 $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2481 $(associated_item!(type $name);)*
2484 $(pub trait $name: Types {
2485 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2488 pub trait Server: Types $(+ $name)* {}
2489 impl<S: Types $(+ $name)*> Server for S {}
2493 with_api!(Self, self_, declare_server_traits);
2496 struct RustAnalyzer;
2497 impl Types for RustAnalyzer {
2498 type TokenStream = T;
2502 fn make<T>() -> T { loop {} }
2503 impl TokenStream for RustAnalyzer {
2504 fn new() -> Self::TokenStream {
2505 let group: Self::Group = make();
2510 1075..1086 '{ loop {} }': T
2511 1077..1084 'loop {}': !
2513 1157..1220 '{ ... }': T
2514 1171..1176 'group': G
2515 1192..1196 'make': fn make<G>() -> G
2516 1192..1198 'make()': G
2517 1208..1212 'make': fn make<T>() -> T
2518 1208..1214 'make()': T
2524 fn unify_impl_trait() {
2525 check_infer_with_mismatches(
2530 fn foo(x: impl Trait<u32>) { loop {} }
2531 fn bar<T>(x: impl Trait<T>) -> T { loop {} }
2534 impl<T> Trait<T> for S<T> {}
2536 fn default<T>() -> T { loop {} }
2538 fn test() -> impl Trait<i32> {
2539 let s1 = S(default());
2541 let x: i32 = bar(S(default()));
2545 26..27 'x': impl Trait<u32>
2546 46..57 '{ loop {} }': ()
2549 68..69 'x': impl Trait<T>
2550 91..102 '{ loop {} }': T
2551 93..100 'loop {}': !
2553 171..182 '{ loop {} }': T
2554 173..180 'loop {}': !
2556 213..309 '{ ...t()) }': S<i32>
2557 223..225 's1': S<u32>
2558 228..229 'S': S<u32>(u32) -> S<u32>
2559 228..240 'S(default())': S<u32>
2560 230..237 'default': fn default<u32>() -> u32
2561 230..239 'default()': u32
2562 246..249 'foo': fn foo(S<u32>)
2563 246..253 'foo(s1)': ()
2564 250..252 's1': S<u32>
2566 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2567 272..289 'bar(S(...lt()))': i32
2568 276..277 'S': S<i32>(i32) -> S<i32>
2569 276..288 'S(default())': S<i32>
2570 278..285 'default': fn default<i32>() -> i32
2571 278..287 'default()': i32
2572 295..296 'S': S<i32>(i32) -> S<i32>
2573 295..307 'S(default())': S<i32>
2574 297..304 'default': fn default<i32>() -> i32
2575 297..306 'default()': i32
2581 fn assoc_types_from_bounds() {
2600 f::<(), _>(|z| { z; });
2605 132..163 '{ ... }); }': ()
2606 138..148 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2607 138..160 'f::<()... z; })': ()
2608 149..159 '|z| { z; }': |&()| -> ()
2610 153..159 '{ z; }': ()
2617 fn associated_type_bound() {
2621 type Item: OtherTrait<u32>;
2623 pub trait OtherTrait<T> {
2627 // this is just a workaround for chalk#234
2629 impl<T: Trait> Trait for S<T> {
2630 type Item = <T as Trait>::Item;
2633 fn test<T: Trait>() {
2634 let y: <S<T> as Trait>::Item = no_matter;
2642 fn dyn_trait_through_chalk() {
2646 struct Box<T: ?Sized> {}
2647 impl<T: ?Sized> core::ops::Deref for Box<T> {
2654 fn test(x: Box<dyn Trait>) {
2662 fn string_to_owned() {
2668 fn to_owned(&self) -> Self::Owned;
2670 impl ToOwned for str {
2671 type Owned = String;
2675 } //^^^^^^^^^^^^^^^^ String
2681 fn iterator_chain() {
2682 check_infer_with_mismatches(
2684 //- minicore: fn, option
2685 pub trait Iterator {
2688 fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
2690 F: FnMut(Self::Item) -> Option<B>,
2693 fn for_each<F>(self, f: F)
2695 F: FnMut(Self::Item),
2699 pub trait IntoIterator {
2701 type IntoIter: Iterator<Item = Self::Item>;
2702 fn into_iter(self) -> Self::IntoIter;
2705 pub struct FilterMap<I, F> { }
2706 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
2708 F: FnMut(I::Item) -> Option<B>,
2713 #[stable(feature = "rust1", since = "1.0.0")]
2714 impl<I: Iterator> IntoIterator for I {
2715 type Item = I::Item;
2718 fn into_iter(self) -> I {
2725 fn new() -> Self { loop {} }
2728 impl<T> IntoIterator for Vec<T> {
2730 type IntoIter = IntoIter<T>;
2733 pub struct IntoIter<T> { }
2734 impl<T> Iterator for IntoIter<T> {
2739 Vec::<i32>::new().into_iter()
2740 .filter_map(|x| if x > 0 { Some(x as u32) } else { None })
2741 .for_each(|y| { y; });
2746 152..163 '{ loop {} }': FilterMap<Self, F>
2747 154..161 'loop {}': !
2749 184..188 'self': Self
2751 240..251 '{ loop {} }': ()
2752 242..249 'loop {}': !
2754 360..364 'self': Self
2756 700..720 '{ ... }': I
2758 779..790 '{ loop {} }': Vec<T>
2759 781..788 'loop {}': !
2761 977..1104 '{ ... }); }': ()
2762 983..998 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2763 983..1000 'Vec::<...:new()': Vec<i32>
2764 983..1012 'Vec::<...iter()': IntoIter<i32>
2765 983..1075 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2766 983..1101 'Vec::<... y; })': ()
2767 1029..1074 '|x| if...None }': |i32| -> Option<u32>
2769 1033..1074 'if x >...None }': Option<u32>
2771 1036..1041 'x > 0': bool
2773 1042..1060 '{ Some...u32) }': Option<u32>
2774 1044..1048 'Some': Some<u32>(u32) -> Option<u32>
2775 1044..1058 'Some(x as u32)': Option<u32>
2777 1049..1057 'x as u32': u32
2778 1066..1074 '{ None }': Option<u32>
2779 1068..1072 'None': Option<u32>
2780 1090..1100 '|y| { y; }': |u32| -> ()
2782 1094..1100 '{ y; }': ()
2805 fn foo() -> Self::Output;
2809 type Output = T::OutputA;
2810 fn foo() -> Self::Output { loop {} }
2821 fn trait_object_no_coercion() {
2822 check_infer_with_mismatches(
2826 fn foo(x: &dyn Foo) {}
2828 fn test(x: &dyn Foo) {
2832 21..22 'x': &dyn Foo
2834 46..47 'x': &dyn Foo
2835 59..74 '{ foo(x); }': ()
2836 65..68 'foo': fn foo(&dyn Foo)
2838 69..70 'x': &dyn Foo
2845 check_infer_with_mismatches(
2849 impl Copy for IsCopy {}
2852 trait Test { fn test(&self) -> bool; }
2853 impl<T: Copy> Test for T {}
2858 (IsCopy, IsCopy).test();
2859 (IsCopy, NotCopy).test();
2862 78..82 'self': &Self
2863 134..235 '{ ...t(); }': ()
2864 140..146 'IsCopy': IsCopy
2865 140..153 'IsCopy.test()': bool
2866 159..166 'NotCopy': NotCopy
2867 159..173 'NotCopy.test()': {unknown}
2868 179..195 '(IsCop...sCopy)': (IsCopy, IsCopy)
2869 179..202 '(IsCop...test()': bool
2870 180..186 'IsCopy': IsCopy
2871 188..194 'IsCopy': IsCopy
2872 208..225 '(IsCop...tCopy)': (IsCopy, NotCopy)
2873 208..232 '(IsCop...test()': {unknown}
2874 209..215 'IsCopy': IsCopy
2875 217..224 'NotCopy': NotCopy
2881 fn builtin_fn_def_copy() {
2882 check_infer_with_mismatches(
2886 fn bar<T: Copy>(T) -> T {}
2887 struct Struct(usize);
2888 enum Enum { Variant(usize) }
2890 trait Test { fn test(&self) -> bool; }
2891 impl<T: Copy> Test for T {}
2897 Enum::Variant.test();
2901 28..29 'T': {unknown}
2903 36..38: expected T, got ()
2904 113..117 'self': &Self
2905 169..249 '{ ...t(); }': ()
2906 175..178 'foo': fn foo()
2907 175..185 'foo.test()': bool
2908 191..194 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2909 191..201 'bar.test()': bool
2910 207..213 'Struct': Struct(usize) -> Struct
2911 207..220 'Struct.test()': bool
2912 226..239 'Enum::Variant': Variant(usize) -> Enum
2913 226..246 'Enum::...test()': bool
2919 fn builtin_fn_ptr_copy() {
2920 check_infer_with_mismatches(
2923 trait Test { fn test(&self) -> bool; }
2924 impl<T: Copy> Test for T {}
2926 fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2932 22..26 'self': &Self
2934 86..88 'f2': fn(usize) -> u8
2935 107..109 'f3': fn(u8, u8) -> &u8
2936 130..178 '{ ...t(); }': ()
2938 136..145 'f1.test()': bool
2939 151..153 'f2': fn(usize) -> u8
2940 151..160 'f2.test()': bool
2941 166..168 'f3': fn(u8, u8) -> &u8
2942 166..175 'f3.test()': bool
2948 fn builtin_sized() {
2949 check_infer_with_mismatches(
2952 trait Test { fn test(&self) -> bool; }
2953 impl<T: Sized> Test for T {}
2957 (*"foo").test(); // not Sized
2959 (1u8, *"foo").test(); // not Sized
2962 22..26 'self': &Self
2963 79..194 '{ ...ized }': ()
2965 85..95 '1u8.test()': bool
2966 101..116 '(*"foo").test()': {unknown}
2967 102..108 '*"foo"': str
2968 103..108 '"foo"': &str
2969 135..145 '(1u8, 1u8)': (u8, u8)
2970 135..152 '(1u8, ...test()': bool
2973 158..171 '(1u8, *"foo")': (u8, str)
2974 158..178 '(1u8, ...test()': {unknown}
2976 164..170 '*"foo"': str
2977 165..170 '"foo"': &str
2983 fn integer_range_iterate() {
2986 //- /main.rs crate:main deps:core
2988 for x in 0..100 { x; }
2991 //- /core.rs crate:core
2993 pub struct Range<Idx> {
3000 pub trait Iterator {
3004 pub trait IntoIterator {
3006 type IntoIter: Iterator<Item = Self::Item>;
3009 impl<T> IntoIterator for T where T: Iterator {
3010 type Item = <T as Iterator>::Item;
3011 type IntoIter = Self;
3016 impl Step for i32 {}
3017 impl Step for i64 {}
3019 impl<A: Step> iter::Iterator for ops::Range<A> {
3027 fn infer_closure_arg() {
3038 let s = Option::None;
3039 let f = |x: Option<i32>| {};
3043 52..126 '{ ...)(s) }': ()
3044 62..63 's': Option<i32>
3045 66..78 'Option::None': Option<i32>
3046 88..89 'f': |Option<i32>| -> ()
3047 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
3048 93..94 'x': Option<i32>
3050 117..124 '(&f)(s)': ()
3051 118..120 '&f': &|Option<i32>| -> ()
3052 119..120 'f': |Option<i32>| -> ()
3053 122..123 's': Option<i32>
3059 fn dyn_fn_param_informs_call_site_closure_signature() {
3060 cov_mark
::check
!(dyn_fn_param_informs_call_site_closure_signature
);
3063 //- minicore: fn, coerce_unsized
3066 fn inherent(&self) -> u8 { 0 }
3068 fn take_dyn_fn(f: &dyn Fn(S)) {}
3071 take_dyn_fn(&|x| { x.inherent(); });
3079 fn infer_fn_trait_arg() {
3080 check_infer_with_mismatches(
3082 //- minicore: fn, option
3083 fn foo<F, T>(f: F) -> T
3085 F: Fn(Option<i32>) -> T,
3093 59..89 '{ ...f(s) }': T
3094 69..70 's': Option<i32>
3095 73..77 'None': Option<i32>
3098 85..86 's': Option<i32>
3104 fn infer_box_fn_arg() {
3105 // The type mismatch is because we don't define Unsize and CoerceUnsized
3106 check_infer_with_mismatches(
3108 //- minicore: fn, deref, option
3109 #[lang = "owned_box"]
3110 pub struct Box<T: ?Sized> {
3114 impl<T: ?Sized> core::ops::Deref for Box<T> {
3117 fn deref(&self) -> &T {
3124 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3128 154..158 'self': &Box<T>
3129 166..193 '{ ... }': &T
3130 176..187 '&self.inner': &*mut T
3131 177..181 'self': &Box<T>
3132 177..187 'self.inner': *mut T
3133 206..296 '{ ...&s); }': ()
3134 216..217 's': Option<i32>
3135 220..224 'None': Option<i32>
3136 234..235 'f': Box<dyn FnOnce(&Option<i32>)>
3137 269..282 'box (|ps| {})': Box<|&Option<i32>| -> ()>
3138 274..281 '|ps| {}': |&Option<i32>| -> ()
3139 275..277 'ps': &Option<i32>
3141 288..289 'f': Box<dyn FnOnce(&Option<i32>)>
3142 288..293 'f(&s)': ()
3143 290..292 '&s': &Option<i32>
3144 291..292 's': Option<i32>
3145 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|&Option<i32>| -> ()>
3151 fn infer_dyn_fn_output() {
3156 let f: &dyn Fn() -> i32;
3164 fn infer_dyn_fn_once_output() {
3169 let f: dyn FnOnce() -> i32;
3177 fn variable_kinds_1() {
3180 trait Trait<T> { fn get(self, t: T) -> T; }
3182 impl Trait<u128> for S {}
3183 impl Trait<f32> for S {}
3195 fn variable_kinds_2() {
3198 trait Trait { fn get(self) -> Self; }
3199 impl Trait for u128 {}
3200 impl Trait for f32 {}
3212 fn underscore_import() {
3217 fn method(&self) -> u8 { 0 }
3222 impl crate::tr::Tr for Tr {}
3224 use crate::tr::Tr as _;
3239 fn method(&self) -> u8 { 0 }
3256 fn trait_in_scope_with_inner_item() {
3261 fn method(&self) -> u8 { 0 }
3276 46..50 'self': &Self
3279 115..185 '{ ... } }': ()
3280 132..183 '{ ... }': ()
3282 142..153 '().method()': u8
3288 fn inner_use_in_block() {
3293 fn method(&self) -> u8 { 0 }
3309 //^^^^^^^^^^^ {unknown}
3313 //^^^^^^^^^^^ {unknown}
3320 fn nested_inner_function_calling_self() {
3330 17..73 '{ ... } }': ()
3333 57..62 'inner': fn inner() -> S
3340 fn infer_default_trait_type_parameter() {
3345 trait Op<RHS=Self> {
3348 fn do_op(self, rhs: RHS) -> Self::Output;
3354 fn do_op(self, rhs: Self) -> Self::Output {
3369 186..206 '{ ... }': bool
3370 196..200 'true': bool
3371 220..277 '{ ...(y); }': ()
3378 264..274 'x.do_op(y)': bool
3385 fn qualified_path_as_qualified_trait() {
3395 fn boo() -> Self::Output {
3402 impl foo::Foo for F {
3405 impl foo::Bar for F {
3406 type Output = <F as foo::Foo>::Target;
3411 let x = <F as Bar>::boo();
3414 132..163 '{ ... }': Bar::Output<Self>
3415 146..153 'loop {}': !
3417 306..358 '{ ...o(); }': ()
3419 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3420 338..355 '<F as ...:boo()': ()
3426 fn renamed_extern_crate_in_block() {
3429 //- /lib.rs crate:lib deps:serde
3430 use serde::Deserialize;
3435 extern crate serde as _serde;
3436 impl _serde::Deserialize for Foo {
3437 fn deserialize() -> u8 { 0 }
3443 //^^^^^^^^^^^^^^^^^^ u8
3446 //- /serde.rs crate:serde
3448 pub trait Deserialize {
3449 fn deserialize() -> u8;
3455 fn bin_op_with_rhs_is_self_for_assoc_bound() {
3456 check_no_mismatches(
3458 fn repro<T>(t: T) -> bool
3461 T::Output: Convertable,
3463 let a = execute(&t).convert();
3464 let b = execute(&t).convert();
3466 let a = execute(&t).convert2();
3467 let b = execute(&t).convert2();
3470 fn execute<T>(t: &T) -> T::Output
3474 <T as Request>::output()
3477 type TraitSelf: PartialEq<Self::TraitSelf>;
3478 type AssocAsDefaultSelf: PartialEq;
3479 fn convert(self) -> Self::AssocAsDefaultSelf;
3480 fn convert2(self) -> Self::TraitSelf;
3484 fn output() -> Self::Output;
3491 fn bin_op_adt_with_rhs_primitive() {
3492 check_infer_with_mismatches(
3495 pub trait Add<Rhs = Self> {
3497 fn add(self, rhs: Rhs) -> Self::Output;
3500 struct Wrapper(u32);
3501 impl Add<u32> for Wrapper {
3503 fn add(self, rhs: u32) -> Wrapper {
3508 let wrapped = Wrapper(10);
3510 let res = wrapped + num;
3516 192..196 'self': Wrapper
3518 219..247 '{ ... }': Wrapper
3519 229..236 'Wrapper': Wrapper(u32) -> Wrapper
3520 229..241 'Wrapper(rhs)': Wrapper
3522 259..345 '{ ...um; }': ()
3523 269..276 'wrapped': Wrapper
3524 279..286 'Wrapper': Wrapper(u32) -> Wrapper
3525 279..290 'Wrapper(10)': Wrapper
3529 322..325 'res': Wrapper
3530 328..335 'wrapped': Wrapper
3531 328..341 'wrapped + num': Wrapper
3543 fn do_thing(&self) -> Self::Output;
3546 impl T for [u8; 4] {
3547 type Output = usize;
3548 fn do_thing(&self) -> Self::Output {
3553 impl T for [u8; 2] {
3555 fn do_thing(&self) -> Self::Output {
3562 let v2 = v.do_thing();
3564 let v4 = v3.do_thing();
3568 44..48 'self': &Self
3569 133..137 'self': &[u8; 4]
3570 155..172 '{ ... }': usize
3572 236..240 'self': &[u8; 2]
3573 258..275 '{ ... }': u8
3575 289..392 '{ ...g(); }': ()
3576 299..300 'v': [u8; 2]
3577 303..311 '[0u8; 2]': [u8; 2]
3581 326..327 'v': [u8; 2]
3582 326..338 'v.do_thing()': u8
3583 348..350 'v3': [u8; 4]
3584 353..361 '[0u8; 4]': [u8; 4]
3587 371..373 'v4': usize
3588 376..378 'v3': [u8; 4]
3589 376..389 'v3.do_thing()': usize
3595 fn const_generics() {
3600 fn do_thing(&self) -> Self::Output;
3603 impl<const L: usize> T for [u8; L] {
3604 type Output = [u8; L];
3605 fn do_thing(&self) -> Self::Output {
3612 let v2 = v.do_thing();
3616 44..48 'self': &Self
3617 151..155 'self': &[u8; L]
3618 173..194 '{ ... }': [u8; L]
3619 183..188 '*self': [u8; L]
3620 184..188 'self': &[u8; L]
3621 208..260 '{ ...g(); }': ()
3622 218..219 'v': [u8; 2]
3623 222..230 '[0u8; 2]': [u8; 2]
3626 240..242 'v2': [u8; 2]
3627 245..246 'v': [u8; 2]
3628 245..257 'v.do_thing()': [u8; 2]
3634 fn fn_returning_unit() {
3635 check_infer_with_mismatches(
3638 fn test<F: FnOnce()>(f: F) {
3643 27..51 '{ ...f(); }': ()
3652 fn trait_in_scope_of_trait_impl() {
3658 fn bar(self) -> usize { 0 }
3661 impl foo::Foo for u32 {
3663 let _x = self.bar();
3670 82..87 '{ 0 }': usize
3672 131..135 'self': u32
3673 137..173 '{ ... }': ()
3674 151..153 '_x': usize
3675 156..160 'self': u32
3676 156..166 'self.bar()': usize
3682 fn infer_async_ret_type() {
3685 //- minicore: future, result
3689 fn collect<B: Convert>(self) -> B {
3697 impl Convert for u32 {
3698 fn new() -> Self { 0 }
3701 async fn get_accounts() -> Result<u32, ()> {
3702 let ret = Fooey.collect();
3703 // ^^^^^^^^^^^^^^^ u32
3712 check
!(block_local_impls
);
3721 impl Trait<u32> for S {
3722 fn foo(&self) -> u32 { 0 }
3734 check
!(block_local_impls
);
3743 impl Trait<u32> for S {
3744 fn foo(&self) -> u32 { 0 }
3756 check
!(block_local_impls
);
3768 impl Trait<S1> for S2 {
3769 fn foo(&self) -> S1 { S1 }
3781 fn associated_type_sized_bounds() {
3786 trait IsSized { const IS_SIZED: Yes; }
3787 impl<T: Sized> IsSized for T { const IS_SIZED: Yes = Yes; }
3790 type Explicit: Sized;
3792 type Relaxed: ?Sized;
3795 F::Explicit::IS_SIZED;
3796 F::Implicit::IS_SIZED;
3797 F::Relaxed::IS_SIZED;
3802 212..295 '{ ...ZED; }': ()
3803 218..239 'F::Exp..._SIZED': Yes
3804 245..266 'F::Imp..._SIZED': Yes
3805 272..292 'F::Rel..._SIZED': {unknown}
3814 pub struct Key<K, V, P = (K, V)> {}
3821 impl<K, V> Policy for (K, V) {
3826 pub struct KeyMap<KEY> {}
3828 impl<P: Policy> KeyMap<Key<P::K, P::V, P>> {
3829 pub fn get(&self, key: &P::K) -> P::V {
3835 struct FunctionId {}
3838 let key_map: &KeyMap<Key<Fn, FunctionId>> = loop {};
3840 let result = key_map.get(key);
3848 fn dyn_multiple_auto_traits_in_different_order() {
3849 check_no_mismatches(
3854 fn f(t: &(dyn Sync + Send)) {}
3855 fn g(t: &(dyn Send + Sync)) {
3861 check_no_mismatches(
3867 fn f(t: &(dyn T + Send + Sync)) {}
3868 fn g(t: &(dyn Sync + T + Send)) {
3874 check_infer_with_mismatches(
3881 fn f(t: &(dyn T1 + T2 + Send + Sync)) {}
3882 fn g(t: &(dyn Sync + T2 + T1 + Send)) {
3887 68..69 't': &{unknown}
3889 109..110 't': &{unknown}
3890 142..155 '{ f(t); }': ()
3891 148..149 'f': fn f(&{unknown})
3893 150..151 't': &{unknown}
3897 check_no_mismatches(
3902 type Proj: Send + Sync;
3905 fn f(t: &(dyn T<Proj = ()> + Send + Sync)) {}
3906 fn g(t: &(dyn Sync + T<Proj = ()> + Send)) {
3914 fn dyn_multiple_projection_bounds() {
3915 check_no_mismatches(
3922 fn f(t: &dyn Trait<T = (), U = ()>) {}
3923 fn g(t: &dyn Trait<U = (), T = ()>) {
3935 fn f(t: &dyn Trait<T = (), T = ()>) {}
3942 fn dyn_duplicate_auto_trait() {
3943 check_no_mismatches(
3947 fn f(t: &(dyn Send + Send)) {}
3948 fn g(t: &(dyn Send)) {
3954 check_no_mismatches(
3959 fn f(t: &(dyn T + Send + Send)) {}
3960 fn g(t: &(dyn T + Send)) {