]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_gcc/tests/run/operations.rs
Auto merge of #95326 - lupd:std-iter-doc, r=Dylan-DPC
[rust.git] / compiler / rustc_codegen_gcc / tests / run / operations.rs
1 // Compiler:
2 //
3 // Run-time:
4 //   stdout: 41
5 //     39
6 //     10
7
8 #![allow(unused_attributes)]
9 #![feature(auto_traits, lang_items, no_core, start, intrinsics, arbitrary_self_types)]
10
11 #![no_std]
12 #![no_core]
13
14 /*
15  * Core
16  */
17
18 // Because we don't have core yet.
19 #[lang = "sized"]
20 pub trait Sized {}
21
22 #[lang = "copy"]
23 trait Copy {
24 }
25
26 impl Copy for isize {}
27 impl Copy for *mut i32 {}
28 impl Copy for usize {}
29 impl Copy for u8 {}
30 impl Copy for i8 {}
31 impl Copy for i16 {}
32 impl Copy for i32 {}
33
34 #[lang = "deref"]
35 pub trait Deref {
36     type Target: ?Sized;
37
38     fn deref(&self) -> &Self::Target;
39 }
40
41 #[lang = "receiver"]
42 trait Receiver {
43 }
44
45 #[lang = "freeze"]
46 pub(crate) unsafe auto trait Freeze {}
47
48 #[lang = "panic_location"]
49 struct PanicLocation {
50     file: &'static str,
51     line: u32,
52     column: u32,
53 }
54
55 mod libc {
56     #[link(name = "c")]
57     extern "C" {
58         pub fn printf(format: *const i8, ...) -> i32;
59         pub fn puts(s: *const u8) -> i32;
60         pub fn fflush(stream: *mut i32) -> i32;
61
62         pub static STDOUT: *mut i32;
63     }
64 }
65
66 mod intrinsics {
67     extern "rust-intrinsic" {
68         pub fn abort() -> !;
69     }
70 }
71
72 #[lang = "panic"]
73 #[track_caller]
74 #[no_mangle]
75 pub fn panic(_msg: &str) -> ! {
76     unsafe {
77         libc::puts("Panicking\0" as *const str as *const u8);
78         libc::fflush(libc::STDOUT);
79         intrinsics::abort();
80     }
81 }
82
83 #[lang = "add"]
84 trait Add<RHS = Self> {
85     type Output;
86
87     fn add(self, rhs: RHS) -> Self::Output;
88 }
89
90 impl Add for u8 {
91     type Output = Self;
92
93     fn add(self, rhs: Self) -> Self {
94         self + rhs
95     }
96 }
97
98 impl Add for i8 {
99     type Output = Self;
100
101     fn add(self, rhs: Self) -> Self {
102         self + rhs
103     }
104 }
105
106 impl Add for i32 {
107     type Output = Self;
108
109     fn add(self, rhs: Self) -> Self {
110         self + rhs
111     }
112 }
113
114 impl Add for usize {
115     type Output = Self;
116
117     fn add(self, rhs: Self) -> Self {
118         self + rhs
119     }
120 }
121
122 impl Add for isize {
123     type Output = Self;
124
125     fn add(self, rhs: Self) -> Self {
126         self + rhs
127     }
128 }
129
130 #[lang = "sub"]
131 pub trait Sub<RHS = Self> {
132     type Output;
133
134     fn sub(self, rhs: RHS) -> Self::Output;
135 }
136
137 impl Sub for usize {
138     type Output = Self;
139
140     fn sub(self, rhs: Self) -> Self {
141         self - rhs
142     }
143 }
144
145 impl Sub for isize {
146     type Output = Self;
147
148     fn sub(self, rhs: Self) -> Self {
149         self - rhs
150     }
151 }
152
153 impl Sub for u8 {
154     type Output = Self;
155
156     fn sub(self, rhs: Self) -> Self {
157         self - rhs
158     }
159 }
160
161 impl Sub for i8 {
162     type Output = Self;
163
164     fn sub(self, rhs: Self) -> Self {
165         self - rhs
166     }
167 }
168
169 impl Sub for i16 {
170     type Output = Self;
171
172     fn sub(self, rhs: Self) -> Self {
173         self - rhs
174     }
175 }
176
177 #[lang = "mul"]
178 pub trait Mul<RHS = Self> {
179     type Output;
180
181     #[must_use]
182     fn mul(self, rhs: RHS) -> Self::Output;
183 }
184
185 impl Mul for u8 {
186     type Output = Self;
187
188     fn mul(self, rhs: Self) -> Self::Output {
189         self * rhs
190     }
191 }
192
193 impl Mul for usize {
194     type Output = Self;
195
196     fn mul(self, rhs: Self) -> Self::Output {
197         self * rhs
198     }
199 }
200
201 impl Mul for isize {
202     type Output = Self;
203
204     fn mul(self, rhs: Self) -> Self::Output {
205         self * rhs
206     }
207 }
208
209 /*
210  * Code
211  */
212
213 #[start]
214 fn main(mut argc: isize, _argv: *const *const u8) -> isize {
215     unsafe {
216         libc::printf(b"%ld\n\0" as *const u8 as *const i8, 40 + argc);
217         libc::printf(b"%ld\n\0" as *const u8 as *const i8, 40 - argc);
218         libc::printf(b"%ld\n\0" as *const u8 as *const i8, 10 * argc);
219     }
220     0
221 }