Skip to content

Commit 53c0275

Browse files
CentrilRalfJung
andauthored
Apply suggestions from code review
Co-Authored-By: RalfJung <[email protected]>
1 parent aa4a9b0 commit 53c0275

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/libcore/mem.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,13 +1064,13 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
10641064
/// use std::mem::{self, MaybeUninit};
10651065
///
10661066
/// let b: bool = unsafe { mem::uninitialized() }; // undefined behavior!
1067-
/// // equivalent code with `MaybeUninit`
1067+
/// // The equivalent code with `MaybeUninit`:
10681068
/// let b: bool = unsafe { MaybeUninit::uninitialized().into_initialized() }; // undefined behavior!
10691069
/// ```
10701070
///
10711071
/// Moreover, uninitialized memory is special in that the compiler knows that
10721072
/// 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,
10741074
/// which otherwise can hold any bit pattern:
10751075
///
10761076
/// ```rust,no_run
@@ -1084,7 +1084,7 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
10841084
/// (Notice that the rules around uninitialized integers are not finalized yet, but
10851085
/// until they are, it is advisable to avoid them.)
10861086
///
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.
10881088
/// It is a signal to the compiler indicating that the data here might *not*
10891089
/// be initialized:
10901090
///
@@ -1107,7 +1107,7 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
11071107
#[allow(missing_debug_implementations)]
11081108
#[unstable(feature = "maybe_uninit", issue = "53491")]
11091109
#[derive(Copy)]
1110-
// NOTE after stabilizing `MaybeUninit` proceed to deprecate `mem::uninitialized`
1110+
// NOTE after stabilizing `MaybeUninit` proceed to deprecate `mem::uninitialized`.
11111111
pub union MaybeUninit<T> {
11121112
uninit: (),
11131113
value: ManuallyDrop<T>,
@@ -1123,7 +1123,7 @@ impl<T: Copy> Clone for MaybeUninit<T> {
11231123
}
11241124

11251125
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.
11271127
///
11281128
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
11291129
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
@@ -1149,13 +1149,13 @@ impl<T> MaybeUninit<T> {
11491149
/// but `MaybeUninit<&'static i32>::zeroed()` is not because references must not
11501150
/// be null.
11511151
///
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.
11531153
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
11541154
///
11551155
/// # Example
11561156
///
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.
11591159
///
11601160
/// ```rust
11611161
/// #![feature(maybe_uninit)]
@@ -1166,7 +1166,7 @@ impl<T> MaybeUninit<T> {
11661166
/// assert_eq!(x, (0, false));
11671167
/// ```
11681168
///
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
11701170
/// cannot hold 0 as a valid value.
11711171
///
11721172
/// ```rust,no_run
@@ -1177,7 +1177,7 @@ impl<T> MaybeUninit<T> {
11771177
///
11781178
/// let x = MaybeUninit::<(u8, NotZero)>::zeroed();
11791179
/// 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.
11811181
/// // This is undefined behavior.
11821182
/// ```
11831183
#[unstable(feature = "maybe_uninit", issue = "53491")]
@@ -1203,7 +1203,7 @@ impl<T> MaybeUninit<T> {
12031203
}
12041204

12051205
/// 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.
12071207
///
12081208
/// # Examples
12091209
///
@@ -1237,7 +1237,7 @@ impl<T> MaybeUninit<T> {
12371237
}
12381238

12391239
/// 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.
12411241
///
12421242
/// # Examples
12431243
///
@@ -1249,7 +1249,8 @@ impl<T> MaybeUninit<T> {
12491249
///
12501250
/// let mut x = MaybeUninit::<Vec<u32>>::uninitialized();
12511251
/// 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.
12531254
/// let x_vec = unsafe { &mut *x.as_mut_ptr() };
12541255
/// x_vec.push(3);
12551256
/// assert_eq!(x_vec.len(), 4);
@@ -1303,7 +1304,7 @@ impl<T> MaybeUninit<T> {
13031304
///
13041305
/// let x = MaybeUninit::<Vec<u32>>::uninitialized();
13051306
/// 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.
13071308
/// ```
13081309
#[unstable(feature = "maybe_uninit", issue = "53491")]
13091310
#[inline(always)]
@@ -1312,16 +1313,16 @@ impl<T> MaybeUninit<T> {
13121313
ManuallyDrop::into_inner(self.value)
13131314
}
13141315

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
13161317
/// to the usual drop handling.
13171318
///
1318-
/// # Unsafety
1319+
/// # Safety
13191320
///
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
13211322
/// state. Calling this when the content is not yet fully initialized causes undefined
13221323
/// behavior.
13231324
///
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
13251326
/// multiple copies of the data (by calling `read_initialized` multiple times, or first
13261327
/// calling `read_initialized` and then [`into_initialized`]), it is your responsibility
13271328
/// to ensure that that data may indeed be duplicated.

0 commit comments

Comments
 (0)