@@ -1064,13 +1064,13 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
1064
1064
/// use std::mem::{self, MaybeUninit};
1065
1065
///
1066
1066
/// let b: bool = unsafe { mem::uninitialized() }; // undefined behavior!
1067
- /// // equivalent code with `MaybeUninit`
1067
+ /// // The equivalent code with `MaybeUninit`:
1068
1068
/// let b: bool = unsafe { MaybeUninit::uninitialized().into_initialized() }; // undefined behavior!
1069
1069
/// ```
1070
1070
///
1071
1071
/// Moreover, uninitialized memory is special in that the compiler knows that
1072
1072
/// it does not have a fixed value. This makes it undefined behavior to have
1073
- /// uninitialized data in a variable even if that variable has integer type,
1073
+ /// uninitialized data in a variable even if that variable has an integer type,
1074
1074
/// which otherwise can hold any bit pattern:
1075
1075
///
1076
1076
/// ```rust,no_run
@@ -1084,7 +1084,7 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
1084
1084
/// (Notice that the rules around uninitialized integers are not finalized yet, but
1085
1085
/// until they are, it is advisable to avoid them.)
1086
1086
///
1087
- /// `MaybeUninit` serves to enable unsafe code to deal with uninitialized data.
1087
+ /// `MaybeUninit<T> ` serves to enable unsafe code to deal with uninitialized data.
1088
1088
/// It is a signal to the compiler indicating that the data here might *not*
1089
1089
/// be initialized:
1090
1090
///
@@ -1107,7 +1107,7 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
1107
1107
#[ allow( missing_debug_implementations) ]
1108
1108
#[ unstable( feature = "maybe_uninit" , issue = "53491" ) ]
1109
1109
#[ derive( Copy ) ]
1110
- // NOTE after stabilizing `MaybeUninit` proceed to deprecate `mem::uninitialized`
1110
+ // NOTE after stabilizing `MaybeUninit` proceed to deprecate `mem::uninitialized`.
1111
1111
pub union MaybeUninit < T > {
1112
1112
uninit : ( ) ,
1113
1113
value : ManuallyDrop < T > ,
@@ -1123,7 +1123,7 @@ impl<T: Copy> Clone for MaybeUninit<T> {
1123
1123
}
1124
1124
1125
1125
impl < T > MaybeUninit < T > {
1126
- /// Create a new `MaybeUninit` initialized with the given value.
1126
+ /// Create a new `MaybeUninit<T> ` initialized with the given value.
1127
1127
///
1128
1128
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
1129
1129
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
@@ -1149,13 +1149,13 @@ impl<T> MaybeUninit<T> {
1149
1149
/// but `MaybeUninit<&'static i32>::zeroed()` is not because references must not
1150
1150
/// be null.
1151
1151
///
1152
- /// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
1152
+ /// Note that dropping a `MaybeUninit<T> ` will never call `T`'s drop code.
1153
1153
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
1154
1154
///
1155
1155
/// # Example
1156
1156
///
1157
- /// Correct usage of this method : initializing a struct with zero, where all
1158
- /// fields of the struct can hold 0 as a valid value.
1157
+ /// Correct usage of this function : initializing a struct with zero, where all
1158
+ /// fields of the struct can hold the bit-pattern 0 as a valid value.
1159
1159
///
1160
1160
/// ```rust
1161
1161
/// #![feature(maybe_uninit)]
@@ -1166,7 +1166,7 @@ impl<T> MaybeUninit<T> {
1166
1166
/// assert_eq!(x, (0, false));
1167
1167
/// ```
1168
1168
///
1169
- /// *Incorrect* usage of this method : initializing a struct with zero, where some fields
1169
+ /// *Incorrect* usage of this function : initializing a struct with zero, where some fields
1170
1170
/// cannot hold 0 as a valid value.
1171
1171
///
1172
1172
/// ```rust,no_run
@@ -1177,7 +1177,7 @@ impl<T> MaybeUninit<T> {
1177
1177
///
1178
1178
/// let x = MaybeUninit::<(u8, NotZero)>::zeroed();
1179
1179
/// let x = unsafe { x.into_initialized() };
1180
- /// // We create a `NotZero` (inside a pair) that does not have a valid discriminant.
1180
+ /// // Inside a pair, we create a `NotZero` that does not have a valid discriminant.
1181
1181
/// // This is undefined behavior.
1182
1182
/// ```
1183
1183
#[ unstable( feature = "maybe_uninit" , issue = "53491" ) ]
@@ -1203,7 +1203,7 @@ impl<T> MaybeUninit<T> {
1203
1203
}
1204
1204
1205
1205
/// Gets a pointer to the contained value. Reading from this pointer or turning it
1206
- /// into a reference is undefined behavior unless the `MaybeUninit` is initialized.
1206
+ /// into a reference is undefined behavior unless the `MaybeUninit<T> ` is initialized.
1207
1207
///
1208
1208
/// # Examples
1209
1209
///
@@ -1237,7 +1237,7 @@ impl<T> MaybeUninit<T> {
1237
1237
}
1238
1238
1239
1239
/// Gets a mutable pointer to the contained value. Reading from this pointer or turning it
1240
- /// into a reference is undefined behavior unless the `MaybeUninit` is initialized.
1240
+ /// into a reference is undefined behavior unless the `MaybeUninit<T> ` is initialized.
1241
1241
///
1242
1242
/// # Examples
1243
1243
///
@@ -1249,7 +1249,8 @@ impl<T> MaybeUninit<T> {
1249
1249
///
1250
1250
/// let mut x = MaybeUninit::<Vec<u32>>::uninitialized();
1251
1251
/// x.set(vec![0,1,2]);
1252
- /// // Create a reference into the `MaybeUninit`. This is okay because we initialized it.
1252
+ /// // Create a reference into the `MaybeUninit<Vec<u32>>`.
1253
+ /// // This is okay because we initialized it.
1253
1254
/// let x_vec = unsafe { &mut *x.as_mut_ptr() };
1254
1255
/// x_vec.push(3);
1255
1256
/// assert_eq!(x_vec.len(), 4);
@@ -1303,7 +1304,7 @@ impl<T> MaybeUninit<T> {
1303
1304
///
1304
1305
/// let x = MaybeUninit::<Vec<u32>>::uninitialized();
1305
1306
/// let x_init = unsafe { x.into_initialized() };
1306
- /// // `x` had not been initialized yet, so this last line causes undefined behavior.
1307
+ /// // `x` had not been initialized yet, so this last line caused undefined behavior.
1307
1308
/// ```
1308
1309
#[ unstable( feature = "maybe_uninit" , issue = "53491" ) ]
1309
1310
#[ inline( always) ]
@@ -1312,16 +1313,16 @@ impl<T> MaybeUninit<T> {
1312
1313
ManuallyDrop :: into_inner ( self . value )
1313
1314
}
1314
1315
1315
- /// Reads the value from the `MaybeUninit` container. The resulting `T` is subject
1316
+ /// Reads the value from the `MaybeUninit<T> ` container. The resulting `T` is subject
1316
1317
/// to the usual drop handling.
1317
1318
///
1318
- /// # Unsafety
1319
+ /// # Safety
1319
1320
///
1320
- /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized
1321
+ /// It is up to the caller to guarantee that the `MaybeUninit<T> ` really is in an initialized
1321
1322
/// state. Calling this when the content is not yet fully initialized causes undefined
1322
1323
/// behavior.
1323
1324
///
1324
- /// Moreover, this leaves a copy of the same data behind in the `MaybeUninit`. When using
1325
+ /// Moreover, this leaves a copy of the same data behind in the `MaybeUninit<T> `. When using
1325
1326
/// multiple copies of the data (by calling `read_initialized` multiple times, or first
1326
1327
/// calling `read_initialized` and then [`into_initialized`]), it is your responsibility
1327
1328
/// to ensure that that data may indeed be duplicated.
0 commit comments