]> git.lizzy.rs Git - rust.git/blob - tests/ui/traits/trait-upcasting/basic.rs
Auto merge of #101138 - Rejyr:diagnostic-migration-rustc-lint-pt2, r=davidtwco
[rust.git] / tests / ui / traits / trait-upcasting / basic.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 Bar: Foo {
20     fn b(&self) -> i32 {
21         20
22     }
23
24     fn w(&self) -> i32 {
25         21
26     }
27 }
28
29 trait Baz: Bar {
30     fn c(&self) -> i32 {
31         30
32     }
33 }
34
35 impl Foo for i32 {
36     fn a(&self) -> i32 {
37         100
38     }
39 }
40
41 impl Bar for i32 {
42     fn b(&self) -> i32 {
43         200
44     }
45 }
46
47 impl Baz for i32 {
48     fn c(&self) -> i32 {
49         300
50     }
51 }
52
53 fn main() {
54     let baz: &dyn Baz = &1;
55     let _: &dyn std::fmt::Debug = baz;
56     assert_eq!(*baz, 1);
57     assert_eq!(baz.a(), 100);
58     assert_eq!(baz.b(), 200);
59     assert_eq!(baz.c(), 300);
60     assert_eq!(baz.z(), 11);
61     assert_eq!(baz.y(), 12);
62     assert_eq!(baz.w(), 21);
63
64     let bar: &dyn Bar = baz;
65     let _: &dyn std::fmt::Debug = bar;
66     assert_eq!(*bar, 1);
67     assert_eq!(bar.a(), 100);
68     assert_eq!(bar.b(), 200);
69     assert_eq!(bar.z(), 11);
70     assert_eq!(bar.y(), 12);
71     assert_eq!(bar.w(), 21);
72
73     let foo: &dyn Foo = baz;
74     let _: &dyn std::fmt::Debug = foo;
75     assert_eq!(*foo, 1);
76     assert_eq!(foo.a(), 100);
77     assert_eq!(foo.z(), 11);
78     assert_eq!(foo.y(), 12);
79
80     let foo: &dyn Foo = bar;
81     let _: &dyn std::fmt::Debug = foo;
82     assert_eq!(*foo, 1);
83     assert_eq!(foo.a(), 100);
84     assert_eq!(foo.z(), 11);
85     assert_eq!(foo.y(), 12);
86 }