sugar for dynamic allocations via `malloc` and `free`:
```rust,ignore
-#![feature(lang_items, box_syntax, start, libc)]
+#![feature(lang_items, box_syntax, start, libc, core_intrinsics)]
#![no_std]
+use core::intrinsics;
extern crate libc;
-extern {
- fn abort() -> !;
-}
-
#[lang = "owned_box"]
pub struct Box<T>(*mut T);
// Check if `malloc` failed:
if p as usize == 0 {
- abort();
+ intrinsics::abort();
}
p
}
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
-#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { loop {} }
+#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { unsafe { intrinsics::abort() } }
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
in the same format as C:
```rust,ignore
-#![feature(lang_items)]
+#![feature(lang_items, core_intrinsics)]
#![feature(start)]
#![no_std]
+use core::intrinsics;
// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;
pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
_file: &'static str,
_line: u32) -> ! {
- loop {}
+ unsafe { intrinsics::abort() }
}
```
compiler's name mangling too:
```rust,ignore
-#![feature(lang_items)]
+#![feature(lang_items, core_intrinsics)]
#![feature(start)]
#![no_std]
#![no_main]
+use core::intrinsics;
// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;
pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
_file: &'static str,
_line: u32) -> ! {
- loop {}
+ unsafe { intrinsics::abort() }
}
```