Skip to content

Commit 22116c2

Browse files
committed
Global allocators have to be defined in the root of the crate
At least until rust-lang/rust#44113 is fixed.
1 parent b4ec84c commit 22116c2

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@ extern crate wasm_bindgen;
33

44
mod utils;
55

6+
use cfg_if::cfg_if;
67
use wasm_bindgen::prelude::*;
78

9+
cfg_if! {
10+
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
11+
// allocator.
12+
if #[cfg(feature = "wee_alloc")] {
13+
extern crate wee_alloc;
14+
#[global_allocator]
15+
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
16+
}
17+
}
18+
819
#[wasm_bindgen]
920
extern {
1021
fn alert(s: &str);

src/utils.rs

-10
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,3 @@ cfg_if! {
1111
pub fn set_panic_hook() {}
1212
}
1313
}
14-
15-
cfg_if! {
16-
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
17-
// allocator.
18-
if #[cfg(feature = "wee_alloc")] {
19-
extern crate wee_alloc;
20-
#[global_allocator]
21-
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
22-
}
23-
}

0 commit comments

Comments
 (0)