Skip to content

Range iteration specialization: remove trivial bounds #124380

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

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
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
20 changes: 7 additions & 13 deletions library/core/src/iter/adapters/step_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,7 @@ macro_rules! spec_int_ranges_r {
unsafe impl StepByBackImpl<Range<$t>> for StepBy<Range<$t>> {

#[inline]
fn spec_next_back(&mut self) -> Option<Self::Item>
where Range<$t>: DoubleEndedIterator + ExactSizeIterator,
{
fn spec_next_back(&mut self) -> Option<Self::Item> {
Copy link
Member

@compiler-errors compiler-errors Apr 25, 2024

Choose a reason for hiding this comment

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

Forgetting a bound here is sound because we already validate for method compatibility in compare_method_predicate_entailment.

But in this case the bound is not forgotten -- it's just trivial.

let step = self.original_step().get() as $t;
let remaining = self.iter.end;
if remaining > 0 {
Expand All @@ -533,9 +531,7 @@ macro_rules! spec_int_ranges_r {
// We have to repeat them here so that the specialization overrides the StepByImplBack defaults

#[inline]
fn spec_nth_back(&mut self, n: usize) -> Option<Self::Item>
where Self: DoubleEndedIterator,
{
fn spec_nth_back(&mut self, n: usize) -> Option<Self::Item> {
if self.advance_back_by(n).is_err() {
return None;
}
Expand All @@ -544,10 +540,9 @@ macro_rules! spec_int_ranges_r {

#[inline]
fn spec_try_rfold<Acc, F, R>(&mut self, init: Acc, mut f: F) -> R
where
Self: DoubleEndedIterator,
F: FnMut(Acc, Self::Item) -> R,
R: Try<Output = Acc>
where
F: FnMut(Acc, Self::Item) -> R,
R: Try<Output = Acc>
{
let mut accum = init;
while let Some(x) = self.next_back() {
Expand All @@ -558,9 +553,8 @@ macro_rules! spec_int_ranges_r {

#[inline]
fn spec_rfold<Acc, F>(mut self, init: Acc, mut f: F) -> Acc
where
Self: DoubleEndedIterator,
F: FnMut(Acc, Self::Item) -> Acc
where
F: FnMut(Acc, Self::Item) -> Acc
{
let mut accum = init;
while let Some(x) = self.next_back() {
Expand Down
Loading