1 // run-pass
2 
3 #![feature(trait_upcasting)]
4 #![allow(incomplete_features)]
5 
6 trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
a(&self) -> i327     fn a(&self) -> i32 {
8         10
9     }
10 
z(&self) -> i3211     fn z(&self) -> i32 {
12         11
13     }
14 
y(&self) -> i3215     fn y(&self) -> i32 {
16         12
17     }
18 }
19 
20 trait Bar1: Foo {
b(&self) -> i3221     fn b(&self) -> i32 {
22         20
23     }
24 
w(&self) -> i3225     fn w(&self) -> i32 {
26         21
27     }
28 }
29 
30 trait Bar2: Foo {
c(&self) -> i3231     fn c(&self) -> i32 {
32         30
33     }
34 
v(&self) -> i3235     fn v(&self) -> i32 {
36         31
37     }
38 }
39 
40 trait Baz: Bar1 + Bar2 {
d(&self) -> i3241     fn d(&self) -> i32 {
42         40
43     }
44 }
45 
46 impl Foo for i32 {
a(&self) -> i3247     fn a(&self) -> i32 {
48         100
49     }
50 }
51 
52 impl Bar1 for i32 {
b(&self) -> i3253     fn b(&self) -> i32 {
54         200
55     }
56 }
57 
58 impl Bar2 for i32 {
c(&self) -> i3259     fn c(&self) -> i32 {
60         300
61     }
62 }
63 
64 impl Baz for i32 {
d(&self) -> i3265     fn d(&self) -> i32 {
66         400
67     }
68 }
69 
main()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 }
116