From 54660765af59765e68e4fea56292139ae14ea1f9 Mon Sep 17 00:00:00 2001 From: Linda_pp Date: Thu, 14 Jul 2022 22:36:58 +0900 Subject: [PATCH] capi: fix 'unused return value' warnings Somewhat recently, 'CString::from_raw' got a '#[must_use]' slapped on it. Arguably, writing 'drop' around its return value is indeed much clearer. So we do that here. We also do that for 'Box::from_raw' even though it doesn't have a '#[must_use]' on it. But the same principle applies. PR #882 --- regex-capi/src/error.rs | 2 +- regex-capi/src/rure.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/regex-capi/src/error.rs b/regex-capi/src/error.rs index 2ca3fae80..a269a3913 100644 --- a/regex-capi/src/error.rs +++ b/regex-capi/src/error.rs @@ -54,7 +54,7 @@ ffi_fn! { ffi_fn! { fn rure_error_free(err: *mut Error) { - unsafe { Box::from_raw(err); } + unsafe { drop(Box::from_raw(err)); } } } diff --git a/regex-capi/src/rure.rs b/regex-capi/src/rure.rs index dc49b20a3..d2e1539ed 100644 --- a/regex-capi/src/rure.rs +++ b/regex-capi/src/rure.rs @@ -151,7 +151,7 @@ ffi_fn! { ffi_fn! { fn rure_free(re: *const Regex) { - unsafe { Box::from_raw(re as *mut Regex); } + unsafe { drop(Box::from_raw(re as *mut Regex)); } } } @@ -257,10 +257,10 @@ ffi_fn! { fn rure_iter_capture_names_free(it: *mut IterCaptureNames) { unsafe { let it = &mut *it; - while let Some(ptr) = it.name_ptrs.pop(){ - CString::from_raw(ptr); + while let Some(ptr) = it.name_ptrs.pop() { + drop(CString::from_raw(ptr)); } - Box::from_raw(it); + drop(Box::from_raw(it)); } } } @@ -316,7 +316,7 @@ ffi_fn! { ffi_fn! { fn rure_iter_free(it: *mut Iter) { - unsafe { Box::from_raw(it); } + unsafe { drop(Box::from_raw(it)); } } } @@ -407,7 +407,7 @@ ffi_fn! { ffi_fn! { fn rure_captures_free(captures: *const Captures) { - unsafe { Box::from_raw(captures as *mut Captures); } + unsafe { drop(Box::from_raw(captures as *mut Captures)); } } } @@ -447,7 +447,7 @@ ffi_fn! { ffi_fn! { fn rure_options_free(options: *mut Options) { - unsafe { Box::from_raw(options); } + unsafe { drop(Box::from_raw(options)); } } } @@ -527,7 +527,7 @@ ffi_fn! { ffi_fn! { fn rure_set_free(re: *const RegexSet) { - unsafe { Box::from_raw(re as *mut RegexSet); } + unsafe { drop(Box::from_raw(re as *mut RegexSet)); } } } @@ -624,6 +624,6 @@ fn rure_escape( ffi_fn! { fn rure_cstring_free(s: *mut c_char) { - unsafe { CString::from_raw(s); } + unsafe { drop(CString::from_raw(s)); } } }