Skip to content
4 changes: 2 additions & 2 deletions library/core/src/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ macro_rules! step_identical_methods {
// In debug builds, trigger a panic on overflow.
// This should optimize completely out in release builds.
if Self::forward_checked(start, n).is_none() {
let _ = Add::add(Self::MAX, 1);
let _ = Add::add(usize::MAX, n);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣 nice trick

}
// Do wrapping math to allow e.g. `Step::forward(-128i8, 255)`.
start.wrapping_add(n as Self)
Expand All @@ -215,7 +215,7 @@ macro_rules! step_identical_methods {
// In debug builds, trigger a panic on overflow.
// This should optimize completely out in release builds.
if Self::backward_checked(start, n).is_none() {
let _ = Sub::sub(Self::MIN, 1);
let _ = Sub::sub(usize::MIN, n);
}
// Do wrapping math to allow e.g. `Step::backward(127i8, 255)`.
start.wrapping_sub(n as Self)
Expand Down
6 changes: 6 additions & 0 deletions library/core/src/iter/sources/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,28 @@ impl<T> fmt::Debug for Empty<T> {
impl<T> Iterator for Empty<T> {
type Item = T;

#[inline]
fn next(&mut self) -> Option<T> {
None
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}

#[stable(feature = "iter_empty", since = "1.2.0")]
impl<T> DoubleEndedIterator for Empty<T> {
#[inline]
fn next_back(&mut self) -> Option<T> {
None
}
}

#[stable(feature = "iter_empty", since = "1.2.0")]
impl<T> ExactSizeIterator for Empty<T> {
#[inline]
fn len(&self) -> usize {
0
}
Expand All @@ -77,6 +81,7 @@ impl<T> FusedIterator for Empty<T> {}
// which isn't necessary.
#[stable(feature = "iter_empty", since = "1.2.0")]
impl<T> Clone for Empty<T> {
#[inline]
fn clone(&self) -> Empty<T> {
Empty(marker::PhantomData)
}
Expand All @@ -86,6 +91,7 @@ impl<T> Clone for Empty<T> {
// which isn't necessary.
#[stable(feature = "iter_empty", since = "1.2.0")]
impl<T> Default for Empty<T> {
#[inline]
fn default() -> Empty<T> {
Empty(marker::PhantomData)
}
Expand Down