Skip to content

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.

2 participants