]>
Commit | Line | Data |
---|---|---|
94222f64 XL |
1 | // run-pass |
2 | ||
3 | #![feature(trait_upcasting)] | |
4 | #![allow(incomplete_features)] | |
5 | ||
6 | trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync { | |
7 | fn a(&self) -> i32 { | |
8 | 10 | |
9 | } | |
10 | ||
11 | fn z(&self) -> i32 { | |
12 | 11 | |
13 | } | |
14 | ||
15 | fn y(&self) -> i32 { | |
16 | 12 | |
17 | } | |
18 | } | |
19 | ||
20 | trait Bar1: Foo { | |
21 | fn b(&self) -> i32 { | |
22 | 20 | |
23 | } | |
24 | ||
25 | fn w(&self) -> i32 { | |
26 | 21 | |
27 | } | |
28 | } | |
29 | ||
30 | trait Bar2: Foo { | |
31 | fn c(&self) -> i32 { | |
32 | 30 | |
33 | } | |
34 | ||
35 | fn v(&self) -> i32 { | |
36 | 31 | |
37 | } | |
38 | } | |
39 | ||
40 | trait Baz: Bar1 + Bar2 { | |
41 | fn d(&self) -> i32 { | |
42 | 40 | |
43 | } | |
44 | } | |
45 | ||
46 | impl Foo for i32 { | |
47 | fn a(&self) -> i32 { | |
48 | 100 | |
49 | } | |
50 | } | |
51 | ||
52 | impl Bar1 for i32 { | |
53 | fn b(&self) -> i32 { | |
54 | 200 | |
55 | } | |
56 | } | |
57 | ||
58 | impl Bar2 for i32 { | |
59 | fn c(&self) -> i32 { | |
60 | 300 | |
61 | } | |
62 | } | |
63 | ||
64 | impl Baz for i32 { | |
65 | fn d(&self) -> i32 { | |
66 | 400 | |
67 | } | |
68 | } | |
69 | ||
70 | fn main() { | |
71 | let baz: &dyn Baz = &1; | |
72 | let _: &dyn std::fmt::Debug = baz; | |
73 | assert_eq!(*baz, 1); | |
74 | assert_eq!(baz.a(), 100); | |
75 | assert_eq!(baz.b(), 200); | |
76 | assert_eq!(baz.c(), 300); | |
77 | assert_eq!(baz.d(), 400); | |
78 | assert_eq!(baz.z(), 11); | |
79 | assert_eq!(baz.y(), 12); | |
80 | assert_eq!(baz.w(), 21); | |
81 | assert_eq!(baz.v(), 31); | |
82 | ||
83 | let bar1: &dyn Bar1 = baz; | |
84 | let _: &dyn std::fmt::Debug = bar1; | |
85 | assert_eq!(*bar1, 1); | |
86 | assert_eq!(bar1.a(), 100); | |
87 | assert_eq!(bar1.b(), 200); | |
88 | assert_eq!(bar1.z(), 11); | |
89 | assert_eq!(bar1.y(), 12); | |
90 | assert_eq!(bar1.w(), 21); | |
91 | ||
92 | let bar2: &dyn Bar2 = baz; | |
93 | let _: &dyn std::fmt::Debug = bar2; | |
94 | assert_eq!(*bar2, 1); | |
95 | assert_eq!(bar2.a(), 100); | |
96 | assert_eq!(bar2.c(), 300); | |
97 | assert_eq!(bar2.z(), 11); | |
98 | assert_eq!(bar2.y(), 12); | |
99 | assert_eq!(bar2.v(), 31); | |
100 | ||
101 | let foo: &dyn Foo = baz; | |
102 | let _: &dyn std::fmt::Debug = foo; | |
103 | assert_eq!(*foo, 1); | |
104 | assert_eq!(foo.a(), 100); | |
105 | ||
106 | let foo: &dyn Foo = bar1; | |
107 | let _: &dyn std::fmt::Debug = foo; | |
108 | assert_eq!(*foo, 1); | |
109 | assert_eq!(foo.a(), 100); | |
110 | ||
111 | let foo: &dyn Foo = bar2; | |
112 | let _: &dyn std::fmt::Debug = foo; | |
113 | assert_eq!(*foo, 1); | |
114 | assert_eq!(foo.a(), 100); | |
115 | } |