Skip to content

Commit 5466076

Browse files
authored
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
1 parent fc9ee6a commit 5466076

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

regex-capi/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ffi_fn! {
5454

5555
ffi_fn! {
5656
fn rure_error_free(err: *mut Error) {
57-
unsafe { Box::from_raw(err); }
57+
unsafe { drop(Box::from_raw(err)); }
5858
}
5959
}
6060

regex-capi/src/rure.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ ffi_fn! {
151151

152152
ffi_fn! {
153153
fn rure_free(re: *const Regex) {
154-
unsafe { Box::from_raw(re as *mut Regex); }
154+
unsafe { drop(Box::from_raw(re as *mut Regex)); }
155155
}
156156
}
157157

@@ -257,10 +257,10 @@ ffi_fn! {
257257
fn rure_iter_capture_names_free(it: *mut IterCaptureNames) {
258258
unsafe {
259259
let it = &mut *it;
260-
while let Some(ptr) = it.name_ptrs.pop(){
261-
CString::from_raw(ptr);
260+
while let Some(ptr) = it.name_ptrs.pop() {
261+
drop(CString::from_raw(ptr));
262262
}
263-
Box::from_raw(it);
263+
drop(Box::from_raw(it));
264264
}
265265
}
266266
}
@@ -316,7 +316,7 @@ ffi_fn! {
316316

317317
ffi_fn! {
318318
fn rure_iter_free(it: *mut Iter) {
319-
unsafe { Box::from_raw(it); }
319+
unsafe { drop(Box::from_raw(it)); }
320320
}
321321
}
322322

@@ -407,7 +407,7 @@ ffi_fn! {
407407

408408
ffi_fn! {
409409
fn rure_captures_free(captures: *const Captures) {
410-
unsafe { Box::from_raw(captures as *mut Captures); }
410+
unsafe { drop(Box::from_raw(captures as *mut Captures)); }
411411
}
412412
}
413413

@@ -447,7 +447,7 @@ ffi_fn! {
447447

448448
ffi_fn! {
449449
fn rure_options_free(options: *mut Options) {
450-
unsafe { Box::from_raw(options); }
450+
unsafe { drop(Box::from_raw(options)); }
451451
}
452452
}
453453

@@ -527,7 +527,7 @@ ffi_fn! {
527527

528528
ffi_fn! {
529529
fn rure_set_free(re: *const RegexSet) {
530-
unsafe { Box::from_raw(re as *mut RegexSet); }
530+
unsafe { drop(Box::from_raw(re as *mut RegexSet)); }
531531
}
532532
}
533533

@@ -624,6 +624,6 @@ fn rure_escape(
624624

625625
ffi_fn! {
626626
fn rure_cstring_free(s: *mut c_char) {
627-
unsafe { CString::from_raw(s); }
627+
unsafe { drop(CString::from_raw(s)); }
628628
}
629629
}

0 commit comments

Comments
 (0)