]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/dyn-upcast-trait-mismatch.rs
:arrow_up: rust-analyzer
[rust.git] / src / tools / miri / tests / fail / dyn-upcast-trait-mismatch.rs
1 #![feature(trait_upcasting)]
2 #![allow(incomplete_features)]
3
4 trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
5     fn a(&self) -> i32 {
6         10
7     }
8
9     fn z(&self) -> i32 {
10         11
11     }
12
13     fn y(&self) -> i32 {
14         12
15     }
16 }
17
18 trait Bar: Foo {
19     fn b(&self) -> i32 {
20         20
21     }
22
23     fn w(&self) -> i32 {
24         21
25     }
26 }
27
28 trait Baz: Bar {
29     fn c(&self) -> i32 {
30         30
31     }
32 }
33
34 impl Foo for i32 {
35     fn a(&self) -> i32 {
36         100
37     }
38 }
39
40 impl Bar for i32 {
41     fn b(&self) -> i32 {
42         200
43     }
44 }
45
46 impl Baz for i32 {
47     fn c(&self) -> i32 {
48         300
49     }
50 }
51
52 fn main() {
53     let baz: &dyn Baz = &1;
54     let baz_fake: &dyn Bar = unsafe { std::mem::transmute(baz) };
55     let _err = baz_fake as &dyn Foo;
56     //~^ERROR: upcast on a pointer whose vtable does not match its type
57 }