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 133..139 '{ 99 }': u32
193 217..225 '{ C {} }': C
195 256..340 '{ ...g(); }': ()
197 270..281 'a::A::thing': fn thing() -> A
198 270..283 'a::A::thing()': A
200 297..308 'b::B::thing': fn thing() -> u32
201 297..310 'b::B::thing()': u32
203 324..335 'c::C::thing': fn thing() -> C
204 324..337 '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 edition:2018 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 explicit_fn_once_call_fn_item() {
994 fn test() { foo.call_once(); }
1001 fn super_trait_impl_return_trait_method_resolution() {
1006 fn foo(self) -> usize;
1009 trait Super : Base {}
1011 fn base1() -> impl Base { loop {} }
1012 fn super1() -> impl Super { loop {} }
1014 fn test(base2: impl Base, super2: impl Super) {
1023 90..101 '{ loop {} }': !
1026 128..139 '{ loop {} }': !
1027 130..137 'loop {}': !
1029 149..154 'base2': impl Base
1030 167..173 'super2': impl Super
1031 187..264 '{ ...o(); }': ()
1032 193..198 'base1': fn base1() -> impl Base
1033 193..200 'base1()': impl Base
1034 193..206 'base1().foo()': usize
1035 212..218 'super1': fn super1() -> impl Super
1036 212..220 'super1()': impl Super
1037 212..226 'super1().foo()': usize
1038 232..237 'base2': impl Base
1039 232..243 'base2.foo()': usize
1040 249..255 'super2': impl Super
1041 249..261 'super2.foo()': usize
1047 fn method_resolution_non_parameter_type() {
1056 struct Wrapper<T>(T);
1057 fn foo<T>(t: Wrapper<T>)
1062 } //^^^^^^^ {unknown}
1068 fn method_resolution_3373() {
1074 fn from(v: i32) -> A<i32> { A(v) }
1079 } //^^^^^^^^^^ A<i32>
1085 fn method_resolution_slow() {
1086 // this can get quite slow if we set the solver size limit too high
1091 struct S1; impl SendX for S1 {}
1092 struct S2; impl SendX for S2 {}
1095 trait Trait { fn method(self); }
1098 impl<A, B> SendX for X1<A, B> where A: SendX, B: SendX {}
1104 impl<B, C> Trait for S<B, C> where C: FnX, B: SendX {}
1106 fn test() { (S {}).method(); }
1107 //^^^^^^^^^^^^^^^ ()
1113 fn dyn_trait_super_trait_not_in_scope() {
1117 pub trait SuperTrait {
1118 fn foo(&self) -> u32 { 0 }
1121 trait Trait: m::SuperTrait {}
1124 impl m::SuperTrait for S {}
1127 fn test(d: &dyn Trait) {
1132 51..55 'self': &Self
1135 176..177 'd': &dyn Trait
1136 191..207 '{ ...o(); }': ()
1137 197..198 'd': &dyn Trait
1138 197..204 'd.foo()': u32
1144 fn method_resolution_foreign_opaque_type() {
1149 fn f() -> &'static S;
1153 fn foo(&self) -> bool {
1159 let s = unsafe { f() };
1165 89..109 '{ ... }': bool
1166 99..103 'true': bool
1167 123..167 '{ ...o(); }': ()
1169 137..151 'unsafe { f() }': &S
1170 137..151 'unsafe { f() }': &S
1171 146..147 'f': fn f() -> &S
1174 157..164 's.foo()': bool
1180 fn method_with_allocator_box_self_type() {
1187 pub fn into_vec<A>(self: Box<Self, A>) { }
1191 let foo: Slice<u32>;
1192 foo.into_vec(); // we shouldn't crash on this at least
1193 } //^^^^^^^^^^^^^^ {unknown}
1199 fn method_on_dyn_impl() {
1206 pub fn dyn_foo(&self) -> u32 {
1212 let f = &42u32 as &dyn Foo;
1221 fn dyn_trait_method_priority() {
1226 fn into(&self) -> usize { 0 }
1229 fn foo(a: &dyn Trait) {
1238 fn trait_method_priority_for_placeholder_type() {
1243 fn into(&self) -> usize { 0 }
1246 fn foo<T: Trait>(a: &T) {
1255 fn autoderef_visibility_field() {
1260 pub struct Foo(pub char);
1261 pub struct Bar(i32);
1263 pub fn new() -> Self {
1267 impl core::ops::Deref for Bar {
1269 fn deref(&self) -> &Foo {
1276 let x = super::a::Bar::new().0;
1277 // ^^^^^^^^^^^^^^^^^^^^ adjustments: Deref(Some(OverloadedDeref(Not)))
1278 // ^^^^^^^^^^^^^^^^^^^^^^ type: char
1286 fn autoderef_visibility_method() {
1287 cov_mark
::check
!(autoderef_candidate_not_visible
);
1292 pub struct Foo(pub char);
1294 pub fn mango(&self) -> char {
1298 pub struct Bar(i32);
1300 pub fn new() -> Self {
1303 fn mango(&self) -> i32 {
1307 impl core::ops::Deref for Bar {
1309 fn deref(&self) -> &Foo {
1316 let x = super::a::Bar::new().mango();
1317 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type: char
1325 fn trait_vs_private_inherent_const() {
1326 cov_mark
::check
!(const_candidate_not_visible
);
1332 const VALUE: u32 = 2;
1337 impl Trait for Foo {
1338 const VALUE: usize = 3;
1343 // ^^^^^^^^^^ type: u32
1348 let x = a::Foo::VALUE;
1349 // ^^^^^^^^^^^^^ type: usize
1356 fn trait_impl_in_unnamed_const() {
1362 fn method(&self) -> u16;
1378 fn trait_impl_in_synstructure_const() {
1384 fn method(&self) -> u16;
1387 const _DERIVE_Tr_: () = {
1400 fn inherent_impl_in_unnamed_const() {
1407 fn method(&self) -> u16 { 0 }
1409 pub(super) fn super_method(&self) -> u16 { 0 }
1411 pub(crate) fn crate_method(&self) -> u16 { 0 }
1413 pub fn pub_method(&self) -> u16 { 0 }
1422 //^^^^^^^^^^^^^^^^ u16
1425 //^^^^^^^^^^^^^^^^ u16
1428 //^^^^^^^^^^^^^^ u16
1435 fn resolve_const_generic_array_methods() {
1439 impl<T, const N: usize> [T; N] {
1440 pub fn map<F, U>(self, f: F) -> [U; N]
1448 pub fn map<F, U>(self, f: F) -> &[U]
1455 let v = [1, 2].map::<_, usize>(|x| -> x * 2);
1464 fn resolve_const_generic_method() {
1467 struct Const<const N: usize>;
1470 impl<T, const N: usize> [T; N] {
1471 pub fn my_map<F, U, const X: usize>(self, f: F, c: Const<X>) -> [U; X]
1479 pub fn my_map<F, const X: usize, U>(self, f: F, c: Const<X>) -> &[U]
1485 fn f<const C: usize, P>() {
1486 let v = [1, 2].my_map::<_, (), 12>(|x| -> x * 2, Const::<12>);
1489 let v = [1, 2].my_map::<_, P, C>(|x| -> x * 2, Const::<C>);
1498 fn const_generic_type_alias() {
1501 struct Const<const N: usize>;
1506 fn f(self) -> Const<12> {
1512 fn f(self) -> Const<15> {
1526 fn skip_array_during_method_dispatch() {
1529 //- /main2018.rs crate:main2018 deps:core edition:2018
1530 use core::IntoIterator;
1533 let v = [4].into_iter();
1537 let a = [0, 1].into_iter();
1542 //- /main2021.rs crate:main2021 deps:core edition:2021
1543 use core::IntoIterator;
1546 let v = [4].into_iter();
1550 let a = [0, 1].into_iter();
1555 //- /core.rs crate:core
1556 #[rustc_skip_array_during_method_dispatch]
1557 pub trait IntoIterator {
1559 fn into_iter(self) -> Self::Out;
1562 impl<T> IntoIterator for [T; 1] {
1564 fn into_iter(self) -> Self::Out { loop {} }
1566 impl<'a, T> IntoIterator for &'a [T] {
1568 fn into_iter(self) -> Self::Out { loop {} }
1575 fn sized_blanket_impl() {
1579 trait Foo { fn foo() -> u8; }
1580 impl<T: Sized> Foo for T {}
1581 fn f<S: Sized, T, U: ?Sized>() {
1590 89..160 '{ ...foo; }': ()
1591 95..103 'u32::foo': fn foo<u32>() -> u8
1592 109..115 'S::foo': fn foo<S>() -> u8
1593 121..127 'T::foo': fn foo<T>() -> u8
1594 133..139 'U::foo': {unknown}
1595 145..157 '<[u32]>::foo': {unknown}
1605 struct SomeStruct(i32);
1608 fn is_even(&self) -> bool {
1613 let o = SomeStruct(3);
1614 let is_even = o.is_even();
1627 struct A<T, U>(T, U);
1631 impl<T> core::ops::Deref for A<B<T>, u32> {
1633 fn deref(&self) -> &B<T> { &self.0 }
1635 impl core::ops::Deref for B<isize> {
1636 type Target = C<isize>;
1637 fn deref(&self) -> &C<isize> { loop {} }
1640 impl<T: Copy> C<T> {
1641 fn thing(&self) -> T { self.0 }
1644 fn make<T>() -> T { loop {} }
1647 let a1 = A(make(), make());
1648 let _: usize = (*a1).0;
1650 //^^ A<B<usize>, u32>
1652 let a2 = A(make(), make());
1656 //^^ A<B<isize>, u32>
1668 struct A<T, U>(T, U);
1672 impl<T> core::ops::Deref for A<B<T>, u32> {
1674 fn deref(&self) -> &B<T> { &self.0 }
1676 impl core::ops::Deref for B<isize> {
1677 type Target = C<isize>;
1678 fn deref(&self) -> &C<isize> { loop {} }
1681 impl<T> core::ops::Deref for A<C<T>, i32> {
1683 fn deref(&self) -> &C<T> { &self.0 }
1686 impl<T: Copy> C<T> {
1687 fn thing(&self) -> T { self.0 }
1690 fn make<T>() -> T { loop {} }
1693 let a1 = A(make(), 1u32);
1696 //^^ A<B<isize>, u32>
1698 let a2 = A(make(), 1i32);
1699 let _: &str = a2.thing();
1701 //^^ A<C<&str>, i32>
1708 fn receiver_adjustment_autoref() {
1717 //^^^ adjustments: Borrow(Ref(Not))
1719 // ^^^^ adjustments: ,
1726 fn receiver_adjustment_unsize_array() {
1733 } //^ adjustments: Borrow(Ref(Not)), Pointer(Unsize)
1739 fn bad_inferred_reference_1() {
1740 check_no_mismatches(
1743 pub trait Into<T>: Sized {
1746 impl<T> Into<T> for T {
1747 fn into(self) -> T { self }
1750 trait ExactSizeIterator {
1751 fn len(&self) -> usize;
1756 fn len(&self) -> usize { 0 }
1759 pub fn test(generic_args: impl Into<Foo>) {
1760 let generic_args = generic_args.into();
1762 let _: Foo = generic_args;
1769 fn bad_inferred_reference_2() {
1770 check_no_mismatches(
1773 trait ExactSizeIterator {
1774 fn len(&self) -> usize;
1779 fn len(&self) -> usize { 0 }
1785 let _: Foo = generic_args;
1792 fn resolve_minicore_iterator() {
1795 //- minicore: iterators, sized
1797 let m = core::iter::repeat(()).filter_map(|()| Some(92)).next();
1798 } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Option<i32>
1804 fn primitive_assoc_fn_shadowed_by_use() {
1807 //- /lib.rs crate:lib deps:core
1811 let x = u16::from_le_bytes();
1816 //- /core.rs crate:core
1820 pub fn from_le_bytes() -> Self { 0 }
1827 fn with_impl_bounds() {
1832 impl Trait for isize {}
1834 impl<T: Trait> Foo<T> {
1835 fn foo() -> isize { 0 }
1836 fn bar(&self) -> isize { 0 }
1845 let _ = Foo::<isize>::foo();
1847 let _ = Foo(0isize).bar();
1849 let _ = Foo::<()>::foo();
1851 let _ = Foo(()).bar();
1853 let _ = Foo::<usize>::foo();
1855 let _ = Foo(0usize).bar();
1859 fn g<T: Trait>(a: T) {
1860 let _ = Foo::<T>::foo();
1862 let _ = Foo(a).bar();
1870 fn incoherent_impls() {
1873 //- minicore: error, send
1874 pub struct Box<T>(T);
1875 use core::error::Error;
1877 #[rustc_allow_incoherent_impl]
1879 pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error>> {
1883 #[rustc_allow_incoherent_impl]
1884 impl dyn Error + Send {
1885 /// Attempts to downcast the box to a concrete type.
1886 pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error + Send>> {
1887 let err: Box<dyn Error> = self;
1888 // ^^^^ expected Box<dyn Error>, got Box<dyn Error + Send>
1889 // FIXME, type mismatch should not occur
1890 <dyn Error>::downcast(err).map_err(|_| loop {})
1891 //^^^^^^^^^^^^^^^^^^^^^ type: fn downcast<{unknown}>(Box<dyn Error>) -> Result<Box<{unknown}>, Box<dyn Error>>
1899 fn fallback_private_methods() {
1911 let s = module::Struct;