summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/trait-upcasting/replace-vptr.rs
blob: 9ccfc9306ac0c46e04097ebd9a0ba9ad334cba07 (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
// run-pass

#![feature(trait_upcasting)]

trait A {
    fn foo_a(&self);
}

trait B {
    fn foo_b(&self);
}

trait C: A + B {
    fn foo_c(&self);
}

struct S(i32);

impl A for S {
    fn foo_a(&self) {
        unreachable!();
    }
}

impl B for S {
    fn foo_b(&self) {
        assert_eq!(42, self.0);
    }
}

impl C for S {
    fn foo_c(&self) {
        unreachable!();
    }
}

fn invoke_inner(b: &dyn B) {
    b.foo_b();
}

fn invoke_outer(c: &dyn C) {
    invoke_inner(c);
}

fn main() {
    let s = S(42);
    invoke_outer(&s);
}