Skip to content

Commit 9603a5f

Browse files
committed
Use assume_init_ref directly from slice
1 parent 7babfc5 commit 9603a5f

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

library/core/src/array/iter/iter_inner.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,10 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
177177

178178
#[inline]
179179
pub(super) fn peek_with<U>(&self, func: impl for<'b> FnOnce(Option<&'b T>) -> U) -> U {
180-
let tmp = self.alive.clone().next().map(|idx| {
180+
func(self.alive.clone().next().map(|idx| {
181181
// SAFETY: `idx` is in self.alive range
182-
unsafe { self.data.get_unchecked(idx).assume_init_read() }
183-
});
184-
185-
let out = func(tmp.as_ref());
186-
// Avoid dropping before the item is consumed
187-
crate::mem::forget(tmp);
188-
out
182+
unsafe { self.data.get_unchecked(idx).assume_init_ref() }
183+
}));
189184
}
190185

191186
#[inline]

0 commit comments

Comments
 (0)