]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_cranelift/example/mini_core.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / compiler / rustc_codegen_cranelift / example / mini_core.rs
CommitLineData
29967ef6
XL
1#![feature(
2 no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
fc512014 3 untagged_unions, decl_macro, rustc_attrs, transparent_unions, auto_traits,
29967ef6
XL
4 thread_local,
5)]
6#![no_core]
7#![allow(dead_code)]
8
9#[lang = "sized"]
10pub trait Sized {}
11
12#[lang = "unsize"]
13pub trait Unsize<T: ?Sized> {}
14
15#[lang = "coerce_unsized"]
16pub trait CoerceUnsized<T> {}
17
18impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
19impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
20impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
21impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
22
23#[lang = "dispatch_from_dyn"]
24pub trait DispatchFromDyn<T> {}
25
26// &T -> &U
27impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
28// &mut T -> &mut U
29impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
30// *const T -> *const U
31impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
32// *mut T -> *mut U
33impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
34impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}
35
36#[lang = "receiver"]
37pub trait Receiver {}
38
39impl<T: ?Sized> Receiver for &T {}
40impl<T: ?Sized> Receiver for &mut T {}
41impl<T: ?Sized> Receiver for Box<T> {}
42
43#[lang = "copy"]
44pub unsafe trait Copy {}
45
46unsafe impl Copy for bool {}
47unsafe impl Copy for u8 {}
48unsafe impl Copy for u16 {}
49unsafe impl Copy for u32 {}
50unsafe impl Copy for u64 {}
51unsafe impl Copy for u128 {}
52unsafe impl Copy for usize {}
53unsafe impl Copy for i8 {}
54unsafe impl Copy for i16 {}
55unsafe impl Copy for i32 {}
56unsafe impl Copy for isize {}
57unsafe impl Copy for f32 {}
58unsafe impl Copy for char {}
59unsafe impl<'a, T: ?Sized> Copy for &'a T {}
60unsafe impl<T: ?Sized> Copy for *const T {}
61unsafe impl<T: ?Sized> Copy for *mut T {}
62unsafe impl<T: Copy> Copy for Option<T> {}
63
64#[lang = "sync"]
65pub unsafe trait Sync {}
66
67unsafe impl Sync for bool {}
68unsafe impl Sync for u8 {}
69unsafe impl Sync for u16 {}
70unsafe impl Sync for u32 {}
71unsafe impl Sync for u64 {}
72unsafe impl Sync for usize {}
73unsafe impl Sync for i8 {}
74unsafe impl Sync for i16 {}
75unsafe impl Sync for i32 {}
76unsafe impl Sync for isize {}
77unsafe impl Sync for char {}
78unsafe impl<'a, T: ?Sized> Sync for &'a T {}
79unsafe impl Sync for [u8; 16] {}
80
81#[lang = "freeze"]
82unsafe auto trait Freeze {}
83
84unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
85unsafe impl<T: ?Sized> Freeze for *const T {}
86unsafe impl<T: ?Sized> Freeze for *mut T {}
87unsafe impl<T: ?Sized> Freeze for &T {}
88unsafe impl<T: ?Sized> Freeze for &mut T {}
89
90#[lang = "structural_peq"]
91pub trait StructuralPartialEq {}
92
93#[lang = "structural_teq"]
94pub trait StructuralEq {}
95
96#[lang = "not"]
97pub trait Not {
98 type Output;
99
100 fn not(self) -> Self::Output;
101}
102
103impl Not for bool {
104 type Output = bool;
105
106 fn not(self) -> bool {
107 !self
108 }
109}
110
111#[lang = "mul"]
112pub trait Mul<RHS = Self> {
113 type Output;
114
115 #[must_use]
116 fn mul(self, rhs: RHS) -> Self::Output;
117}
118
119impl Mul for u8 {
120 type Output = Self;
121
122 fn mul(self, rhs: Self) -> Self::Output {
123 self * rhs
124 }
125}
126
127impl Mul for usize {
128 type Output = Self;
129
130 fn mul(self, rhs: Self) -> Self::Output {
131 self * rhs
132 }
133}
134
135#[lang = "add"]
136pub trait Add<RHS = Self> {
137 type Output;
138
139 fn add(self, rhs: RHS) -> Self::Output;
140}
141
142impl Add for u8 {
143 type Output = Self;
144
145 fn add(self, rhs: Self) -> Self {
146 self + rhs
147 }
148}
149
150impl Add for i8 {
151 type Output = Self;
152
153 fn add(self, rhs: Self) -> Self {
154 self + rhs
155 }
156}
157
158impl Add for usize {
159 type Output = Self;
160
161 fn add(self, rhs: Self) -> Self {
162 self + rhs
163 }
164}
165
166#[lang = "sub"]
167pub trait Sub<RHS = Self> {
168 type Output;
169
170 fn sub(self, rhs: RHS) -> Self::Output;
171}
172
173impl Sub for usize {
174 type Output = Self;
175
176 fn sub(self, rhs: Self) -> Self {
177 self - rhs
178 }
179}
180
181impl Sub for u8 {
182 type Output = Self;
183
184 fn sub(self, rhs: Self) -> Self {
185 self - rhs
186 }
187}
188
189impl Sub for i8 {
190 type Output = Self;
191
192 fn sub(self, rhs: Self) -> Self {
193 self - rhs
194 }
195}
196
197impl Sub for i16 {
198 type Output = Self;
199
200 fn sub(self, rhs: Self) -> Self {
201 self - rhs
202 }
203}
204
205#[lang = "rem"]
206pub trait Rem<RHS = Self> {
207 type Output;
208
209 fn rem(self, rhs: RHS) -> Self::Output;
210}
211
212impl Rem for usize {
213 type Output = Self;
214
215 fn rem(self, rhs: Self) -> Self {
216 self % rhs
217 }
218}
219
220#[lang = "bitor"]
221pub trait BitOr<RHS = Self> {
222 type Output;
223
224 #[must_use]
225 fn bitor(self, rhs: RHS) -> Self::Output;
226}
227
228impl BitOr for bool {
229 type Output = bool;
230
231 fn bitor(self, rhs: bool) -> bool {
232 self | rhs
233 }
234}
235
236impl<'a> BitOr<bool> for &'a bool {
237 type Output = bool;
238
239 fn bitor(self, rhs: bool) -> bool {
240 *self | rhs
241 }
242}
243
244#[lang = "eq"]
245pub trait PartialEq<Rhs: ?Sized = Self> {
246 fn eq(&self, other: &Rhs) -> bool;
247 fn ne(&self, other: &Rhs) -> bool;
248}
249
250impl PartialEq for u8 {
251 fn eq(&self, other: &u8) -> bool {
252 (*self) == (*other)
253 }
254 fn ne(&self, other: &u8) -> bool {
255 (*self) != (*other)
256 }
257}
258
259impl PartialEq for u16 {
260 fn eq(&self, other: &u16) -> bool {
261 (*self) == (*other)
262 }
263 fn ne(&self, other: &u16) -> bool {
264 (*self) != (*other)
265 }
266}
267
268impl PartialEq for u32 {
269 fn eq(&self, other: &u32) -> bool {
270 (*self) == (*other)
271 }
272 fn ne(&self, other: &u32) -> bool {
273 (*self) != (*other)
274 }
275}
276
277
278impl PartialEq for u64 {
279 fn eq(&self, other: &u64) -> bool {
280 (*self) == (*other)
281 }
282 fn ne(&self, other: &u64) -> bool {
283 (*self) != (*other)
284 }
285}
286
287impl PartialEq for u128 {
288 fn eq(&self, other: &u128) -> bool {
289 (*self) == (*other)
290 }
291 fn ne(&self, other: &u128) -> bool {
292 (*self) != (*other)
293 }
294}
295
296impl PartialEq for usize {
297 fn eq(&self, other: &usize) -> bool {
298 (*self) == (*other)
299 }
300 fn ne(&self, other: &usize) -> bool {
301 (*self) != (*other)
302 }
303}
304
305impl PartialEq for i8 {
306 fn eq(&self, other: &i8) -> bool {
307 (*self) == (*other)
308 }
309 fn ne(&self, other: &i8) -> bool {
310 (*self) != (*other)
311 }
312}
313
314impl PartialEq for i32 {
315 fn eq(&self, other: &i32) -> bool {
316 (*self) == (*other)
317 }
318 fn ne(&self, other: &i32) -> bool {
319 (*self) != (*other)
320 }
321}
322
323impl PartialEq for isize {
324 fn eq(&self, other: &isize) -> bool {
325 (*self) == (*other)
326 }
327 fn ne(&self, other: &isize) -> bool {
328 (*self) != (*other)
329 }
330}
331
332impl PartialEq for char {
333 fn eq(&self, other: &char) -> bool {
334 (*self) == (*other)
335 }
336 fn ne(&self, other: &char) -> bool {
337 (*self) != (*other)
338 }
339}
340
341impl<T: ?Sized> PartialEq for *const T {
342 fn eq(&self, other: &*const T) -> bool {
343 *self == *other
344 }
345 fn ne(&self, other: &*const T) -> bool {
346 *self != *other
347 }
348}
349
350impl <T: PartialEq> PartialEq for Option<T> {
351 fn eq(&self, other: &Self) -> bool {
352 match (self, other) {
353 (Some(lhs), Some(rhs)) => *lhs == *rhs,
354 (None, None) => true,
355 _ => false,
356 }
357 }
358
359 fn ne(&self, other: &Self) -> bool {
360 match (self, other) {
361 (Some(lhs), Some(rhs)) => *lhs != *rhs,
362 (None, None) => false,
363 _ => true,
364 }
365 }
366}
367
368#[lang = "neg"]
369pub trait Neg {
370 type Output;
371
372 fn neg(self) -> Self::Output;
373}
374
375impl Neg for i8 {
376 type Output = i8;
377
378 fn neg(self) -> i8 {
379 -self
380 }
381}
382
383impl Neg for i16 {
384 type Output = i16;
385
386 fn neg(self) -> i16 {
387 self
388 }
389}
390
391impl Neg for isize {
392 type Output = isize;
393
394 fn neg(self) -> isize {
395 -self
396 }
397}
398
399impl Neg for f32 {
400 type Output = f32;
401
402 fn neg(self) -> f32 {
403 -self
404 }
405}
406
407pub enum Option<T> {
408 Some(T),
409 None,
410}
411
412pub use Option::*;
413
414#[lang = "phantom_data"]
415pub struct PhantomData<T: ?Sized>;
416
417#[lang = "fn_once"]
418#[rustc_paren_sugar]
419pub trait FnOnce<Args> {
420 #[lang = "fn_once_output"]
421 type Output;
422
423 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
424}
425
426#[lang = "fn_mut"]
427#[rustc_paren_sugar]
428pub trait FnMut<Args>: FnOnce<Args> {
429 extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
430}
431
432#[lang = "panic"]
433#[track_caller]
434pub fn panic(_msg: &str) -> ! {
435 unsafe {
436 libc::puts("Panicking\n\0" as *const str as *const i8);
437 intrinsics::abort();
438 }
439}
440
441#[lang = "panic_bounds_check"]
442#[track_caller]
443fn panic_bounds_check(index: usize, len: usize) -> ! {
444 unsafe {
445 libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index);
446 intrinsics::abort();
447 }
448}
449
450#[lang = "eh_personality"]
451fn eh_personality() -> ! {
452 loop {}
453}
454
455#[lang = "drop_in_place"]
456#[allow(unconditional_recursion)]
457pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
458 // Code here does not matter - this is replaced by the
459 // real drop glue by the compiler.
460 drop_in_place(to_drop);
461}
462
463#[lang = "deref"]
464pub trait Deref {
465 type Target: ?Sized;
466
467 fn deref(&self) -> &Self::Target;
468}
469
470#[lang = "owned_box"]
471pub struct Box<T: ?Sized>(*mut T);
472
473impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
474
475impl<T: ?Sized> Drop for Box<T> {
476 fn drop(&mut self) {
477 // drop is currently performed by compiler.
478 }
479}
480
481impl<T> Deref for Box<T> {
482 type Target = T;
483
484 fn deref(&self) -> &Self::Target {
485 &**self
486 }
487}
488
489#[lang = "exchange_malloc"]
490unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
491 libc::malloc(size)
492}
493
494#[lang = "box_free"]
495unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
496 libc::free(ptr as *mut u8);
497}
498
499#[lang = "drop"]
500pub trait Drop {
501 fn drop(&mut self);
502}
503
504#[lang = "manually_drop"]
505#[repr(transparent)]
506pub struct ManuallyDrop<T: ?Sized> {
507 pub value: T,
508}
509
510#[lang = "maybe_uninit"]
511#[repr(transparent)]
512pub union MaybeUninit<T> {
513 pub uninit: (),
514 pub value: ManuallyDrop<T>,
515}
516
517pub mod intrinsics {
518 extern "rust-intrinsic" {
519 pub fn abort() -> !;
520 pub fn size_of<T>() -> usize;
521 pub fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
522 pub fn min_align_of<T>() -> usize;
523 pub fn min_align_of_val<T: ?::Sized>(val: *const T) -> usize;
524 pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
525 pub fn transmute<T, U>(e: T) -> U;
526 pub fn ctlz_nonzero<T>(x: T) -> T;
527 pub fn needs_drop<T>() -> bool;
528 pub fn bitreverse<T>(x: T) -> T;
529 pub fn bswap<T>(x: T) -> T;
530 pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
531 }
532}
533
534pub mod libc {
535 #[cfg_attr(not(windows), link(name = "c"))]
536 #[cfg_attr(windows, link(name = "msvcrt"))]
537 extern "C" {
538 pub fn puts(s: *const i8) -> i32;
539 pub fn printf(format: *const i8, ...) -> i32;
540 pub fn malloc(size: usize) -> *mut u8;
541 pub fn free(ptr: *mut u8);
542 pub fn memcpy(dst: *mut u8, src: *const u8, size: usize);
543 pub fn memmove(dst: *mut u8, src: *const u8, size: usize);
544 pub fn strncpy(dst: *mut u8, src: *const u8, size: usize);
545 }
546}
547
548#[lang = "index"]
549pub trait Index<Idx: ?Sized> {
550 type Output: ?Sized;
551 fn index(&self, index: Idx) -> &Self::Output;
552}
553
554impl<T> Index<usize> for [T; 3] {
555 type Output = T;
556
557 fn index(&self, index: usize) -> &Self::Output {
558 &self[index]
559 }
560}
561
562impl<T> Index<usize> for [T] {
563 type Output = T;
564
565 fn index(&self, index: usize) -> &Self::Output {
566 &self[index]
567 }
568}
569
570extern {
571 type VaListImpl;
572}
573
574#[lang = "va_list"]
575#[repr(transparent)]
576pub struct VaList<'a>(&'a mut VaListImpl);
577
578#[rustc_builtin_macro]
579#[rustc_macro_transparency = "semitransparent"]
580pub macro stringify($($t:tt)*) { /* compiler built-in */ }
581
582#[rustc_builtin_macro]
583#[rustc_macro_transparency = "semitransparent"]
584pub macro file() { /* compiler built-in */ }
585
586#[rustc_builtin_macro]
587#[rustc_macro_transparency = "semitransparent"]
588pub macro line() { /* compiler built-in */ }
589
590#[rustc_builtin_macro]
591#[rustc_macro_transparency = "semitransparent"]
592pub macro cfg() { /* compiler built-in */ }
593
594#[rustc_builtin_macro]
595#[rustc_macro_transparency = "semitransparent"]
596pub macro global_asm() { /* compiler built-in */ }
597
598pub static A_STATIC: u8 = 42;
599
600#[lang = "panic_location"]
601struct PanicLocation {
602 file: &'static str,
603 line: u32,
604 column: u32,
605}
606
607#[no_mangle]
608pub fn get_tls() -> u8 {
609 #[thread_local]
610 static A: u8 = 42;
611
612 A
613}