about summary refs log tree commit diff
path: root/tests/ui/traits/vtable/empty-supertrait-with-nonempty-supersupertrait.rs
blob: 507cda63868cd35edceb7265c04e322c5cbeaf1d (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
//@ revisions: run dump
//@[run] run-pass
//@[dump] check-fail
//! Regression test for #145752
//! Ensure that `OneTwo` contains a vptr for `TwoAgain`
#![allow(unused)]
#![cfg_attr(dump, feature(rustc_attrs))]

trait One {
    fn one(&self) {
        panic!("don't call this");
    }
}
impl One for () {}

trait Two {
    fn two(&self) {
        println!("good");
    }
}
impl Two for () {}

trait TwoAgain: Two {}
impl<T: Two> TwoAgain for T {}

trait OneTwo: One + TwoAgain {}
impl<T: One + Two> OneTwo for T {}

fn main() {
    (&()).two();
    (&() as &dyn OneTwo).two();
    (&() as &dyn OneTwo as &dyn Two).two();

    // these two used to panic because they called `one` due to #145752
    (&() as &dyn OneTwo as &dyn TwoAgain).two();
    (&() as &dyn OneTwo as &dyn TwoAgain as &dyn Two).two();
}

#[cfg_attr(dump, rustc_dump_vtable)]
type T = dyn OneTwo;
//[dump]~^ ERROR vtable entries: [
//[dump]~| ERROR            MetadataDropInPlace,
//[dump]~| ERROR            MetadataSize,
//[dump]~| ERROR            MetadataAlign,
//[dump]~| ERROR            Method(<dyn OneTwo as One>::one - shim(reify)),
//[dump]~| ERROR            Method(<dyn OneTwo as Two>::two - shim(reify)),
//[dump]~| ERROR            TraitVPtr(<dyn OneTwo as Two>),
//[dump]~| ERROR            TraitVPtr(<dyn OneTwo as TwoAgain>),
//[dump]~| ERROR        ]