Skip to content

Commit ae2b1f0

Browse files
authored
Rollup merge of rust-lang#103447 - ajtribick:maybe_uninit_doc_update, r=scottmcm
`MaybeUninit`: use `assume_init_drop()` in the partially initialized array example The `assume_init_drop()` method does the same thing as the pointer conversion, and makes the example more straightforward.
2 parents 296700e + 560433a commit ae2b1f0

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

library/core/src/mem/maybe_uninit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ use crate::slice;
146146
///
147147
/// ```
148148
/// use std::mem::MaybeUninit;
149-
/// use std::ptr;
150149
///
151150
/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is
152151
/// // safe because the type we are claiming to have initialized here is a
@@ -162,7 +161,7 @@ use crate::slice;
162161
///
163162
/// // For each item in the array, drop if we allocated it.
164163
/// for elem in &mut data[0..data_len] {
165-
/// unsafe { ptr::drop_in_place(elem.as_mut_ptr()); }
164+
/// unsafe { elem.assume_init_drop(); }
166165
/// }
167166
/// ```
168167
///

0 commit comments

Comments
 (0)