-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved errors for invalid
self
arguments (#4276)
- Loading branch information
1 parent
bd73514
commit 9e78347
Showing
4 changed files
with
79 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub struct A { | ||
data: u32, | ||
} | ||
|
||
// oh no, I forgot to add `#[wasm_bindgen]` to the impl block | ||
impl A { | ||
#[wasm_bindgen(js_name = bar)] | ||
pub fn foo(&self) {} | ||
} | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
type MyClass; | ||
|
||
// oops, I mixed up `self` and `this` | ||
#[wasm_bindgen(method)] | ||
fn render(self: &MyClass) -> String; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error: the `self` argument is only allowed for functions in `impl` blocks. | ||
|
||
If the function is already in an `impl` block, did you perhaps forget to add `#[wasm_bindgen]` to the `impl` block? | ||
--> ui-tests/invalid-self.rs:11:17 | ||
| | ||
11 | pub fn foo(&self) {} | ||
| ^^^^ | ||
|
||
error: the `self` argument is not allowed for `extern` functions. | ||
|
||
Did you perhaps mean `this`? For more information on importing JavaScript functions, see: | ||
https://rustwasm.github.io/docs/wasm-bindgen/examples/import-js.html | ||
--> ui-tests/invalid-self.rs:20:15 | ||
| | ||
20 | fn render(self: &MyClass) -> String; | ||
| ^^^^ |