1 use expect_test
::expect
;
3 use crate::tests
::check
;
5 use super::{check_infer, check_no_mismatches, check_types}
;
8 fn infer_slice_method() {
26 fn cross_crate_primitive_method() {
29 //- /main.rs crate:main deps:other_crate
35 //- /lib.rs crate:other_crate
38 pub fn foo(self) -> f32 { 0. }
46 fn infer_array_inherent_impl() {
49 impl<T, const N: usize> [T; N] {
54 fn test(x: &[u8; 0]) {
63 fn infer_associated_method_struct() {
80 58..68 'A { x: 0 }': A
82 87..121 '{ ...a.x; }': ()
84 101..107 'A::new': fn new() -> A
85 101..109 'A::new()': A
93 fn infer_associated_method_struct_in_local_scope() {
100 fn from(_: i32, _: i32) -> Self {
105 let _a = A::from(1, 2);
109 14..146 '{ ... 2); }': ()
111 130..137 'A::from': fn from(i32, i32) -> A
112 130..143 'A::from(1, 2)': A
124 fn infer_associated_method_enum() {
149 120..177 '{ ... c; }': ()
151 134..138 'A::b': fn b() -> A
155 161..165 'A::c': fn c() -> A
163 fn infer_associated_method_with_modules() {
168 impl A { pub fn thing() -> A { A {} }}
173 impl B { pub fn thing() -> u32 { 99 }}
177 impl C { pub fn thing() -> C { C {} }}
183 let x = a::A::thing();
184 let y = b::B::thing();
185 let z = c::C::thing();
191 125..131 '{ 99 }': u32
193 201..209 '{ C {} }': C
195 240..324 '{ ...g(); }': ()
197 254..265 'a::A::thing': fn thing() -> A
198 254..267 'a::A::thing()': A
200 281..292 'b::B::thing': fn thing() -> u32
201 281..294 'b::B::thing()': u32
203 308..319 'c::C::thing': fn thing() -> C
204 308..321 'c::C::thing()': C
210 fn infer_associated_method_generics() {
218 pub fn make(val: T) -> Gen<T> {
224 let a = Gen::make(0u32);
229 81..108 '{ ... }': Gen<T>
230 91..102 'Gen { val }': Gen<T>
232 122..154 '{ ...32); }': ()
233 132..133 'a': Gen<u32>
234 136..145 'Gen::make': fn make<u32>(u32) -> Gen<u32>
235 136..151 'Gen::make(0u32)': Gen<u32>
242 fn infer_associated_method_generics_without_args() {
250 pub fn make() -> Gen<T> {
256 let a = Gen::<u32>::make();
260 75..99 '{ ... }': Gen<T>
263 113..148 '{ ...e(); }': ()
264 123..124 'a': Gen<u32>
265 127..143 'Gen::<...::make': fn make<u32>() -> Gen<u32>
266 127..145 'Gen::<...make()': Gen<u32>
272 fn infer_associated_method_generics_2_type_params_without_args() {
280 impl<T> Gen<u32, T> {
281 pub fn make() -> Gen<u32,T> {
287 let a = Gen::<u32, u64>::make();
291 101..125 '{ ... }': Gen<u32, T>
292 111..119 'loop { }': !
294 139..179 '{ ...e(); }': ()
295 149..150 'a': Gen<u32, u64>
296 153..174 'Gen::<...::make': fn make<u64>() -> Gen<u32, u64>
297 153..176 'Gen::<...make()': Gen<u32, u64>
303 fn cross_crate_associated_method_call() {
306 //- /main.rs crate:main deps:other_crate
308 let x = other_crate::foo::S::thing();
312 //- /lib.rs crate:other_crate
316 pub fn thing() -> i128 { 0 }
324 fn infer_trait_method_simple() {
325 // the trait implementation is intentionally incomplete -- it shouldn't matter
329 fn method(&self) -> u32;
332 impl Trait1 for S1 {}
334 fn method(&self) -> i128;
337 impl Trait2 for S2 {}
341 S2.method(); // -> i128
349 fn infer_trait_method_scoped() {
350 // the trait implementation is intentionally incomplete -- it shouldn't matter
356 fn method(&self) -> u32;
358 impl Trait1 for super::S {}
362 fn method(&self) -> i128;
364 impl Trait2 for super::S {}
369 use super::foo::Trait1;
378 use super::bar::Trait2;
389 fn infer_trait_method_generic_1() {
390 // the trait implementation is intentionally incomplete -- it shouldn't matter
394 fn method(&self) -> T;
397 impl Trait<u32> for S {}
407 fn infer_trait_method_generic_more_params() {
408 // the trait implementation is intentionally incomplete -- it shouldn't matter
411 trait Trait<T1, T2, T3> {
412 fn method1(&self) -> (T1, T2, T3);
413 fn method2(&self) -> (T3, T2, T1);
416 impl Trait<u8, u16, u32> for S1 {}
418 impl<T> Trait<i8, i16, T> for S2 {}
421 //^^^^^^^^^^^^ (u8, u16, u32)
423 //^^^^^^^^^^^^ (u32, u16, u8)
425 //^^^^^^^^^^^^ (i8, i16, {unknown})
427 //^^^^^^^^^^^^ ({unknown}, i16, i8)
434 fn infer_trait_method_generic_2() {
435 // the trait implementation is intentionally incomplete -- it shouldn't matter
439 fn method(&self) -> T;
442 impl<U> Trait<U> for S<U> {}
445 //^^^^^^^^^^^^^^^^ u32
452 fn infer_trait_assoc_method() {
456 fn default() -> Self;
459 impl Default for S {}
461 let s1: S = Default::default();
462 let s2 = S::default();
463 let s3 = <S as Default>::default();
467 86..192 '{ ...t(); }': ()
469 104..120 'Defaul...efault': fn default<S>() -> S
470 104..122 'Defaul...ault()': S
472 137..147 'S::default': fn default<S>() -> S
473 137..149 'S::default()': S
475 164..187 '<S as ...efault': fn default<S>() -> S
476 164..189 '<S as ...ault()': S
482 fn infer_trait_assoc_method_generics_1() {
489 impl Trait<u32> for S {}
491 impl<T> Trait<T> for G<T> {}
494 let b = G::<u64>::make();
495 let c: f64 = G::make();
499 126..210 '{ ...e(); }': ()
501 140..147 'S::make': fn make<S, u32>() -> u32
502 140..149 'S::make()': u32
504 163..177 'G::<u64>::make': fn make<G<u64>, u64>() -> u64
505 163..179 'G::<u6...make()': u64
507 198..205 'G::make': fn make<G<f64>, f64>() -> f64
508 198..207 'G::make()': f64
514 fn infer_trait_assoc_method_generics_2() {
518 fn make<U>() -> (T, U);
521 impl Trait<u32> for S {}
523 impl<T> Trait<T> for G<T> {}
525 let a = S::make::<i64>();
526 let b: (_, i64) = S::make();
527 let c = G::<u32>::make::<i64>();
528 let d: (u32, _) = G::make::<i64>();
529 let e: (u32, i64) = G::make();
533 134..312 '{ ...e(); }': ()
534 144..145 'a': (u32, i64)
535 148..162 'S::make::<i64>': fn make<S, u32, i64>() -> (u32, i64)
536 148..164 'S::mak...i64>()': (u32, i64)
537 174..175 'b': (u32, i64)
538 188..195 'S::make': fn make<S, u32, i64>() -> (u32, i64)
539 188..197 'S::make()': (u32, i64)
540 207..208 'c': (u32, i64)
541 211..232 'G::<u3...:<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64)
542 211..234 'G::<u3...i64>()': (u32, i64)
543 244..245 'd': (u32, i64)
544 258..272 'G::make::<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64)
545 258..274 'G::mak...i64>()': (u32, i64)
546 284..285 'e': (u32, i64)
547 300..307 'G::make': fn make<G<u32>, u32, i64>() -> (u32, i64)
548 300..309 'G::make()': (u32, i64)
554 fn infer_trait_assoc_method_generics_3() {
558 fn make() -> (Self, T);
561 impl Trait<i64> for S<i32> {}
567 100..126 '{ ...e(); }': ()
568 110..111 'a': (S<i32>, i64)
569 114..121 'S::make': fn make<S<i32>, i64>() -> (S<i32>, i64)
570 114..123 'S::make()': (S<i32>, i64)
576 fn infer_trait_assoc_method_generics_4() {
580 fn make() -> (Self, T);
583 impl Trait<i64> for S<u64> {}
584 impl Trait<i32> for S<u32> {}
586 let a: (S<u64>, _) = S::make();
587 let b: (_, i32) = S::make();
591 130..202 '{ ...e(); }': ()
592 140..141 'a': (S<u64>, i64)
593 157..164 'S::make': fn make<S<u64>, i64>() -> (S<u64>, i64)
594 157..166 'S::make()': (S<u64>, i64)
595 176..177 'b': (S<u32>, i32)
596 190..197 'S::make': fn make<S<u32>, i32>() -> (S<u32>, i32)
597 190..199 'S::make()': (S<u32>, i32)
603 fn infer_trait_assoc_method_generics_5() {
607 fn make<U>() -> (Self, T, U);
610 impl Trait<i64> for S<u64> {}
612 let a = <S as Trait<i64>>::make::<u8>();
613 let b: (S<u64>, _, _) = Trait::<i64>::make::<u8>();
617 106..210 '{ ...>(); }': ()
618 116..117 'a': (S<u64>, i64, u8)
619 120..149 '<S as ...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8)
620 120..151 '<S as ...<u8>()': (S<u64>, i64, u8)
621 161..162 'b': (S<u64>, i64, u8)
622 181..205 'Trait:...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8)
623 181..207 'Trait:...<u8>()': (S<u64>, i64, u8)
629 fn infer_call_trait_method_on_generic_param_1() {
633 fn method(&self) -> u32;
635 fn test<T: Trait>(t: T) {
642 69..88 '{ ...d(); }': ()
644 75..85 't.method()': u32
650 fn infer_call_trait_method_on_generic_param_2() {
654 fn method(&self) -> T;
656 fn test<U, T: Trait<U>>(t: T) {
663 76..95 '{ ...d(); }': ()
665 82..92 't.method()': U
671 fn infer_with_multiple_trait_impls() {
678 impl Into<u32> for S {}
679 impl Into<u64> for S {}
681 let x: u32 = S.into();
682 let y: u64 = S.into();
683 let z = Into::<u64>::into(S);
688 110..201 '{ ...(S); }': ()
691 129..137 'S.into()': u32
694 156..164 'S.into()': u64
696 178..195 'Into::...::into': fn into<S, u64>(S) -> u64
697 178..198 'Into::...nto(S)': u64
704 fn method_resolution_unify_impl_self_type() {
708 impl S<u32> { fn foo(&self) -> u8 { 0 } }
709 impl S<i32> { fn foo(&self) -> i8 { 0 } }
710 fn test() { (S::<u32>.foo(), S::<i32>.foo()); }
711 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (u8, i8)
717 fn method_resolution_trait_before_autoref() {
720 trait Trait { fn foo(self) -> u128; }
722 impl S { fn foo(&self) -> i8 { 0 } }
723 impl Trait for S { fn foo(self) -> u128 { 0 } }
724 fn test() { S.foo(); }
731 fn method_resolution_by_value_before_autoref() {
734 trait Clone { fn clone(&self) -> Self; }
738 fn test() { (S.clone(), (&S).clone(), (&&S).clone()); }
739 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (S, S, &S)
745 fn method_resolution_trait_before_autoderef() {
748 trait Trait { fn foo(self) -> u128; }
750 impl S { fn foo(self) -> i8 { 0 } }
751 impl Trait for &S { fn foo(self) -> u128 { 0 } }
752 fn test() { (&S).foo(); }
759 fn method_resolution_impl_before_trait() {
762 trait Trait { fn foo(self) -> u128; }
764 impl S { fn foo(self) -> i8 { 0 } }
765 impl Trait for S { fn foo(self) -> u128 { 0 } }
766 fn test() { S.foo(); }
773 fn method_resolution_impl_ref_before_trait() {
776 trait Trait { fn foo(self) -> u128; }
778 impl S { fn foo(&self) -> i8 { 0 } }
779 impl Trait for &S { fn foo(self) -> u128 { 0 } }
780 fn test() { S.foo(); }
787 fn method_resolution_trait_autoderef() {
790 trait Trait { fn foo(self) -> u128; }
792 impl Trait for S { fn foo(self) -> u128 { 0 } }
793 fn test() { (&S).foo(); }
800 fn method_resolution_unsize_array() {
813 fn method_resolution_trait_from_prelude() {
816 //- /main.rs crate:main deps:core
825 //- /lib.rs crate:core
829 fn clone(&self) -> Self;
838 fn method_resolution_where_clause_for_unknown_trait() {
839 // The blanket impl currently applies because we ignore the unresolved where clause
842 trait Trait { fn foo(self) -> u128; }
844 impl<T> Trait for T where T: UnknownTrait {}
845 fn test() { (&S).foo(); }
852 fn method_resolution_where_clause_not_met() {
853 // The blanket impl shouldn't apply because we can't prove S: Clone
854 // This is also to make sure that we don't resolve to the foo method just
855 // because that's the only method named foo we can find, which would make
856 // the below tests not work
860 trait Trait { fn foo(self) -> u128; }
862 impl<T> Trait for T where T: Clone {}
863 fn test() { (&S).foo(); }
864 //^^^^^^^^^^ {unknown}
870 fn method_resolution_where_clause_inline_not_met() {
871 // The blanket impl shouldn't apply because we can't prove S: Clone
875 trait Trait { fn foo(self) -> u128; }
877 impl<T: Clone> Trait for T {}
878 fn test() { (&S).foo(); }
879 //^^^^^^^^^^ {unknown}
885 fn method_resolution_where_clause_1() {
889 trait Trait { fn foo(self) -> u128; }
892 impl<T> Trait for T where T: Clone {}
893 fn test() { S.foo(); }
900 fn method_resolution_where_clause_2() {
903 trait Into<T> { fn into(self) -> T; }
904 trait From<T> { fn from(other: T) -> Self; }
907 impl From<S2> for S1 {}
908 impl<T, U> Into<U> for T where U: From<T> {}
909 fn test() { S2.into(); }
910 //^^^^^^^^^ {unknown}
916 fn method_resolution_where_clause_inline() {
919 trait Into<T> { fn into(self) -> T; }
920 trait From<T> { fn from(other: T) -> Self; }
923 impl From<S2> for S1 {}
924 impl<T, U: From<T>> Into<U> for T {}
925 fn test() { S2.into(); }
926 //^^^^^^^^^ {unknown}
932 fn method_resolution_overloaded_method() {
935 struct Wrapper<T>(T);
939 impl<T> Wrapper<Foo<T>> {
940 pub fn new(foo_: T) -> Self {
945 impl<T> Wrapper<Bar<T>> {
946 pub fn new(bar_: T) -> Self {
952 let a = Wrapper::<Foo<f32>>::new(1.0);
953 let b = Wrapper::<Bar<f32>>::new(1.0);
955 //^^^^^^ (Wrapper<Foo<f32>>, Wrapper<Bar<f32>>)
962 fn method_resolution_overloaded_const() {
963 cov_mark
::check
!(const_candidate_self_type_mismatch
);
966 struct Wrapper<T>(T);
970 impl<T> Wrapper<Foo<T>> {
971 pub const VALUE: Foo<T>;
974 impl<T> Wrapper<Bar<T>> {
975 pub const VALUE: Bar<T>;
979 let a = Wrapper::<Foo<f32>>::VALUE;
980 let b = Wrapper::<Bar<f32>>::VALUE;
982 //^^^^^^ (Foo<f32>, Bar<f32>)
989 fn method_resolution_encountering_fn_type() {
994 trait FnOnce { fn call(self); }
995 fn test() { foo.call(); }
996 //^^^^^^^^^^ {unknown}
1002 fn super_trait_impl_return_trait_method_resolution() {
1007 fn foo(self) -> usize;
1010 trait Super : Base {}
1012 fn base1() -> impl Base { loop {} }
1013 fn super1() -> impl Super { loop {} }
1015 fn test(base2: impl Base, super2: impl Super) {
1024 90..101 '{ loop {} }': !
1027 128..139 '{ loop {} }': !
1028 130..137 'loop {}': !
1030 149..154 'base2': impl Base
1031 167..173 'super2': impl Super
1032 187..264 '{ ...o(); }': ()
1033 193..198 'base1': fn base1() -> impl Base
1034 193..200 'base1()': impl Base
1035 193..206 'base1().foo()': usize
1036 212..218 'super1': fn super1() -> impl Super
1037 212..220 'super1()': impl Super
1038 212..226 'super1().foo()': usize
1039 232..237 'base2': impl Base
1040 232..243 'base2.foo()': usize
1041 249..255 'super2': impl Super
1042 249..261 'super2.foo()': usize
1048 fn method_resolution_non_parameter_type() {
1057 struct Wrapper<T>(T);
1058 fn foo<T>(t: Wrapper<T>)
1063 } //^^^^^^^ {unknown}
1069 fn method_resolution_3373() {
1075 fn from(v: i32) -> A<i32> { A(v) }
1080 } //^^^^^^^^^^ A<i32>
1086 fn method_resolution_slow() {
1087 // this can get quite slow if we set the solver size limit too high
1092 struct S1; impl SendX for S1 {}
1093 struct S2; impl SendX for S2 {}
1096 trait Trait { fn method(self); }
1099 impl<A, B> SendX for X1<A, B> where A: SendX, B: SendX {}
1105 impl<B, C> Trait for S<B, C> where C: FnX, B: SendX {}
1107 fn test() { (S {}).method(); }
1108 //^^^^^^^^^^^^^^^ ()
1114 fn dyn_trait_super_trait_not_in_scope() {
1118 pub trait SuperTrait {
1119 fn foo(&self) -> u32 { 0 }
1122 trait Trait: m::SuperTrait {}
1125 impl m::SuperTrait for S {}
1128 fn test(d: &dyn Trait) {
1133 51..55 'self': &Self
1136 176..177 'd': &dyn Trait
1137 191..207 '{ ...o(); }': ()
1138 197..198 'd': &dyn Trait
1139 197..204 'd.foo()': u32
1145 fn method_resolution_foreign_opaque_type() {
1150 fn f() -> &'static S;
1154 fn foo(&self) -> bool {
1160 let s = unsafe { f() };
1166 89..109 '{ ... }': bool
1167 99..103 'true': bool
1168 123..167 '{ ...o(); }': ()
1170 137..151 'unsafe { f() }': &S
1171 137..151 'unsafe { f() }': &S
1172 146..147 'f': fn f() -> &S
1175 157..164 's.foo()': bool
1181 fn method_with_allocator_box_self_type() {
1188 pub fn into_vec<A>(self: Box<Self, A>) { }
1192 let foo: Slice<u32>;
1193 foo.into_vec(); // we shouldn't crash on this at least
1194 } //^^^^^^^^^^^^^^ {unknown}
1200 fn method_on_dyn_impl() {
1207 pub fn dyn_foo(&self) -> u32 {
1213 let f = &42u32 as &dyn Foo;
1222 fn autoderef_visibility_field() {
1227 pub struct Foo(pub char);
1228 pub struct Bar(i32);
1230 pub fn new() -> Self {
1234 impl core::ops::Deref for Bar {
1236 fn deref(&self) -> &Foo {
1243 let x = super::a::Bar::new().0;
1244 // ^^^^^^^^^^^^^^^^^^^^ adjustments: Deref(Some(OverloadedDeref(Not)))
1245 // ^^^^^^^^^^^^^^^^^^^^^^ type: char
1253 fn autoderef_visibility_method() {
1254 cov_mark
::check
!(autoderef_candidate_not_visible
);
1259 pub struct Foo(pub char);
1261 pub fn mango(&self) -> char {
1265 pub struct Bar(i32);
1267 pub fn new() -> Self {
1270 fn mango(&self) -> i32 {
1274 impl core::ops::Deref for Bar {
1276 fn deref(&self) -> &Foo {
1283 let x = super::a::Bar::new().mango();
1284 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type: char
1292 fn trait_vs_private_inherent_const() {
1293 cov_mark
::check
!(const_candidate_not_visible
);
1299 const VALUE: u32 = 2;
1304 impl Trait for Foo {
1305 const VALUE: usize = 3;
1310 // ^^^^^^^^^^ type: u32
1315 let x = a::Foo::VALUE;
1316 // ^^^^^^^^^^^^^ type: usize
1323 fn trait_impl_in_unnamed_const() {
1329 fn method(&self) -> u16;
1345 fn trait_impl_in_synstructure_const() {
1351 fn method(&self) -> u16;
1354 const _DERIVE_Tr_: () = {
1367 fn inherent_impl_in_unnamed_const() {
1374 fn method(&self) -> u16 { 0 }
1376 pub(super) fn super_method(&self) -> u16 { 0 }
1378 pub(crate) fn crate_method(&self) -> u16 { 0 }
1380 pub fn pub_method(&self) -> u16 { 0 }
1389 //^^^^^^^^^^^^^^^^ u16
1392 //^^^^^^^^^^^^^^^^ u16
1395 //^^^^^^^^^^^^^^ u16
1402 fn resolve_const_generic_array_methods() {
1406 impl<T, const N: usize> [T; N] {
1407 pub fn map<F, U>(self, f: F) -> [U; N]
1415 pub fn map<F, U>(self, f: F) -> &[U]
1422 let v = [1, 2].map::<_, usize>(|x| -> x * 2);
1431 fn resolve_const_generic_method() {
1434 struct Const<const N: usize>;
1437 impl<T, const N: usize> [T; N] {
1438 pub fn my_map<F, U, const X: usize>(self, f: F, c: Const<X>) -> [U; X]
1446 pub fn my_map<F, const X: usize, U>(self, f: F, c: Const<X>) -> &[U]
1452 fn f<const C: usize, P>() {
1453 let v = [1, 2].my_map::<_, (), 12>(|x| -> x * 2, Const::<12>);
1456 let v = [1, 2].my_map::<_, P, C>(|x| -> x * 2, Const::<C>);
1465 fn const_generic_type_alias() {
1468 struct Const<const N: usize>;
1473 fn f(self) -> Const<12> {
1479 fn f(self) -> Const<15> {
1493 fn skip_array_during_method_dispatch() {
1496 //- /main2018.rs crate:main2018 deps:core
1497 use core::IntoIterator;
1500 let v = [4].into_iter();
1504 let a = [0, 1].into_iter();
1509 //- /main2021.rs crate:main2021 deps:core edition:2021
1510 use core::IntoIterator;
1513 let v = [4].into_iter();
1517 let a = [0, 1].into_iter();
1522 //- /core.rs crate:core
1523 #[rustc_skip_array_during_method_dispatch]
1524 pub trait IntoIterator {
1526 fn into_iter(self) -> Self::Out;
1529 impl<T> IntoIterator for [T; 1] {
1531 fn into_iter(self) -> Self::Out { loop {} }
1533 impl<'a, T> IntoIterator for &'a [T] {
1535 fn into_iter(self) -> Self::Out { loop {} }
1542 fn sized_blanket_impl() {
1546 trait Foo { fn foo() -> u8; }
1547 impl<T: Sized> Foo for T {}
1548 fn f<S: Sized, T, U: ?Sized>() {
1557 89..160 '{ ...foo; }': ()
1558 95..103 'u32::foo': fn foo<u32>() -> u8
1559 109..115 'S::foo': fn foo<S>() -> u8
1560 121..127 'T::foo': fn foo<T>() -> u8
1561 133..139 'U::foo': {unknown}
1562 145..157 '<[u32]>::foo': {unknown}
1572 struct SomeStruct(i32);
1575 fn is_even(&self) -> bool {
1580 let o = SomeStruct(3);
1581 let is_even = o.is_even();
1594 struct A<T, U>(T, U);
1598 impl<T> core::ops::Deref for A<B<T>, u32> {
1600 fn deref(&self) -> &B<T> { &self.0 }
1602 impl core::ops::Deref for B<isize> {
1603 type Target = C<isize>;
1604 fn deref(&self) -> &C<isize> { loop {} }
1607 impl<T: Copy> C<T> {
1608 fn thing(&self) -> T { self.0 }
1611 fn make<T>() -> T { loop {} }
1614 let a1 = A(make(), make());
1615 let _: usize = (*a1).0;
1617 //^^ A<B<usize>, u32>
1619 let a2 = A(make(), make());
1623 //^^ A<B<isize>, u32>
1635 struct A<T, U>(T, U);
1639 impl<T> core::ops::Deref for A<B<T>, u32> {
1641 fn deref(&self) -> &B<T> { &self.0 }
1643 impl core::ops::Deref for B<isize> {
1644 type Target = C<isize>;
1645 fn deref(&self) -> &C<isize> { loop {} }
1648 impl<T> core::ops::Deref for A<C<T>, i32> {
1650 fn deref(&self) -> &C<T> { &self.0 }
1653 impl<T: Copy> C<T> {
1654 fn thing(&self) -> T { self.0 }
1657 fn make<T>() -> T { loop {} }
1660 let a1 = A(make(), 1u32);
1663 //^^ A<B<isize>, u32>
1665 let a2 = A(make(), 1i32);
1666 let _: &str = a2.thing();
1668 //^^ A<C<&str>, i32>
1675 fn receiver_adjustment_autoref() {
1684 //^^^ adjustments: Borrow(Ref(Not))
1686 // ^^^^ adjustments: ,
1693 fn receiver_adjustment_unsize_array() {
1694 // FIXME not quite correct
1701 } //^ adjustments: Pointer(Unsize), Borrow(Ref(Not))
1707 fn bad_inferred_reference_1() {
1708 check_no_mismatches(
1711 pub trait Into<T>: Sized {
1714 impl<T> Into<T> for T {
1715 fn into(self) -> T { self }
1718 trait ExactSizeIterator {
1719 fn len(&self) -> usize;
1724 fn len(&self) -> usize { 0 }
1727 pub fn test(generic_args: impl Into<Foo>) {
1728 let generic_args = generic_args.into();
1730 let _: Foo = generic_args;
1737 fn bad_inferred_reference_2() {
1738 check_no_mismatches(
1741 trait ExactSizeIterator {
1742 fn len(&self) -> usize;
1747 fn len(&self) -> usize { 0 }
1753 let _: Foo = generic_args;
1760 fn resolve_minicore_iterator() {
1763 //- minicore: iterators, sized
1765 let m = core::iter::repeat(()).filter_map(|()| Some(92)).next();
1766 } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Option<i32>
1772 fn primitive_assoc_fn_shadowed_by_use() {
1775 //- /lib.rs crate:lib deps:core
1779 let x = u16::from_le_bytes();
1784 //- /core.rs crate:core
1788 pub fn from_le_bytes() -> Self { 0 }
1795 fn with_impl_bounds() {
1800 impl Trait for isize {}
1802 impl<T: Trait> Foo<T> {
1803 fn foo() -> isize { 0 }
1804 fn bar(&self) -> isize { 0 }
1813 let _ = Foo::<isize>::foo();
1815 let _ = Foo(0isize).bar();
1817 let _ = Foo::<()>::foo();
1819 let _ = Foo(()).bar();
1821 let _ = Foo::<usize>::foo();
1823 let _ = Foo(0usize).bar();
1827 fn g<T: Trait>(a: T) {
1828 let _ = Foo::<T>::foo();
1830 let _ = Foo(a).bar();