Implement trait inheritance for bounded type parameters
This commit is contained in:
parent
daa89e0861
commit
78ee821154
38 changed files with 1004 additions and 176 deletions
11
src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs
Normal file
11
src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
pub trait Foo { fn f() -> int; }
|
||||
pub trait Bar { fn g() -> int; }
|
||||
pub trait Baz { fn h() -> int; }
|
||||
|
||||
pub struct A { x: int }
|
||||
|
||||
impl A : Foo { fn f() -> int { 10 } }
|
||||
impl A : Bar { fn g() -> int { 20 } }
|
||||
impl A : Baz { fn h() -> int { 30 } }
|
||||
|
||||
|
||||
7
src/test/auxiliary/trait_inheritance_auto_xc_aux.rs
Normal file
7
src/test/auxiliary/trait_inheritance_auto_xc_aux.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
trait Foo { fn f() -> int; }
|
||||
trait Bar { fn g() -> int; }
|
||||
trait Baz { fn h() -> int; }
|
||||
|
||||
trait Quux: Foo, Bar, Baz { }
|
||||
|
||||
impl<T: Foo Bar Baz> T: Quux { }
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
pub trait Foo {
|
||||
fn f() -> int;
|
||||
}
|
||||
|
||||
pub struct A {
|
||||
x: int
|
||||
}
|
||||
|
||||
impl A : Foo {
|
||||
fn f() -> int { 10 }
|
||||
}
|
||||
|
|
@ -1,9 +1,31 @@
|
|||
pub trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
|
||||
use cmp::Eq;
|
||||
|
||||
pub trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self>, Eq {
|
||||
}
|
||||
|
||||
pub impl int : MyNum {
|
||||
pure fn add(other: &int) -> int { self + *other }
|
||||
pure fn sub(&self, other: &int) -> int { *self - *other }
|
||||
pure fn mul(&self, other: &int) -> int { *self * *other }
|
||||
pub struct MyInt {
|
||||
val: int
|
||||
}
|
||||
|
||||
pub impl MyInt : Add<MyInt, MyInt> {
|
||||
pure fn add(other: &MyInt) -> MyInt { mi(self.val + other.val) }
|
||||
}
|
||||
|
||||
pub impl MyInt : Sub<MyInt, MyInt> {
|
||||
pure fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) }
|
||||
}
|
||||
|
||||
pub impl MyInt : Mul<MyInt, MyInt> {
|
||||
pure fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) }
|
||||
}
|
||||
|
||||
pub impl MyInt : Eq {
|
||||
pure fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
|
||||
|
||||
pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
|
||||
}
|
||||
|
||||
pub impl MyInt : MyNum;
|
||||
|
||||
pure fn mi(v: int) -> MyInt { MyInt { val: v } }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue