]> git.proxmox.com Git - rustc.git/blob - src/test/ui/run-pass/issues/issue-9394-inherited-trait-calls.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / test / ui / run-pass / issues / issue-9394-inherited-trait-calls.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 // run-pass
12
13 trait Base: Base2 + Base3{
14 fn foo(&self) -> String;
15 fn foo1(&self) -> String;
16 fn foo2(&self) -> String{
17 "base foo2".to_string()
18 }
19 }
20
21 trait Base2: Base3{
22 fn baz(&self) -> String;
23 }
24
25 trait Base3{
26 fn root(&self) -> String;
27 }
28
29 trait Super: Base{
30 fn bar(&self) -> String;
31 }
32
33 struct X;
34
35 impl Base for X {
36 fn foo(&self) -> String{
37 "base foo".to_string()
38 }
39 fn foo1(&self) -> String{
40 "base foo1".to_string()
41 }
42
43 }
44
45 impl Base2 for X {
46 fn baz(&self) -> String{
47 "base2 baz".to_string()
48 }
49 }
50
51 impl Base3 for X {
52 fn root(&self) -> String{
53 "base3 root".to_string()
54 }
55 }
56
57 impl Super for X {
58 fn bar(&self) -> String{
59 "super bar".to_string()
60 }
61 }
62
63 pub fn main() {
64 let n = X;
65 let s = &n as &Super;
66 assert_eq!(s.bar(),"super bar".to_string());
67 assert_eq!(s.foo(),"base foo".to_string());
68 assert_eq!(s.foo1(),"base foo1".to_string());
69 assert_eq!(s.foo2(),"base foo2".to_string());
70 assert_eq!(s.baz(),"base2 baz".to_string());
71 assert_eq!(s.root(),"base3 root".to_string());
72 }