From 02e160552212364b87022028ebcdd78bc2b77854 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Wed, 12 Jun 2024 15:43:29 +0200 Subject: [PATCH] Fix triggering `clippy::mem_forget` lint --- CHANGELOG.md | 3 +++ crates/backend/src/codegen.rs | 1 + tests/wasm/3944.rs | 6 ++++++ tests/wasm/closures.rs | 2 +- tests/wasm/ignore.rs | 2 ++ tests/wasm/main.rs | 3 +++ 6 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/wasm/3944.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index bcc66f5c606..4d18964b1ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,9 @@ * Fixed Rust values not getting GC'd if they were created via. a constructor. [#3940](https://github.com/rustwasm/wasm-bindgen/pull/3940) +* Fix triggering `clippy::mem_forget` lint in exported structs. + [#3985](https://github.com/rustwasm/wasm-bindgen/pull/3985) + -------------------------------------------------------------------------------- ## [0.2.92](https://github.com/rustwasm/wasm-bindgen/compare/0.2.91...0.2.92) diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index 268d74fc42c..0dc8ee3d00f 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -394,6 +394,7 @@ impl ToTokens for ast::Struct { #wasm_bindgen::__rt::std::result::Result::Err(value) } else { // Don't run `JsValue`'s destructor, `unwrap_fn` already did that for us. + #[allow(clippy::mem_forget)] #wasm_bindgen::__rt::std::mem::forget(value); unsafe { #wasm_bindgen::__rt::std::result::Result::Ok( diff --git a/tests/wasm/3944.rs b/tests/wasm/3944.rs new file mode 100644 index 00000000000..8a22b3d4ac3 --- /dev/null +++ b/tests/wasm/3944.rs @@ -0,0 +1,6 @@ +#![deny(clippy::mem_forget)] + +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +struct Foo2; diff --git a/tests/wasm/closures.rs b/tests/wasm/closures.rs index a0247b5d1ca..c36b5720559 100644 --- a/tests/wasm/closures.rs +++ b/tests/wasm/closures.rs @@ -473,7 +473,7 @@ fn drop_during_call_ok() { assert_eq!(x, 3); // make sure `A` is bound to our closure environment. - drop(&a); + let _a = &a; unsafe { assert!(!HIT); } diff --git a/tests/wasm/ignore.rs b/tests/wasm/ignore.rs index 39897e31b49..3e0cf927df6 100644 --- a/tests/wasm/ignore.rs +++ b/tests/wasm/ignore.rs @@ -1,3 +1,5 @@ +use wasm_bindgen_test::wasm_bindgen_test; + #[wasm_bindgen_test] #[ignore] fn should_panic() { diff --git a/tests/wasm/main.rs b/tests/wasm/main.rs index 6272352c2e9..fdef95f23d7 100644 --- a/tests/wasm/main.rs +++ b/tests/wasm/main.rs @@ -14,6 +14,8 @@ extern crate serde_derive; use wasm_bindgen::prelude::*; +#[path = "3944.rs"] +pub mod _3944; pub mod api; pub mod arg_names; pub mod async_vecs; @@ -31,6 +33,7 @@ pub mod final_; pub mod futures; pub mod gc; pub mod getters_and_setters; +pub mod ignore; pub mod import_class; pub mod imports; pub mod intrinsics;