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