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