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

Ignoring return value from Box::from_raw does not cause warning #99269

Closed
rhysd opened this issue Jul 15, 2022 · 0 comments · Fixed by #99270
Closed

Ignoring return value from Box::from_raw does not cause warning #99269

rhysd opened this issue Jul 15, 2022 · 0 comments · Fixed by #99270
Labels
C-bug Category: This is a bug.

Comments

@rhysd
Copy link
Contributor

rhysd commented Jul 15, 2022

I tried this code:

#![allow(dead_code)]

unsafe fn free<T>(ptr: *mut T) {
    Box::from_raw(ptr);
}

fn main() {}

I expected to see this happen: explanation

The same as CString::from_raw, I expected the following warning:

warning: unused return value of `Box::<T>::from_raw` that must be used
 --> foo.rs:4:5
  |
4 |     Box::from_raw(ptr);
  |     ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_must_use)]` on by default
  = note: call `drop(from_raw(ptr))` if you intend to drop the `Box`

Instead, this happened: explanation

No warning is reported.

Meta

rustc --version --verbose:

rustc 1.62.0 (a8314ef7d 2022-06-27)
binary: rustc
commit-hash: a8314ef7d0ec7b75c336af2c9857bfaf43002bfc
commit-date: 2022-06-27
host: x86_64-apple-darwin
release: 1.62.0
LLVM version: 14.0.5

Note that #[must_use] was added to CString::from_raw at #89753 following the activity tracked at #89692.

I'm creating this issue after discussion at rust-lang/regex#882.

@rhysd rhysd added the C-bug Category: This is a bug. label Jul 15, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jul 16, 2022
@bors bors closed this as completed in 96474a7 Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant