rust-lang / rust-lang/rust-clippy

clippy issue with #[wasm_bindgen]

Open
#13,606 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

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

Original code: https://github.com/WenqingZong/wasm-game-of-life/pull/1/commits/b388612cddb1e5507bb580f979dfcb8e030de491 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: https://github.com/WenqingZong/wasm-game-of-life/pull/1/commits/b388612cddb1e5507bb580f979dfcb8e030de491

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproducer commit and its src/lib.rs, then run cargo clippy --fix --lib -p wasm-game-of-life using the reported Rust version. Trace how the two suggested fixes are applied around #[wasm_bindgen] and verify that the command no longer produces the reported unsupported trait-impl error while preserving the lint fixes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.