We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c552fc8 commit 6fc70f2Copy full SHA for 6fc70f2
library/core/src/array/iter/iter_inner.rs
@@ -176,13 +176,16 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
176
}
177
178
#[inline]
179
- pub(super) fn peek_with<U>(&mut self, func: impl for<'b> FnOnce(Option<&'b T>) -> U) -> U {
+ 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| {
181
// SAFETY: `idx` is in self.alive range
182
unsafe { self.data.get_unchecked(idx).assume_init_read() }
183
});
184
185
- func(tmp.as_ref())
+ let out = func(tmp.as_ref());
186
+ // Avoid dropping before the item is consumed
187
+ crate::mem::forget(tmp);
188
+ out
189
190
191
0 commit comments