]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/traits/trait-inheritance-subst2.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / test / run-pass / traits / trait-inheritance-subst2.rs
1 // run-pass
2
3 trait Panda<T> {
4 fn chomp(&self, bamboo: &T) -> T;
5 }
6
7 trait Add<RHS,Result>: Panda<RHS> {
8 fn add(&self, rhs: &RHS) -> Result;
9 }
10
11 trait MyNum : Sized + Add<Self,Self> { }
12
13 struct MyInt { val: isize }
14
15 impl Panda<MyInt> for MyInt {
16 fn chomp(&self, bamboo: &MyInt) -> MyInt {
17 mi(self.val + bamboo.val)
18 }
19 }
20
21 impl Add<MyInt, MyInt> for MyInt {
22 fn add(&self, other: &MyInt) -> MyInt { self.chomp(other) }
23 }
24
25 impl MyNum for MyInt {}
26
27 fn f<T:MyNum>(x: T, y: T) -> T {
28 return x.add(&y).chomp(&y);
29 }
30
31 fn mi(v: isize) -> MyInt { MyInt { val: v } }
32
33 pub fn main() {
34 let (x, y) = (mi(3), mi(5));
35 let z = f(x, y);
36 assert_eq!(z.val, 13);
37 }