]> git.proxmox.com Git - rustc.git/blame - src/test/ui/traits/inheritance/cast-without-call-to-supertrait.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / traits / inheritance / cast-without-call-to-supertrait.rs
CommitLineData
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 7trait Foo {
c34b1796 8 fn f(&self) -> isize;
223e47cc
LB
9}
10
11trait Bar : Foo {
c34b1796 12 fn g(&self) -> isize;
223e47cc
LB
13}
14
15struct A {
c34b1796 16 x: isize
223e47cc
LB
17}
18
19impl Foo for A {
c34b1796 20 fn f(&self) -> isize { 10 }
223e47cc
LB
21}
22
23impl Bar for A {
c34b1796 24 fn g(&self) -> isize { 20 }
223e47cc
LB
25}
26
27pub 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}