aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/execute/torture/trait13.rs
blob: 928a37c5d73171639ab0da29980fed9e76c28dda (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
/* { dg-output "123\r*\n456\r*\n" } */
extern "C" {
    fn printf(s: *const i8, ...);
}

#[lang = "sized"]
pub trait Sized {}

struct Foo(i32);
trait Bar {
    fn baz(&self);

    fn qux(&self) {
        // { dg-warning "unused name" "" { target *-*-* } .-1 }
        unsafe {
            let a = "%i\n\0";
            let b = a as *const str;
            let c = b as *const i8;

            printf(c, 456);
        }
    }
}

impl Bar for Foo {
    fn baz(&self) {
        unsafe {
            let a = "%i\n\0";
            let b = a as *const str;
            let c = b as *const i8;

            printf(c, self.0);
        }
    }
}

fn dynamic_dispatch(t: &dyn Bar) {
    t.baz();
    t.qux();
}

fn main() -> i32 {
    let a;
    a = Foo(123);

    let b: &dyn Bar;
    b = &a;
    dynamic_dispatch(b);

    0
}