]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_codegen_cranelift/example/alloc_example.rs
New upstream version 1.51.0+dfsg1
[rustc.git] / compiler / rustc_codegen_cranelift / example / alloc_example.rs
1 #![feature(start, box_syntax, alloc_system, core_intrinsics, alloc_prelude, alloc_error_handler)]
2 #![no_std]
3
4 extern crate alloc;
5 extern crate alloc_system;
6
7 use alloc::prelude::v1::*;
8
9 use alloc_system::System;
10
11 #[global_allocator]
12 static ALLOC: System = System;
13
14 #[cfg_attr(unix, link(name = "c"))]
15 #[cfg_attr(target_env = "msvc", link(name = "msvcrt"))]
16 extern "C" {
17 fn puts(s: *const u8) -> i32;
18 }
19
20 #[panic_handler]
21 fn panic_handler(_: &core::panic::PanicInfo) -> ! {
22 core::intrinsics::abort();
23 }
24
25 #[alloc_error_handler]
26 fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
27 core::intrinsics::abort();
28 }
29
30 #[start]
31 fn main(_argc: isize, _argv: *const *const u8) -> isize {
32 let world: Box<&str> = box "Hello World!\0";
33 unsafe {
34 puts(*world as *const str as *const u8);
35 }
36
37 0
38 }