Rollup merge of #99270 - rhysd:issue-99269, r=Mark-Simulacrum
Add `#[must_use]` to `Box::from_raw` Fixes #99269
This commit is contained in:
commit
96474a718b
@ -949,6 +949,7 @@ impl<T: ?Sized> Box<T> {
|
||||
/// [`Layout`]: crate::Layout
|
||||
#[stable(feature = "box_raw", since = "1.4.0")]
|
||||
#[inline]
|
||||
#[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `Box`"]
|
||||
pub unsafe fn from_raw(raw: *mut T) -> Self {
|
||||
unsafe { Self::from_raw_in(raw, Global) }
|
||||
}
|
||||
|
11
src/test/ui/lint/unused/must-use-box-from-raw.rs
Normal file
11
src/test/ui/lint/unused/must-use-box-from-raw.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// #99269
|
||||
|
||||
// check-pass
|
||||
|
||||
#![warn(unused_must_use)]
|
||||
|
||||
unsafe fn free<T>(ptr: *mut T) {
|
||||
Box::from_raw(ptr); //~ WARNING unused return value
|
||||
}
|
||||
|
||||
fn main() {}
|
15
src/test/ui/lint/unused/must-use-box-from-raw.stderr
Normal file
15
src/test/ui/lint/unused/must-use-box-from-raw.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
warning: unused return value of `Box::<T>::from_raw` that must be used
|
||||
--> $DIR/must-use-box-from-raw.rs:8:5
|
||||
|
|
||||
LL | Box::from_raw(ptr);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/must-use-box-from-raw.rs:5:9
|
||||
|
|
||||
LL | #![warn(unused_must_use)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
= note: call `drop(from_raw(ptr))` if you intend to drop the `Box`
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
Loading…
Reference in New Issue
Block a user