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

#[lang = "add"]
pub trait Add<Rhs = Self> {
    type Output;

    fn add(self, rhs: Rhs) -> Self::Output;
}

struct Foo(i32);

impl Add for Foo {
    type Output = Foo;

    fn add(self, other: Foo) -> Foo {
        let res = Foo(self.0 + other.0);

        unsafe {
            let a = "%i\n\0";
            let b = a as *const str;
            let c = b as *const i8;

            printf(c, res.0);
        }

        res
    }
}

fn main() -> i32 {
    let a;
    a = Foo(1) + Foo(2);

    0
}