Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated Range::step_by (use Iterator::step_by instead) #42110

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/doc/unstable-book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
- [sort_internals](library-features/sort-internals.md)
- [sort_unstable](library-features/sort-unstable.md)
- [splice](library-features/splice.md)
- [step_by](library-features/step-by.md)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm... The iterator_step_by entry is missing from this list. Do you mind adding it, please? 😃

- [step_trait](library-features/step-trait.md)
- [str_checked_slicing](library-features/str-checked-slicing.md)
- [str_escape](library-features/str-escape.md)
Expand Down
7 changes: 0 additions & 7 deletions src/doc/unstable-book/src/library-features/step-by.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/libcollections/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![feature(placement_in_syntax)]
#![feature(rand)]
#![feature(splice)]
#![feature(step_by)]
#![feature(iterator_step_by)]
#![feature(str_escape)]
#![feature(test)]
#![feature(unboxed_closures)]
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ pub trait Iterator {
///
/// ```
/// // an infinite iterator has no upper bound
/// // and the maximum possible lower bound
/// let iter = 0..;
///
/// assert_eq!((0, None), iter.size_hint());
/// assert_eq!((usize::max_value(), None), iter.size_hint());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
16 changes: 13 additions & 3 deletions src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ pub use self::iterator::Iterator;
reason = "likely to be replaced by finer-grained traits",
issue = "27741")]
pub use self::range::Step;
#[unstable(feature = "step_by", reason = "recent addition",
issue = "27741")]
pub use self::range::StepBy as DeprecatedStepBy;

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::sources::{Repeat, repeat};
Expand Down Expand Up @@ -553,6 +550,19 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
self.iter.nth(self.step)
}
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let inner_hint = self.iter.size_hint();

if self.first_take {
let f = |n| if n == 0 { 0 } else { 1 + (n-1)/(self.step+1) };
(f(inner_hint.0), inner_hint.1.map(f))
} else {
let f = |n| n / (self.step+1);
(f(inner_hint.0), inner_hint.1.map(f))
}
}
}

/// An iterator that strings two iterators together.
Expand Down
Loading