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

clippy issue with #[wasm_bindgen] #13606

Open
WenqingZong opened this issue Oct 26, 2024 · 1 comment
Open

clippy issue with #[wasm_bindgen] #13606

WenqingZong opened this issue Oct 26, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@WenqingZong
Copy link

Summary

Hi, found this message in cargo clippy output so post the issue here.

Original code: WenqingZong/wasm-game-of-life@b388612 just git checkout it.

Cargo Clippy output:

➜  wasm-game-of-life git:(version1) cargo clippy
    Checking once_cell v1.20.2
    Checking cfg-if v1.0.0
    Checking wasm-bindgen v0.2.95
    Checking wasm-game-of-life v0.1.0 (/Users/wenqingzong/Projects/wasm-game-of-life)
warning: using `write!()` with a format string that ends in a single newline
  --> src/lib.rs:26:13
   |
26 |             write!(f, "\n")?;
   |             ^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline
   = note: `#[warn(clippy::write_with_newline)]` on by default
help: use `writeln!` instead
   |
26 -             write!(f, "\n")?;
26 +             writeln!(f)?;
   |

warning: you should consider adding a `Default` implementation for `Universe`
  --> src/lib.rs:35:5
   |
35 | /     pub fn new() -> Universe {
36 | |         let width = 64;
37 | |         let height = 64;
...  |
53 | |         }
54 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
   = note: `#[warn(clippy::new_without_default)]` on by default
help: try adding this
   |
34 + impl Default for Universe {
35 +     fn default() -> Self {
36 +         Self::new()
37 +     }
38 + }
   |

warning: `wasm-game-of-life` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p wasm-game-of-life` to apply 2 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.06s






➜  wasm-game-of-life git:(version1) cargo clippy --fix --lib -p wasm-game-of-life
    Checking wasm-game-of-life v0.1.0 (/Users/wenqingzong/Projects/wasm-game-of-life)
warning: failed to automatically apply fixes suggested by rustc to crate `wasm_game_of_life`

after fixes were automatically applied the compiler reported errors within these files:

  * src/lib.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error: #[wasm_bindgen] trait impls are not supported
  --> src/lib.rs:34:6
   |
34 | impl Default for Universe {
   |      ^^^^^^^

error: aborting due to 1 previous error

Original diagnostics will follow.

warning: using `write!()` with a format string that ends in a single newline
  --> src/lib.rs:26:13
   |
26 |             write!(f, "\n")?;
   |             ^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline
   = note: `#[warn(clippy::write_with_newline)]` on by default
help: use `writeln!` instead
   |
26 -             write!(f, "\n")?;
26 +             writeln!(f)?;
   |

warning: you should consider adding a `Default` implementation for `Universe`
  --> src/lib.rs:35:5
   |
35 | /     pub fn new() -> Universe {
36 | |         let width = 64;
37 | |         let height = 64;
...  |
53 | |         }
54 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
   = note: `#[warn(clippy::new_without_default)]` on by default
help: try adding this
   |
34 + impl Default for Universe {
35 +     fn default() -> Self {
36 +         Self::new()
37 +     }
38 + }
   |

warning: `wasm-game-of-life` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p wasm-game-of-life` to apply 2 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.15s

Reproducer

Code: WenqingZong/wasm-game-of-life@b388612

Step to reproduce: cargo clippy --fix --lib -p wasm-game-of-life

Version

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: aarch64-apple-darwin
release: 1.82.0
LLVM version: 19.1.1

Additional Labels

No response

@WenqingZong WenqingZong added the C-bug Category: Clippy is not doing the correct thing label Oct 26, 2024
@GnomedDev
Copy link
Contributor

GnomedDev commented Oct 26, 2024

The error is caused by the impl Default for Universe being generated in-between the #[wasm_bindgen] attribute applied to the impl and the impl itself, leading to the impl Default for Universe getting the #[wasm_bindgen] instead and erroring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

2 participants