Debian Codegraph @

gcc/testsuite/rust/execute/torture/operator_overload_2.rs

raw
1 /* { dg-output "3\r*\n" } */
2 extern "C" {
3 fn printf(s: *const i8, ...);
4 }
5
6 #[lang = "sized"]
7 pub trait Sized {}
8
9 #[lang = "add"]
10 pub trait Add<Rhs = Self> {
11 type Output;
12
13 fn add(self, rhs: Rhs) -> Self::Output;
14 }
15
16 struct Foo(i32);
17
18 impl Add for Foo {
19 type Output = Foo;
20
21 fn add(self, other: Foo) -> Foo {
22 let res = Foo(self.0 + other.0);
23
24 unsafe {
25 let a = "%i\n\0";
26 let b = a as *const str;
27 let c = b as *const i8;
28
29 printf(c, res.0);
30 }
31
32 res
33 }
34 }
35
36 fn main() -> i32 {
37 let a;
38 a = Foo(1) + Foo(2);
39
40 0
41 }