wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

removes unnecessary drop()

Open mBornand opened this issue 2 years ago • 0 comments

The drop function is unnecessary as it will be droped anyway. But if we leave it and the struct implements Copy clippy complains about dropping the copy an not the original.

Without this, this code

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
#[derive(Copy, Clone)]
pub struct Test {
    pub a: u32
}

produces:

error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
 --> src/lib.rs:3:1
  |
3 | #[wasm_bindgen]
  | ^^^^^^^^^^^^^^^
  |
  = note: `#[deny(clippy::drop_copy)]` on by default
note: argument has type `Test`
 --> src/lib.rs:3:1
  |
3 | #[wasm_bindgen]
  | ^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#drop_copy
  = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

It is also a solution to the already closed #2858

mBornand avatar Jul 07 '22 21:07 mBornand