Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capi: Fix 'unused return value' warnings #882

Merged
merged 2 commits into from Jul 14, 2022
Merged

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Jul 14, 2022

cargo check --workspace reported the following warnings on my local machine.

warning: unused return value of `alloc::ffi::c_str::CString::from_raw` that must be used
   --> regex-capi/src/rure.rs:261:17
    |
261 |                 CString::from_raw(ptr);
    |                 ^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unused_must_use)]` on by default
    = note: call `drop(from_raw(ptr))` if you intend to drop the `CString`

warning: unused return value of `alloc::ffi::c_str::CString::from_raw` that must be used
   --> regex-capi/src/rure.rs:627:18
    |
627 |         unsafe { CString::from_raw(s); }
    |                  ^^^^^^^^^^^^^^^^^^^^^
    |
    = note: call `drop(from_raw(ptr))` if you intend to drop the `CString`

warning: `rure` (lib) generated 2 warnings

This PR fixes the warnings.

Environment

  • rustc: 1.62.0
  • cargo: 1.62.0
  • OS: macOS 11.6.7

@rhysd
Copy link
Contributor Author

rhysd commented Jul 14, 2022

Note: The #[must_use] changes were added at Rust 1.57: rust-lang/rust#89692

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might as well go the whole nine yards here and add drop(..) around other calls to from_raw as well. e.g., Box::from_raw. Would you mind doing that as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review comment. I searched Box::from_raw and applied the same fix at 1324f2d

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants