File tree 3 files changed +7
-3
lines changed
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> {
74
74
///
75
75
/// ```rust
76
76
/// 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
78
81
/// ```
82
+ #[ must_use = "if you don't need the wrapper, you can use `mem::forget` instead" ]
79
83
#[ stable( feature = "manually_drop" , since = "1.20.0" ) ]
80
84
#[ rustc_const_stable( feature = "const_manually_drop" , since = "1.36.0" ) ]
81
85
#[ inline( always) ]
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ pub use crate::intrinsics::transmute;
145
145
#[ rustc_const_stable( feature = "const_forget" , since = "1.46.0" ) ]
146
146
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
147
147
pub const fn forget < T > ( t : T ) {
148
- ManuallyDrop :: new ( t) ;
148
+ let _ = ManuallyDrop :: new ( t) ;
149
149
}
150
150
151
151
/// 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> {
293
293
294
294
// Don't drop this `SyncOnceCell`. We just moved out one of the fields, but didn't set
295
295
// the state to uninitialized.
296
- mem:: ManuallyDrop :: new ( self ) ;
296
+ mem:: forget ( self ) ;
297
297
inner
298
298
}
299
299
You can’t perform that action at this time.
0 commit comments