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
25
src/test/run-pass/trait-inheritance-overloading-simple.rs
Normal file
25
src/test/run-pass/trait-inheritance-overloading-simple.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use cmp::Eq;
|
||||
|
||||
trait MyNum : Eq { }
|
||||
|
||||
struct MyInt { val: int }
|
||||
|
||||
impl MyInt : Eq {
|
||||
pure fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
|
||||
pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
|
||||
}
|
||||
|
||||
impl MyInt : MyNum;
|
||||
|
||||
fn f<T:MyNum>(x: T, y: T) -> bool {
|
||||
return x == y;
|
||||
}
|
||||
|
||||
pure fn mi(v: int) -> MyInt { MyInt { val: v } }
|
||||
|
||||
fn main() {
|
||||
let (x, y, z) = (mi(3), mi(5), mi(3));
|
||||
assert x != y;
|
||||
assert x == z;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue