@@ -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
6057extern crate alloc;
6158extern crate wee_alloc;
@@ -64,18 +61,22 @@ extern crate wee_alloc;
6461#[global_allocator]
6562static 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
@@ -222,7 +223,7 @@ for hacking!
222223
223224#![ deny( missing_docs) ]
224225#![ cfg_attr( not( feature = "use_std_for_test_debugging" ) , no_std) ]
225- #![ feature( alloc, allocator_api, core_intrinsics, global_allocator ) ]
226+ #![ feature( alloc, allocator_api, core_intrinsics) ]
226227#![ cfg_attr( target_arch = "wasm32" , feature( link_llvm_intrinsics) ) ]
227228
228229#[ macro_use]
@@ -269,7 +270,7 @@ mod neighbors;
269270mod size_classes;
270271
271272use const_init:: ConstInit ;
272- use core:: alloc:: { Alloc , AllocErr , GlobalAlloc , Layout , Opaque } ;
273+ use core:: alloc:: { Alloc , AllocErr , GlobalAlloc , Layout } ;
273274use core:: cell:: Cell ;
274275use core:: cmp;
275276use core:: marker:: Sync ;
@@ -520,7 +521,7 @@ impl<'a> FreeCell<'a> {
520521 }
521522
522523 unsafe fn from_uninitialized (
523- raw : NonNull < Opaque > ,
524+ raw : NonNull < u8 > ,
524525 size : Bytes ,
525526 next_free : Option < * const FreeCell < ' a > > ,
526527 policy : & AllocPolicy < ' a > ,
@@ -586,7 +587,7 @@ impl<'a> FreeCell<'a> {
586587 let split_cell_head = split_and_aligned - size_of :: < CellHeader > ( ) . 0 ;
587588 let split_cell = unsafe {
588589 & * FreeCell :: from_uninitialized (
589- unchecked_unwrap ( NonNull :: new ( split_cell_head as * mut Opaque ) ) ,
590+ unchecked_unwrap ( NonNull :: new ( split_cell_head as * mut u8 ) ) ,
590591 Bytes ( next - split_cell_head) - size_of :: < CellHeader > ( ) ,
591592 None ,
592593 policy,
@@ -951,7 +952,7 @@ unsafe fn alloc_first_fit<'a>(
951952 align : Bytes ,
952953 head : & Cell < * const FreeCell < ' a > > ,
953954 policy : & AllocPolicy < ' a > ,
954- ) -> Result < NonNull < Opaque > , AllocErr > {
955+ ) -> Result < NonNull < u8 > , AllocErr > {
955956 extra_assert ! ( size. 0 > 0 ) ;
956957
957958 walk_free_list ( head, policy, |previous, current| {
@@ -960,7 +961,7 @@ unsafe fn alloc_first_fit<'a>(
960961 if let Some ( allocated) = current. try_alloc ( previous, size, align, policy) {
961962 assert_aligned_to ( allocated. data ( ) , align) ;
962963 return Some ( unchecked_unwrap (
963- NonNull :: new ( allocated. data ( ) as * mut Opaque ) ,
964+ NonNull :: new ( allocated. data ( ) as * mut u8 ) ,
964965 ) ) ;
965966 }
966967
@@ -973,7 +974,7 @@ unsafe fn alloc_with_refill<'a, 'b>(
973974 align : Bytes ,
974975 head : & ' b Cell < * const FreeCell < ' a > > ,
975976 policy : & AllocPolicy < ' a > ,
976- ) -> Result < NonNull < Opaque > , AllocErr > {
977+ ) -> Result < NonNull < u8 > , AllocErr > {
977978 if let Ok ( result) = alloc_first_fit ( size, align, head, policy) {
978979 return Ok ( result) ;
979980 }
@@ -1072,7 +1073,7 @@ unsafe impl<'a, 'b> Alloc for &'b WeeAlloc<'a>
10721073where
10731074 ' a : ' b ,
10741075{
1075- unsafe fn alloc ( & mut self , layout : Layout ) -> Result < NonNull < Opaque > , AllocErr > {
1076+ unsafe fn alloc ( & mut self , layout : Layout ) -> Result < NonNull < u8 > , AllocErr > {
10761077 let size = Bytes ( layout. size ( ) ) ;
10771078 let align = if layout. align ( ) == 0 {
10781079 Bytes ( 1 )
@@ -1084,7 +1085,7 @@ where
10841085 // Ensure that our made up pointer is properly aligned by using the
10851086 // alignment as the pointer.
10861087 extra_assert ! ( align. 0 > 0 ) ;
1087- return Ok ( NonNull :: new_unchecked ( align. 0 as * mut Opaque ) ) ;
1088+ return Ok ( NonNull :: new_unchecked ( align. 0 as * mut u8 ) ) ;
10881089 }
10891090
10901091 let size: Words = size. round_up_to ( ) ;
@@ -1095,7 +1096,7 @@ where
10951096 } )
10961097 }
10971098
1098- unsafe fn dealloc ( & mut self , ptr : NonNull < Opaque > , layout : Layout ) {
1099+ unsafe fn dealloc ( & mut self , ptr : NonNull < u8 > , layout : Layout ) {
10991100 let size = Bytes ( layout. size ( ) ) ;
11001101 if size. 0 == 0 {
11011102 return ;
@@ -1185,15 +1186,15 @@ where
11851186}
11861187
11871188unsafe impl GlobalAlloc for WeeAlloc < ' static > {
1188- unsafe fn alloc ( & self , layout : Layout ) -> * mut Opaque {
1189+ unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
11891190 let mut me = self ;
11901191 match Alloc :: alloc ( & mut me, layout) {
11911192 Ok ( ptr) => ptr. as_ptr ( ) ,
1192- Err ( AllocErr ) => 0 as * mut Opaque ,
1193+ Err ( AllocErr ) => 0 as * mut u8 ,
11931194 }
11941195 }
11951196
1196- unsafe fn dealloc ( & self , ptr : * mut Opaque , layout : Layout ) {
1197+ unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
11971198 if let Some ( ptr) = NonNull :: new ( ptr) {
11981199 let mut me = self ;
11991200 Alloc :: dealloc ( & mut me, ptr, layout) ;
0 commit comments