]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
0bf4aa26 | 2 | #![allow(dead_code)] |
223e47cc LB |
3 | // Testing that we can cast to a subtrait and call subtrait |
4 | // methods. Not testing supertrait methods | |
5 | ||
c34b1796 | 6 | |
223e47cc | 7 | trait Foo { |
c34b1796 | 8 | fn f(&self) -> isize; |
223e47cc LB |
9 | } |
10 | ||
11 | trait Bar : Foo { | |
c34b1796 | 12 | fn g(&self) -> isize; |
223e47cc LB |
13 | } |
14 | ||
15 | struct A { | |
c34b1796 | 16 | x: isize |
223e47cc LB |
17 | } |
18 | ||
19 | impl Foo for A { | |
c34b1796 | 20 | fn f(&self) -> isize { 10 } |
223e47cc LB |
21 | } |
22 | ||
23 | impl Bar for A { | |
c34b1796 | 24 | fn g(&self) -> isize { 20 } |
223e47cc LB |
25 | } |
26 | ||
27 | pub fn main() { | |
28 | let a = &A { x: 3 }; | |
dc9dc135 XL |
29 | let afoo = a as &dyn Foo; |
30 | let abar = a as &dyn Bar; | |
970d7e83 LB |
31 | assert_eq!(afoo.f(), 10); |
32 | assert_eq!(abar.g(), 20); | |
223e47cc | 33 | } |