]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/trait-inheritance-cast.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / trait-inheritance-cast.rs
1 // Copyright 2012-2014 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 supertrait methods can be called on subtrait object types
12
13 // pretty-expanded FIXME #23616
14
15 trait Foo {
16     fn f(&self) -> int;
17 }
18
19 trait Bar : Foo {
20     fn g(&self) -> int;
21 }
22
23 struct A {
24     x: int
25 }
26
27 impl Foo for A {
28     fn f(&self) -> int { 10 }
29 }
30
31 impl Bar for A {
32     fn g(&self) -> int { 20 }
33 }
34
35 pub fn main() {
36     let a = &A { x: 3 };
37     let afoo = a as &Foo;
38     let abar = a as &Bar;
39     assert_eq!(afoo.f(), 10);
40     assert_eq!(abar.g(), 20);
41     assert_eq!(abar.f(), 10);
42 }