aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/execute/torture/impl_trait3.rs
blob: c1cec07bc4cfdd3aae14c720566b8f2b993e6add (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
/* { dg-output "Hello from Message\r*\n" } */
#[lang = "sized"]
pub trait Sized {}

extern "C" {
    fn printf(s: *const i8, ...);
}

trait Speak {
    fn speak(&self) -> &'static str;
}

trait Printer {
    fn print(&self, input: impl Speak);
}

struct Console;

impl Printer for Console {
    fn print(&self, input: impl Speak) {
        unsafe {
            let a = input.speak();
            let b = a as *const str;
            let c = b as *const i8;

            printf(c);
        }
    }
}

struct Message(&'static str);

impl Speak for Message {
    fn speak(&self) -> &'static str {
        self.0
    }
}

fn main() -> i32 {
    let c = Console;
    let msg = Message("Hello from Message\n");
    c.print(msg);

    0
}