Skip to content

Commit eb3f001

Browse files
committed
make the array initialization guard available to other modules
1 parent b00666e commit eb3f001

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

library/core/src/array/mod.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -865,24 +865,6 @@ where
865865
return Ok(Try::from_output(unsafe { mem::zeroed() }));
866866
}
867867

868-
struct Guard<'a, T, const N: usize> {
869-
array_mut: &'a mut [MaybeUninit<T>; N],
870-
initialized: usize,
871-
}
872-
873-
impl<T, const N: usize> Drop for Guard<'_, T, N> {
874-
fn drop(&mut self) {
875-
debug_assert!(self.initialized <= N);
876-
877-
// SAFETY: this slice will contain only initialized objects.
878-
unsafe {
879-
crate::ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(
880-
&mut self.array_mut.get_unchecked_mut(..self.initialized),
881-
));
882-
}
883-
}
884-
}
885-
886868
let mut array = MaybeUninit::uninit_array::<N>();
887869
let mut guard = Guard { array_mut: &mut array, initialized: 0 };
888870

@@ -920,6 +902,24 @@ where
920902
Ok(Try::from_output(output))
921903
}
922904

905+
pub(crate) struct Guard<'a, T, const N: usize> {
906+
pub array_mut: &'a mut [MaybeUninit<T>; N],
907+
pub initialized: usize,
908+
}
909+
910+
impl<T, const N: usize> Drop for Guard<'_, T, N> {
911+
fn drop(&mut self) {
912+
debug_assert!(self.initialized <= N);
913+
914+
// SAFETY: this slice will contain only initialized objects.
915+
unsafe {
916+
crate::ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(
917+
&mut self.array_mut.get_unchecked_mut(..self.initialized),
918+
));
919+
}
920+
}
921+
}
922+
923923
/// Returns the next chunk of `N` items from the iterator or errors with an
924924
/// iterator over the remainder. Used for `Iterator::next_chunk`.
925925
#[inline]

0 commit comments

Comments
 (0)