]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs
68a31ba9dbe64b179f8385694e1b5af9fb91c45d
[rust.git] / src / test / run-pass / trait-inheritance-cast-without-call-to-supertrait.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Testing that we can cast to a subtrait and call subtrait
12 // methods. Not testing supertrait methods
13
14 trait Foo {
15     fn f(&self) -> int;
16 }
17
18 trait Bar : Foo {
19     fn g(&self) -> int;
20 }
21
22 struct A {
23     x: int
24 }
25
26 impl Foo for A {
27     fn f(&self) -> int { 10 }
28 }
29
30 impl Bar for A {
31     fn g(&self) -> int { 20 }
32 }
33
34 pub fn main() {
35     let a = &A { x: 3 };
36     let afoo = a as &Foo;
37     let abar = a as &Bar;
38     assert_eq!(afoo.f(), 10);
39     assert_eq!(abar.g(), 20);
40 }