]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Make rustc stop complaining about unused `Box::from_raw`s
authorMatt Corallo <git@bluematt.me>
Fri, 28 Oct 2022 21:14:28 +0000 (21:14 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 28 Oct 2022 21:14:28 +0000 (21:14 +0000)
c-bindings-gen/src/blocks.rs
c-bindings-gen/src/main.rs
lightning-c-bindings/src/c_types/mod.rs

index e6d1528c7f97084d7764e0add0651c0ff9679a00..28f30026ed0810ef0263be3a8b4636a234d59b54 100644 (file)
@@ -250,7 +250,7 @@ pub fn write_vec_block<W: std::io::Write>(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 {
index 3f47435d2ffee76d23b292dd8363adc7e2d3eae2..8b57bd9d265c9cf3b91dbdb4bed19da21abef87d 100644 (file)
@@ -677,7 +677,7 @@ fn writeln_opaque<W: std::io::Write>(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();
index 220777636c1eca44f3c043292e4d6e61dd42515b..71616375aabfc10a5784650328cf0803f45c24f1 100644 (file)
@@ -676,10 +676,10 @@ impl<O, E> Drop for CResultTempl<O, E> {
        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<T> SmartPtr<T> {
 impl<T> Drop for SmartPtr<T> {
        fn drop(&mut self) {
                if self.ptr != core::ptr::null_mut() {
-                       unsafe { Box::from_raw(self.ptr); }
+                       let _ = unsafe { Box::from_raw(self.ptr) };
                }
        }
 }