Open
Description
Updated Report
use wasm_bindgen::prelude::*;
impl TestStruct {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
unimplemented!();
}
}
yields...
error: expected one of `(`, `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `static`
--> examples/add/src/lib.rs:4:5
|
4 | #[wasm_bindgen(constructor)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0412]: cannot find type `TestStruct` in this scope
--> examples/add/src/lib.rs:3:6
|
3 | impl TestStruct {
| ^^^^^^^^^^ not found in this scope
error: aborting due to 2 previous errors
which is a pretty bad error!
Original Report
Note: I edited the issue to suggest a better error message since I found the cause.
Describe the Bug
When building the provided code, I get an unclear compiler error.
Steps to Reproduce
- Compile the following code with
wasm-pack build
:
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
pub struct TestStruct {}
impl TestStruct {
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
unimplemented!();
}
}
Expected Behavior
I expect a compiler error that suggests the impl
block have a #[wasm-bindgen]
above it.
Actual Behavior
I get the following compiler error:
error: expected one of `(`, `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `static`
--> src\core\crypto.rs:9:5
|
9 | #[wasm_bindgen(constructor)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^