-
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.
Trigger warnings for unused wasm-bindgen attributes (#3073)
* Trigger warnings for unused wasm-bindgen attributes This attempts to do something similar to #3070, but without potentially dangerous fallout from strict-mode failing on all the existing code out there. Instead of forcing a compiler error like strict-mode does, this PR will internally generate unused variables with spans pointing to unused attributes, so that users get a relatively meaningful warning. Here's how the result looks like on example from #2874: ``` warning: unused variable: `typescript_type` --> tests\headless\snippets.rs:67:28 | 67 | #[wasm_bindgen(getter, typescript_type = "Thing[]")] | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_typescript_type` | = note: `#[warn(unused_variables)]` on by default ``` This is not 100% perfect - until Rust has a built-in `compile_warning!`, nothing is - but is a better status quo than the current one and can help users find problematic attributes without actually breaking their builds. Fixes #3038. * Guide users who used the suggested (invalid) fix (#1) Co-authored-by: Ingvar Stepanyan <me@rreverser.com> * Deprecate strict-macro feature; update tests * Skip anonymous scope if there are no unused attrs * Fix unused-attr check for reserved attribute names * Remove defunct deprecation warning Co-authored-by: Lukas Lihotzki <lukas@lihotzki.de>
- Loading branch information
1 parent
f82f5c5
commit 595b04b
Showing
5 changed files
with
112 additions
and
59 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
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 |
---|---|---|
@@ -1,11 +1,41 @@ | ||
error: unused #[wasm_bindgen] attribute | ||
--> $DIR/unused-attributes.rs:7:20 | ||
error: unused variable: `method` | ||
--> ui-tests/unused-attributes.rs:9:20 | ||
| | ||
7 | #[wasm_bindgen(method)] | ||
| ^^^^^^ | ||
|
||
error: unused #[wasm_bindgen] attribute | ||
--> $DIR/unused-attributes.rs:8:20 | ||
9 | #[wasm_bindgen(method)] | ||
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_method` | ||
| | ||
note: the lint level is defined here | ||
--> ui-tests/unused-attributes.rs:1:9 | ||
| | ||
8 | #[wasm_bindgen(method)] | ||
| ^^^^^^ | ||
1 | #![deny(unused_variables)] | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: unused variable: `getter` | ||
--> ui-tests/unused-attributes.rs:18:16 | ||
| | ||
18 | #[wasm_bindgen(getter, typescript_custom_section)] | ||
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_getter` | ||
|
||
error: unused variable: `readonly` | ||
--> ui-tests/unused-attributes.rs:21:16 | ||
| | ||
21 | #[wasm_bindgen(readonly)] | ||
| ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_readonly` | ||
|
||
error: unused variable: `getter_with_clone` | ||
--> ui-tests/unused-attributes.rs:24:16 | ||
| | ||
24 | #[wasm_bindgen(getter_with_clone, final)] | ||
| ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_getter_with_clone` | ||
|
||
error: unused variable: `final` | ||
--> ui-tests/unused-attributes.rs:24:35 | ||
| | ||
24 | #[wasm_bindgen(getter_with_clone, final)] | ||
| ^^^^^ help: if this is intentional, prefix it with an underscore: `_final` | ||
|
||
error: unused variable: `typescript_type` | ||
--> ui-tests/unused-attributes.rs:26:28 | ||
| | ||
26 | #[wasm_bindgen(getter, typescript_type = "Thing[]")] | ||
| ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_typescript_type` |