This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +7
-3
lines changed Expand file tree Collapse file tree 3 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -74,8 +74,12 @@ impl<T> ManuallyDrop<T> {
7474 ///
7575 /// ```rust
7676 /// use std::mem::ManuallyDrop;
77- /// ManuallyDrop::new(Box::new(()));
77+ /// let mut x = ManuallyDrop::new(String::from("Hello World!"));
78+ /// x.truncate(5); // You can still safely operate on the value
79+ /// assert_eq!(*x, "Hello");
80+ /// // But `Drop` will not be run here
7881 /// ```
82+ #[ must_use = "if you don't need the wrapper, you can use `mem::forget` instead" ]
7983 #[ stable( feature = "manually_drop" , since = "1.20.0" ) ]
8084 #[ rustc_const_stable( feature = "const_manually_drop" , since = "1.36.0" ) ]
8185 #[ inline( always) ]
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ pub use crate::intrinsics::transmute;
145145#[ rustc_const_stable( feature = "const_forget" , since = "1.46.0" ) ]
146146#[ stable( feature = "rust1" , since = "1.0.0" ) ]
147147pub const fn forget < T > ( t : T ) {
148- ManuallyDrop :: new ( t) ;
148+ let _ = ManuallyDrop :: new ( t) ;
149149}
150150
151151/// Like [`forget`], but also accepts unsized values.
Original file line number Diff line number Diff line change @@ -293,7 +293,7 @@ impl<T> SyncOnceCell<T> {
293293
294294 // Don't drop this `SyncOnceCell`. We just moved out one of the fields, but didn't set
295295 // the state to uninitialized.
296- mem:: ManuallyDrop :: new ( self ) ;
296+ mem:: forget ( self ) ;
297297 inner
298298 }
299299
You can’t perform that action at this time.
0 commit comments