]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/trait-inheritance-cast.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / trait-inheritance-cast.rs
CommitLineData
1a4d82fc 1// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
223e47cc
LB
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
223e47cc 11// Testing that supertrait methods can be called on subtrait object types
223e47cc 12
c34b1796
AL
13// pretty-expanded FIXME #23616
14
223e47cc 15trait Foo {
c34b1796 16 fn f(&self) -> isize;
223e47cc
LB
17}
18
19trait Bar : Foo {
c34b1796 20 fn g(&self) -> isize;
223e47cc
LB
21}
22
23struct A {
c34b1796 24 x: isize
223e47cc
LB
25}
26
27impl Foo for A {
c34b1796 28 fn f(&self) -> isize { 10 }
223e47cc
LB
29}
30
31impl Bar for A {
c34b1796 32 fn g(&self) -> isize { 20 }
223e47cc
LB
33}
34
35pub fn main() {
36 let a = &A { x: 3 };
37 let afoo = a as &Foo;
38 let abar = a as &Bar;
970d7e83
LB
39 assert_eq!(afoo.f(), 10);
40 assert_eq!(abar.g(), 20);
41 assert_eq!(abar.f(), 10);
223e47cc 42}