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