@@ -1191,7 +1191,8 @@ impl<T> MaybeUninit<T> {
1191
1191
}
1192
1192
1193
1193
/// Sets the value of the `MaybeUninit<T>`. This overwrites any previous value
1194
- /// without dropping it. For your convenience, this also returns a mutable
1194
+ /// without dropping it, so be careful not to use this twice unless you want to
1195
+ /// skip running the destructor. For your convenience, this also returns a mutable
1195
1196
/// reference to the (now safely initialized) contents of `self`.
1196
1197
#[ unstable( feature = "maybe_uninit" , issue = "53491" ) ]
1197
1198
#[ inline( always) ]
@@ -1214,7 +1215,7 @@ impl<T> MaybeUninit<T> {
1214
1215
/// use std::mem::MaybeUninit;
1215
1216
///
1216
1217
/// let mut x = MaybeUninit::<Vec<u32>>::uninitialized();
1217
- /// x.set( vec![0,1,2]);
1218
+ /// unsafe { x.as_mut_ptr().write( vec![0,1,2]); }
1218
1219
/// // Create a reference into the `MaybeUninit<T>`. This is okay because we initialized it.
1219
1220
/// let x_vec = unsafe { &*x.as_ptr() };
1220
1221
/// assert_eq!(x_vec.len(), 3);
@@ -1250,7 +1251,7 @@ impl<T> MaybeUninit<T> {
1250
1251
/// use std::mem::MaybeUninit;
1251
1252
///
1252
1253
/// let mut x = MaybeUninit::<Vec<u32>>::uninitialized();
1253
- /// x.set( vec![0,1,2]);
1254
+ /// unsafe { x.as_mut_ptr().write( vec![0,1,2]); }
1254
1255
/// // Create a reference into the `MaybeUninit<Vec<u32>>`.
1255
1256
/// // This is okay because we initialized it.
1256
1257
/// let x_vec = unsafe { &mut *x.as_mut_ptr() };
@@ -1295,7 +1296,7 @@ impl<T> MaybeUninit<T> {
1295
1296
/// use std::mem::MaybeUninit;
1296
1297
///
1297
1298
/// let mut x = MaybeUninit::<bool>::uninitialized();
1298
- /// x.set( true);
1299
+ /// unsafe { x.as_mut_ptr().write( true); }
1299
1300
/// let x_init = unsafe { x.into_initialized() };
1300
1301
/// assert_eq!(x_init, true);
1301
1302
/// ```
0 commit comments