From 5266836421190e74f893a3f9de5182057c2bd9b8 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 28 Oct 2022 21:14:28 +0000 Subject: [PATCH] Make rustc stop complaining about unused `Box::from_raw`s --- c-bindings-gen/src/blocks.rs | 2 +- c-bindings-gen/src/main.rs | 2 +- lightning-c-bindings/src/c_types/mod.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/c-bindings-gen/src/blocks.rs b/c-bindings-gen/src/blocks.rs index e6d1528..28f3002 100644 --- a/c-bindings-gen/src/blocks.rs +++ b/c-bindings-gen/src/blocks.rs @@ -250,7 +250,7 @@ pub fn write_vec_block(w: &mut W, mangled_container: &str, in writeln!(w, "impl Drop for {} {{", mangled_container).unwrap(); writeln!(w, "\tfn drop(&mut self) {{").unwrap(); writeln!(w, "\t\tif self.datalen == 0 {{ return; }}").unwrap(); - writeln!(w, "\t\tunsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap(); + writeln!(w, "\t\tlet _ = unsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap(); writeln!(w, "\t}}").unwrap(); writeln!(w, "}}").unwrap(); if clonable { diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index 3f47435..8b57bd9 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -677,7 +677,7 @@ fn writeln_opaque(w: &mut W, ident: &syn::Ident, struct_name: writeln!(w, "#[allow(unused)]").unwrap(); writeln!(w, "/// Used only if an object of this type is returned as a trait impl by a method").unwrap(); writeln!(w, "pub(crate) extern \"C\" fn {}_free_void(this_ptr: *mut c_void) {{", struct_name).unwrap(); - writeln!(w, "\tunsafe {{ let _ = Box::from_raw(this_ptr as *mut native{}); }}\n}}", struct_name).unwrap(); + writeln!(w, "\tlet _ = unsafe {{ Box::from_raw(this_ptr as *mut native{}) }};\n}}", struct_name).unwrap(); writeln!(w, "#[allow(unused)]").unwrap(); writeln!(w, "impl {} {{", struct_name).unwrap(); writeln!(w, "\tpub(crate) fn get_native_ref(&self) -> &'static native{} {{", struct_name).unwrap(); diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 2207776..7161637 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -676,10 +676,10 @@ impl Drop for CResultTempl { fn drop(&mut self) { if self.result_ok { if unsafe { !self.contents.result.is_null() } { - unsafe { Box::from_raw(self.contents.result) }; + let _ = unsafe { Box::from_raw(self.contents.result) }; } } else if unsafe { !self.contents.err.is_null() } { - unsafe { Box::from_raw(self.contents.err) }; + let _ = unsafe { Box::from_raw(self.contents.err) }; } } } @@ -780,7 +780,7 @@ impl SmartPtr { impl Drop for SmartPtr { fn drop(&mut self) { if self.ptr != core::ptr::null_mut() { - unsafe { Box::from_raw(self.ptr); } + let _ = unsafe { Box::from_raw(self.ptr) }; } } } -- 2.39.5