2 // Test that we evaluate projection predicates to winnow out
3 // candidates during trait selection and method resolution (#20296).
4 // If we don't properly winnow out candidates based on the output type
5 // `Target=[A]`, then the impl marked with `(*)` is seen to conflict
6 // with all the others.
8 // pretty-expanded FIXME #23616
10 use std::marker::PhantomData;
13 pub trait MyEq<U: ?Sized=Self> {
14 fn eq(&self, u: &U) -> bool;
17 impl<A, B> MyEq<[B]> for [A]
20 fn eq(&self, other: &[B]) -> bool {
21 self.len() == other.len() &&
22 self.iter().zip(other).all(|(a, b)| MyEq::eq(a, b))
26 // (*) This impl conflicts with everything unless the `Target=[A]`
27 // constraint is considered.
28 impl<'a, A, B, Lhs> MyEq<[B; 0]> for Lhs
29 where A: MyEq<B>, Lhs: Deref<Target=[A]>
31 fn eq(&self, other: &[B; 0]) -> bool {
32 MyEq::eq(&**self, other)
36 struct DerefWithHelper<H, T> {
38 pub marker: PhantomData<T>,
42 fn helper_borrow(&self) -> &T;
45 impl<T> Helper<T> for Option<T> {
46 fn helper_borrow(&self) -> &T {
47 self.as_ref().unwrap()
51 impl<T, H: Helper<T>> Deref for DerefWithHelper<H, T> {
54 fn deref(&self) -> &T {
55 self.helper.helper_borrow()
59 pub fn check<T: MyEq>(x: T, y: T) -> bool {
60 let d: DerefWithHelper<Option<T>, T> = DerefWithHelper { helper: Some(x),
61 marker: PhantomData };