]> git.lizzy.rs Git - rust.git/blob - tests/ui/traits/trait-upcasting/invalid-upcast.rs
Rollup merge of #103702 - WaffleLapkin:lift-sized-bounds-from-pointer-methods-where...
[rust.git] / tests / ui / traits / trait-upcasting / invalid-upcast.rs
1 #![feature(trait_upcasting)]
2
3 trait Foo {
4     fn a(&self) -> i32 {
5         10
6     }
7
8     fn z(&self) -> i32 {
9         11
10     }
11
12     fn y(&self) -> i32 {
13         12
14     }
15 }
16
17 trait Bar {
18     fn b(&self) -> i32 {
19         20
20     }
21
22     fn w(&self) -> i32 {
23         21
24     }
25 }
26
27 trait Baz {
28     fn c(&self) -> i32 {
29         30
30     }
31 }
32
33 impl Foo for i32 {
34     fn a(&self) -> i32 {
35         100
36     }
37 }
38
39 impl Bar for i32 {
40     fn b(&self) -> i32 {
41         200
42     }
43 }
44
45 impl Baz for i32 {
46     fn c(&self) -> i32 {
47         300
48     }
49 }
50
51 fn main() {
52     let baz: &dyn Baz = &1;
53     let _: &dyn std::fmt::Debug = baz;
54     //~^ ERROR mismatched types [E0308]
55     let _: &dyn Send = baz;
56     //~^ ERROR mismatched types [E0308]
57     let _: &dyn Sync = baz;
58     //~^ ERROR mismatched types [E0308]
59
60     let bar: &dyn Bar = baz;
61     //~^ ERROR mismatched types [E0308]
62     let _: &dyn std::fmt::Debug = bar;
63     //~^ ERROR mismatched types [E0308]
64     let _: &dyn Send = bar;
65     //~^ ERROR mismatched types [E0308]
66     let _: &dyn Sync = bar;
67     //~^ ERROR mismatched types [E0308]
68
69     let foo: &dyn Foo = baz;
70     //~^ ERROR mismatched types [E0308]
71     let _: &dyn std::fmt::Debug = foo;
72     //~^ ERROR mismatched types [E0308]
73     let _: &dyn Send = foo;
74     //~^ ERROR mismatched types [E0308]
75     let _: &dyn Sync = foo;
76     //~^ ERROR mismatched types [E0308]
77
78     let foo: &dyn Foo = bar;
79     //~^ ERROR mismatched types [E0308]
80     let _: &dyn std::fmt::Debug = foo;
81     //~^ ERROR mismatched types [E0308]
82     let _: &dyn Send = foo;
83     //~^ ERROR mismatched types [E0308]
84     let _: &dyn Sync = foo;
85     //~^ ERROR mismatched types [E0308]
86 }