Skip to content

Commit a2ce876

Browse files
committed
fix peek_with in macros
1 parent 2fa7343 commit a2ce876

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
180180
func(self.alive.clone().next().map(|idx| {
181181
// SAFETY: `idx` is in self.alive range
182182
unsafe { self.data.get_unchecked(idx).assume_init_ref() }
183-
}));
183+
}))
184184
}
185185

186186
#[inline]

library/core/src/slice/iter/macros.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ macro_rules! iterator {
471471
#[unstable(feature = "peekable_iterator", issue = "132973")]
472472
impl<'a, T> PeekableIterator for $name<'a, T> {
473473
fn peek_with<U>(&mut self, func: impl for<'b> FnOnce(Option<&'b Self::Item>) -> U) -> U {
474-
let ptr = self.ptr;
475474
let end_or_len = self.end_or_len;
476475

477476
// SAFETY: See inner comments.
@@ -482,14 +481,13 @@ macro_rules! iterator {
482481
return func(None);
483482
}
484483
} else {
485-
if ptr.as_ptr() == end_or_len {
484+
if self.ptr == crate::intrinsics::transmute::<$ptr, NonNull<T>>(end_or_len) {
486485
return func(None);
487486
}
488487
}
489488
// SAFETY: Now that we know it wasn't empty
490489
// we can give out a reference to it.
491-
let tmp = ptr.$into_ref();
492-
func(Some(&tmp))
490+
func(Some(self.ptr.$into_ref()).as_ref())
493491
}
494492
}
495493
}

0 commit comments

Comments
 (0)