Debian Codegraph @

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

raw
1 /* { dg-output "3\r*\n3\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 impl Add for i32 {
17 type Output = i32;
18
19 fn add(self, other: i32) -> i32 {
20 let res = self + other;
21
22 unsafe {
23 let a = "%i\n\0";
24 let b = a as *const str;
25 let c = b as *const i8;
26
27 printf(c, res);
28 }
29
30 res
31 }
32 }
33
34 struct Foo(i32);
35 impl Add for Foo {
36 type Output = Foo;
37
38 fn add(self, other: Foo) -> Foo {
39 let res = Foo(self.0 + other.0);
40
41 unsafe {
42 let a = "%i\n\0";
43 let b = a as *const str;
44 let c = b as *const i8;
45
46 printf(c, res.0);
47 }
48
49 res
50 }
51 }
52
53 fn main() -> i32 {
54 let a;
55 a = Foo(1) + Foo(2);
56
57 0
58 }