From 325025e74b98ee3bab229ed416fa9669b9eeca71 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 30 Sep 2021 13:53:24 +0200 Subject: [PATCH] Improve previous commit --- library/core/src/array/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 3fa63cf968f64..6825e663fc61d 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -568,18 +568,17 @@ where fn drop(&mut self) { debug_assert!(self.initialized <= N); - let ptr = MaybeUninit::slice_as_mut_ptr(self.array_mut); - let initialized_part = crate::ptr::slice_from_raw_parts_mut(ptr, self.initialized); - - // SAFETY: this raw slice will contain only initialized objects. + // SAFETY: this slice will contain only initialized objects. unsafe { - crate::ptr::drop_in_place(initialized_part); + crate::ptr::drop_in_place(MaybeUninit::slice_assume_init_mut( + &mut self.array_mut.get_unchecked_mut(..self.initialized), + )); } } } let mut array = MaybeUninit::uninit_array::(); - let mut guard: Guard<'_, _, N> = Guard { array_mut: &mut array, initialized: 0 }; + let mut guard = Guard { array_mut: &mut array, initialized: 0 }; while let Some(item_rslt) = iter.next() { let item = match item_rslt {