File tree 3 files changed +27
-0
lines changed
3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -949,6 +949,7 @@ impl<T: ?Sized> Box<T> {
949
949
/// [`Layout`]: crate::Layout
950
950
#[ stable( feature = "box_raw" , since = "1.4.0" ) ]
951
951
#[ inline]
952
+ #[ must_use = "call `drop(from_raw(ptr))` if you intend to drop the `Box`" ]
952
953
pub unsafe fn from_raw ( raw : * mut T ) -> Self {
953
954
unsafe { Self :: from_raw_in ( raw, Global ) }
954
955
}
Original file line number Diff line number Diff line change
1
+ // #99269
2
+
3
+ // check-pass
4
+
5
+ #![ warn( unused_must_use) ]
6
+
7
+ unsafe fn free < T > ( ptr : * mut T ) {
8
+ Box :: from_raw ( ptr) ; //~ WARNING unused return value
9
+ }
10
+
11
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ warning: unused return value of `Box::<T>::from_raw` that must be used
2
+ --> $DIR/must-use-box-from-raw.rs:8:5
3
+ |
4
+ LL | Box::from_raw(ptr);
5
+ | ^^^^^^^^^^^^^^^^^^^
6
+ |
7
+ note: the lint level is defined here
8
+ --> $DIR/must-use-box-from-raw.rs:5:9
9
+ |
10
+ LL | #![warn(unused_must_use)]
11
+ | ^^^^^^^^^^^^^^^
12
+ = note: call `drop(from_raw(ptr))` if you intend to drop the `Box`
13
+
14
+ warning: 1 warning emitted
15
+
You can’t perform that action at this time.
0 commit comments