about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/dyn-upcast-trait-mismatch.rs
blob: 1d6b6777032de64756f045b054c0cdf685d24912 (plain)
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
66
// Validation stops this too early.
//@compile-flags: -Zmiri-disable-validation

#![feature(trait_upcasting)]
#![allow(incomplete_features)]

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() {
    let baz: &dyn Baz = &1;
    let baz_fake: *const dyn Bar = unsafe { std::mem::transmute(baz) };
    let _err = baz_fake as *const dyn Foo;
    //~^ERROR: using vtable for trait `Baz` but trait `Bar` was expected
}