Get cross crate static default methods working. Closes #7569.
This commit is contained in:
parent
1bbb434880
commit
186f6faf1e
8 changed files with 40 additions and 31 deletions
|
|
@ -5,7 +5,8 @@ pub struct Something { x: int }
|
|||
pub trait A {
|
||||
fn f(&self) -> int;
|
||||
fn g(&self) -> int { 10 }
|
||||
fn h(&self) -> int { 10 }
|
||||
fn h(&self) -> int { 11 }
|
||||
fn lurr(x: &Self, y: &Self) -> int { x.g() + y.h() }
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -19,6 +20,7 @@ impl A for Something {
|
|||
|
||||
trait B<T> {
|
||||
fn thing<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
|
||||
fn staticthing<U>(z: &Self, x: T, y: U) -> (T, U) { (x, y) }
|
||||
}
|
||||
|
||||
impl<T> B<T> for int { }
|
||||
|
|
|
|||
|
|
@ -4,13 +4,17 @@
|
|||
#[allow(default_methods)];
|
||||
|
||||
extern mod aux(name = "trait_default_method_xc_aux");
|
||||
use aux::{A, B, TestEquality, Something};
|
||||
|
||||
use aux::{A, TestEquality, Something};
|
||||
use aux::B;
|
||||
|
||||
fn f<T: aux::A>(i: T) {
|
||||
assert_eq!(i.g(), 10);
|
||||
}
|
||||
|
||||
fn welp<T>(i: int, x: &T) -> int {
|
||||
i.g()
|
||||
}
|
||||
|
||||
mod stuff {
|
||||
pub struct thing { x: int }
|
||||
}
|
||||
|
|
@ -43,23 +47,26 @@ fn main () {
|
|||
// Some tests of random things
|
||||
f(0);
|
||||
|
||||
assert_eq!(A::lurr(&0, &1), 21);
|
||||
|
||||
let a = stuff::thing { x: 0 };
|
||||
let b = stuff::thing { x: 1 };
|
||||
let c = Something { x: 1 };
|
||||
|
||||
assert_eq!(0i.g(), 10);
|
||||
assert_eq!(a.g(), 10);
|
||||
assert_eq!(a.h(), 10);
|
||||
assert_eq!(c.h(), 10);
|
||||
assert_eq!(a.h(), 11);
|
||||
assert_eq!(c.h(), 11);
|
||||
|
||||
0i.thing(3.14, 1);
|
||||
assert_eq!(0i.thing(3.14, 1), (3.14, 1));
|
||||
assert_eq!(B::staticthing(&0i, 3.14, 1), (3.14, 1));
|
||||
assert_eq!(B::staticthing::<float, int, int>(&0i, 3.14, 1), (3.14, 1));
|
||||
|
||||
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);
|
||||
assert_eq!(obj.h(), 11);
|
||||
|
||||
|
||||
// Trying out a real one
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue