Skip to content

Commit 4102b6c

Browse files
committed
Fixes example and readme
1 parent 8c6dbcd commit 4102b6c

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ infrastructure. Nevertheless, `wee_alloc` is also usable with `std`.
5050
// We aren't using the standard library.
5151
#![no_std]
5252

53-
// Required to replace the global allocator.
54-
#![feature(global_allocator)]
55-
5653
// Required to use the `alloc` crate and its types, the `abort` intrinsic, and a
5754
// custom panic handler.
58-
#![feature(alloc, core_intrinsics, lang_items)]
55+
#![feature(alloc, core_intrinsics, panic_implementation, lang_items)]
5956

6057
extern crate alloc;
6158
extern crate wee_alloc;
@@ -64,18 +61,22 @@ extern crate wee_alloc;
6461
#[global_allocator]
6562
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
6663

67-
// Need to provide a tiny `panic_fmt` lang-item implementation for `#![no_std]`.
68-
// This implementation will translate panics into traps in the resulting
69-
// WebAssembly.
70-
#[lang = "panic_fmt"]
71-
extern "C" fn panic_fmt(
72-
_args: ::core::fmt::Arguments,
73-
_file: &'static str,
74-
_line: u32
75-
) -> ! {
76-
use core::intrinsics;
64+
// Need to provide a tiny `panic` implementation for `#![no_std]`.
65+
// This translates into an `unreachable` instruction that will
66+
// raise a `trap` the WebAssembly execution if we panic at runtime.
67+
#[panic_implementation]
68+
fn panic(_info: &::core::panic::PanicInfo) -> ! {
69+
unsafe {
70+
::core::intrinsics::abort();
71+
}
72+
}
73+
74+
// Need to provide a tiny `oom` lang-item implementation for
75+
// `#![no_std]`.
76+
#[lang = "oom"]
77+
extern "C" fn oom() -> ! {
7778
unsafe {
78-
intrinsics::abort();
79+
::core::intrinsics::abort();
7980
}
8081
}
8182

example/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
2020
// raise a `trap` the WebAssembly execution if we panic at runtime.
2121
#[panic_implementation]
2222
fn panic(_info: &::core::panic::PanicInfo) -> ! {
23-
unsafe { ::core::intrinsics::abort() }
23+
unsafe {
24+
::core::intrinsics::abort();
25+
}
2426
}
2527

2628
// Need to provide a tiny `oom` lang-item implementation for

test/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(alloc, allocator_api)]
22

3-
extern crate alloc;
43
extern crate histo;
54
#[macro_use]
65
extern crate quickcheck;

wee_alloc/src/lib.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ infrastructure. Nevertheless, `wee_alloc` is also usable with `std`.
5050
// We aren't using the standard library.
5151
#![no_std]
5252
53-
// Required to replace the global allocator.
54-
#![feature(global_allocator)]
55-
5653
// Required to use the `alloc` crate and its types, the `abort` intrinsic, and a
5754
// custom panic handler.
58-
#![feature(alloc, core_intrinsics, lang_items)]
55+
#![feature(alloc, core_intrinsics, panic_implementation, lang_items)]
5956
6057
extern crate alloc;
6158
extern crate wee_alloc;
@@ -64,18 +61,22 @@ extern crate wee_alloc;
6461
#[global_allocator]
6562
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
6663
67-
// Need to provide a tiny `panic_fmt` lang-item implementation for `#![no_std]`.
68-
// This implementation will translate panics into traps in the resulting
69-
// WebAssembly.
70-
#[lang = "panic_fmt"]
71-
extern "C" fn panic_fmt(
72-
_args: ::core::fmt::Arguments,
73-
_file: &'static str,
74-
_line: u32
75-
) -> ! {
76-
use core::intrinsics;
64+
// Need to provide a tiny `panic` implementation for `#![no_std]`.
65+
// This translates into an `unreachable` instruction that will
66+
// raise a `trap` the WebAssembly execution if we panic at runtime.
67+
#[panic_implementation]
68+
fn panic(_info: &::core::panic::PanicInfo) -> ! {
69+
unsafe {
70+
::core::intrinsics::abort();
71+
}
72+
}
73+
74+
// Need to provide a tiny `oom` lang-item implementation for
75+
// `#![no_std]`.
76+
#[lang = "oom"]
77+
extern "C" fn oom() -> ! {
7778
unsafe {
78-
intrinsics::abort();
79+
::core::intrinsics::abort();
7980
}
8081
}
8182

0 commit comments

Comments
 (0)