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

IteratorExt::rev should be bounded by DoubleEndedIterator #23587

Closed
crumblingstatue opened this issue Mar 21, 2015 · 4 comments · Fixed by #24217
Closed

IteratorExt::rev should be bounded by DoubleEndedIterator #23587

crumblingstatue opened this issue Mar 21, 2015 · 4 comments · Fixed by #24217

Comments

@crumblingstatue
Copy link
Contributor

fn main() {
    (0..10).step_by(2).rev().next();
}

produces the following error:

error: type `core::iter::Rev<core::iter::StepBy<_, core::ops::Range<_>>>` does not implement any method in scope named `next`

According to @eddyb, IteratorExt::rev should be bounded by DoubleEndedIterator to prevent this.

EDIT: Updated the example to show the correct error.

@eddyb
Copy link
Member

eddyb commented Mar 21, 2015

That's not the problematic error, this is:

error: type `core::iter::Rev<core::iter::StepBy<_, core::ops::Range<_>>>` does not implement any method in scope named `next`
(0..10).step_by(2).rev().next();
                         ^~~~~~

@steveklabnik
Copy link
Member

This is basically the same as #23588

@crumblingstatue
Copy link
Contributor Author

This is basically the same as #23588

They are two different issues. Bounding IteratorExt::rev by DoubleEndedIterator won't make using rev() on the result of step_by() possible.

@steveklabnik
Copy link
Member

Yeah, just noting the link :)

aturon added a commit to aturon/rust that referenced this issue Apr 9, 2015
This commit changes `Iterator`'s API by:

* Generalizing bounds from `Iterator` to `IntoIterator` whenever
  possible, matching the semantics and ergonomics of `for` loops.

* Tightens up a few method-level bounds so that you get an error
  earlier. For example, `rev` did not require `DoubleEndedIterator` even
  though the result is only an `Iterator` when the original iterator was
  double-ended.

Closes rust-lang#23587

The bound-tightening is technically a:

[breaking-change]

but no code should break in practice.
Manishearth added a commit to Manishearth/rust that referenced this issue Apr 9, 2015
 This commit changes `Iterator`'s API by:

* Generalizing bounds from `Iterator` to `IntoIterator` whenever
  possible, matching the semantics and ergonomics of `for` loops.

* Tightens up a few method-level bounds so that you get an error
  earlier. For example, `rev` did not require `DoubleEndedIterator` even
  though the result is only an `Iterator` when the original iterator was
  double-ended.

Closes rust-lang#23587

The bound-tightening is technically a:

[breaking-change]

but no code should break in practice.

r? @alexcrichton
cc @Kimundi
aturon added a commit to aturon/rust that referenced this issue Apr 9, 2015
This commit changes `Iterator`'s API by:

* Generalizing bounds from `Iterator` to `IntoIterator` whenever
  possible, matching the semantics and ergonomics of `for` loops.

* Tightens up a few method-level bounds so that you get an error
  earlier. For example, `rev` did not require `DoubleEndedIterator` even
  though the result is only an `Iterator` when the original iterator was
  double-ended.

Closes rust-lang#23587

The bound-tightening is technically a:

[breaking-change]

but no code should break in practice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants