2013-06-12 16:22:17 -05:00
|
|
|
// xfail-fast
|
|
|
|
// aux-build:trait_default_method_xc_aux.rs
|
|
|
|
|
|
|
|
#[allow(default_methods)];
|
|
|
|
|
|
|
|
extern mod aux(name = "trait_default_method_xc_aux");
|
2013-07-02 16:39:25 -05:00
|
|
|
use aux::{A, B, TestEquality, Something};
|
2013-06-12 16:22:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
fn f<T: aux::A>(i: T) {
|
|
|
|
assert_eq!(i.g(), 10);
|
|
|
|
}
|
|
|
|
|
2013-07-02 16:39:25 -05:00
|
|
|
mod stuff {
|
|
|
|
pub struct thing { x: int }
|
|
|
|
}
|
2013-06-12 16:22:17 -05:00
|
|
|
|
2013-07-02 16:39:25 -05:00
|
|
|
impl A for stuff::thing {
|
2013-06-12 16:22:17 -05:00
|
|
|
fn f(&self) -> int { 10 }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn g<T, U, V: B<T>>(i: V, j: T, k: U) -> (T, U) {
|
|
|
|
i.thing(j, k)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn eq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
|
|
|
|
lhs.test_eq(rhs)
|
|
|
|
}
|
|
|
|
fn neq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
|
|
|
|
lhs.test_neq(rhs)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-02 16:39:25 -05:00
|
|
|
impl TestEquality for stuff::thing {
|
|
|
|
fn test_eq(&self, rhs: &stuff::thing) -> bool {
|
2013-06-12 16:22:17 -05:00
|
|
|
//self.x.test_eq(&rhs.x)
|
|
|
|
eq(&self.x, &rhs.x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main () {
|
|
|
|
// Some tests of random things
|
|
|
|
f(0);
|
|
|
|
|
2013-07-02 16:39:25 -05:00
|
|
|
let a = stuff::thing { x: 0 };
|
|
|
|
let b = stuff::thing { x: 1 };
|
|
|
|
let c = Something { x: 1 };
|
2013-06-12 16:22:17 -05:00
|
|
|
|
2013-07-02 16:39:25 -05:00
|
|
|
assert_eq!(0i.g(), 10);
|
2013-06-12 16:22:17 -05:00
|
|
|
assert_eq!(a.g(), 10);
|
|
|
|
assert_eq!(a.h(), 10);
|
2013-07-02 16:39:25 -05:00
|
|
|
assert_eq!(c.h(), 10);
|
2013-06-12 16:22:17 -05:00
|
|
|
|
2013-07-02 16:39:25 -05:00
|
|
|
0i.thing(3.14, 1);
|
|
|
|
assert_eq!(0i.thing(3.14, 1), (3.14, 1));
|
2013-06-12 16:22:17 -05:00
|
|
|
|
|
|
|
assert_eq!(g(0i, 3.14, 1), (3.14, 1));
|
|
|
|
assert_eq!(g(false, 3.14, 1), (3.14, 1));
|
|
|
|
|
|
|
|
let obj = @0i as @A;
|
|
|
|
assert_eq!(obj.h(), 10);
|
|
|
|
|
|
|
|
|
|
|
|
// Trying out a real one
|
2013-07-02 16:39:25 -05:00
|
|
|
assert!(12.test_neq(&10));
|
|
|
|
assert!(!10.test_neq(&10));
|
2013-06-12 16:22:17 -05:00
|
|
|
assert!(a.test_neq(&b));
|
|
|
|
assert!(!a.test_neq(&a));
|
|
|
|
|
|
|
|
assert!(neq(&12, &10));
|
|
|
|
assert!(!neq(&10, &10));
|
|
|
|
assert!(neq(&a, &b));
|
|
|
|
assert!(!neq(&a, &a));
|
|
|
|
}
|