forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdyn-upcast-trait-mismatch.rs
65 lines (55 loc) · 1020 Bytes
/
dyn-upcast-trait-mismatch.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Validation stops this too early.
//@compile-flags: -Zmiri-disable-validation
trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
#[allow(dead_code)]
fn a(&self) -> i32 {
10
}
#[allow(dead_code)]
fn z(&self) -> i32 {
11
}
#[allow(dead_code)]
fn y(&self) -> i32 {
12
}
}
trait Bar: Foo {
#[allow(dead_code)]
fn b(&self) -> i32 {
20
}
#[allow(dead_code)]
fn w(&self) -> i32 {
21
}
}
trait Baz: Bar {
#[allow(dead_code)]
fn c(&self) -> i32 {
30
}
}
impl Foo for i32 {
fn a(&self) -> i32 {
100
}
}
impl Bar for i32 {
fn b(&self) -> i32 {
200
}
}
impl Baz for i32 {
fn c(&self) -> i32 {
300
}
}
fn main() {
unsafe {
let baz: &dyn Baz = &1;
let baz_fake: *const dyn Bar = std::mem::transmute(baz);
let _err = baz_fake as *const dyn Foo;
//~^ERROR: using vtable for `Baz` but `Bar` was expected
}
}