Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library doesn't compile with default-features=false #3961

Closed
survived opened this issue May 14, 2024 · 3 comments
Closed

Library doesn't compile with default-features=false #3961

survived opened this issue May 14, 2024 · 3 comments
Labels

Comments

@survived
Copy link

Describe the Bug

Library doesn't compile without default features.

Steps to Reproduce

Either add wasm-bindgen as dependency to a project:

wasm-bindgen = { version = "0.2", default-features = false }

Or git clone the repo and then do

cargo check --no-default-features

Expected Behavior

Crate is expected to compile with any set of chosen features, including when all features are off.

Actual Behavior

It fails to compile because the code uses std when std feature is disabled.

Compilation error message

error[E0432]: unresolved imports `crate::convert::VectorFromWasmAbi`, `crate::convert::VectorIntoWasmAbi`
  --> src/convert/slices.rs:13:22
   |
13 | use crate::convert::{VectorFromWasmAbi, VectorIntoWasmAbi};
   |                      ^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^ no `VectorIntoWasmAbi` in `convert`
   |                      |
   |                      no `VectorFromWasmAbi` in `convert`
   |
help: a similar name exists in the module
   |
13 | use crate::convert::{RefFromWasmAbi, VectorIntoWasmAbi};
   |                      ~~~~~~~~~~~~~~
help: a similar name exists in the module
   |
13 | use crate::convert::{VectorFromWasmAbi, OptionIntoWasmAbi};
   |                                         ~~~~~~~~~~~~~~~~~

error[E0433]: failed to resolve: use of undeclared crate or module `std`
    --> src/lib.rs:1349:23
     |
1349 |             let msg = std::format!(
     |                       ^^^ use of undeclared crate or module `std`

error[E0433]: failed to resolve: use of undeclared crate or module `std`
    --> src/lib.rs:1818:35
     |
1818 |                 crate::throw_str(&std::format!("{:?}", e));
     |                                   ^^^ use of undeclared crate or module `std`

error[E0433]: failed to resolve: use of undeclared crate or module `std`
    --> src/lib.rs:1705:5
     |
1705 |     std::thread_local! {
     |     ^^^ use of undeclared crate or module `std`

error[E0433]: failed to resolve: could not find `externref` in the crate root
    --> src/lib.rs:1702:16
     |
1702 |         crate::externref::link_intrinsics();
     |                ^^^^^^^^^ could not find `externref` in the crate root

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:190:27
    |
190 |               type Anchor = Box<[$t]>;
    |                             ^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:193:54
    |
193 |               unsafe fn ref_from_abi(js: WasmSlice) -> Box<[$t]> {
    |                                                        ^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:194:18
    |
194 |                   <Box<[$t]>>::from_abi(js)
    |                    ^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `WasmMutSlice` in this scope
   --> src/convert/slices.rs:199:24
    |
199 |               type Abi = WasmMutSlice;
    |                          ^^^^^^^^^^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `MutSlice` in this scope
   --> src/convert/slices.rs:200:27
    |
200 |               type Anchor = MutSlice<$t>;
    |                             ^^^^^^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `WasmMutSlice` in this scope
   --> src/convert/slices.rs:203:44
    |
203 |               unsafe fn ref_mut_from_abi(js: WasmMutSlice) -> MutSlice<$t> {
    |                                              ^^^^^^^^^^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `MutSlice` in this scope
   --> src/convert/slices.rs:203:61
    |
203 |               unsafe fn ref_mut_from_abi(js: WasmMutSlice) -> MutSlice<$t> {
    |                                                               ^^^^^^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:204:33
    |
204 |                   let contents = <Box<[$t]>>::from_abi(js.slice);
    |                                   ^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `JsValue`
   --> src/convert/slices.rs:205:26
    |
205 |                   let js = JsValue::from_abi(js.idx);
    |                            ^^^^^^^ use of undeclared type `JsValue`
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
    |
4   + use crate::JsValue;
    |

error[E0422]: cannot find struct, variant or union type `MutSlice` in this scope
   --> src/convert/slices.rs:206:17
    |
206 |                   MutSlice { contents, js }
    |                   ^^^^^^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:212:27
    |
212 |               type Anchor = Box<[$t]>;
    |                             ^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:215:59
    |
215 |               unsafe fn long_ref_from_abi(js: WasmSlice) -> Box<[$t]> {
    |                                                             ^^^ not found in this scope
...
222 | / vectors! {
223 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
224 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:355:19
    |
355 |     type Anchor = Box<str>;
    |                   ^^^ not found in this scope

error[E0433]: failed to resolve: use of undeclared crate or module `mem`
   --> src/convert/slices.rs:359:9
    |
359 |         mem::transmute::<Box<[u8]>, Box<str>>(<Box<[u8]>>::from_abi(js))
    |         ^^^ use of undeclared crate or module `mem`
    |
help: consider importing one of these items
    |
4   + use core::mem;
    |
4   + use crate::mem;
    |

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:359:26
    |
359 |         mem::transmute::<Box<[u8]>, Box<str>>(<Box<[u8]>>::from_abi(js))
    |                          ^^^ not found in this scope

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:359:37
    |
359 |         mem::transmute::<Box<[u8]>, Box<str>>(<Box<[u8]>>::from_abi(js))
    |                                     ^^^ not found in this scope

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:359:48
    |
359 |         mem::transmute::<Box<[u8]>, Box<str>>(<Box<[u8]>>::from_abi(js))
    |                                                ^^^ not found in this scope

error[E0412]: cannot find type `Box` in this scope
   --> src/convert/slices.rs:365:19
    |
365 |     type Anchor = Box<str>;
    |                   ^^^ not found in this scope

error[E0425]: cannot find value `GLOBAL_EXNDATA` in this scope
    --> src/lib.rs:1711:9
     |
1711 |         GLOBAL_EXNDATA.with(|data| {
     |         ^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `GLOBAL_EXNDATA` in this scope
    --> src/lib.rs:1718:9
     |
1718 |         GLOBAL_EXNDATA.with(|data| {
     |         ^^^^^^^^^^^^^^ not found in this scope

error[E0433]: failed to resolve: use of undeclared crate or module `std`
    --> src/lib.rs:1814:13
     |
1814 |     impl<E: std::fmt::Debug> Main for &mut MainWrapper<Result<(), E>> {
     |             ^^^ use of undeclared crate or module `std`
     |
help: consider importing one of these items
     |
1430 +     use core::fmt;
     |
1430 +     use crate::fmt;
     |
help: if you import `fmt`, refer to it directly
     |
1814 -     impl<E: std::fmt::Debug> Main for &mut MainWrapper<Result<(), E>> {
1814 +     impl<E: fmt::Debug> Main for &mut MainWrapper<Result<(), E>> {
     |

@survived survived added the bug label May 14, 2024
@Liamolucko
Copy link
Collaborator

Yeah, wasm-bindgen's no_std support has been broken for a while: see #2689 (comment).

@daxpedda
Copy link
Collaborator

I'm happy to review a PR making the std feature no-op.

@daxpedda
Copy link
Collaborator

This was fixed in #4005.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants