1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test that we evaluate projection predicates to winnow out
12 // candidates during trait selection and method resolution (#20296).
13 // If we don't properly winnow out candidates based on the output type
14 // `Target=[A]`, then the impl marked with `(*)` is seen to conflict
15 // with all the others.
17 use std::marker::PhantomData;
20 pub trait MyEq<U: ?Sized=Self> {
21 fn eq(&self, u: &U) -> bool;
24 impl<A, B> MyEq<[B]> for [A]
27 fn eq(&self, other: &[B]) -> bool {
28 self.len() == other.len() &&
29 self.iter().zip(other.iter())
30 .all(|(a, b)| MyEq::eq(a, b))
34 // (*) This impl conflicts with everything unless the `Target=[A]`
35 // constraint is considered.
36 impl<'a, A, B, Lhs> MyEq<[B; 0]> for Lhs
37 where A: MyEq<B>, Lhs: Deref<Target=[A]>
39 fn eq(&self, other: &[B; 0]) -> bool {
40 MyEq::eq(&**self, other)
44 struct DerefWithHelper<H, T> {
46 pub marker: PhantomData<T>,
50 fn helper_borrow(&self) -> &T;
53 impl<T> Helper<T> for Option<T> {
54 fn helper_borrow(&self) -> &T {
55 self.as_ref().unwrap()
59 impl<T, H: Helper<T>> Deref for DerefWithHelper<H, T> {
62 fn deref(&self) -> &T {
63 self.helper.helper_borrow()
67 pub fn check<T: MyEq>(x: T, y: T) -> bool {
68 let d: DerefWithHelper<Option<T>, T> = DerefWithHelper { helper: Some(x),
69 marker: PhantomData };