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

Improve bounds in Iterator API #24217

Merged
merged 1 commit into from
Apr 9, 2015
Merged

Conversation

aturon
Copy link
Member

@aturon aturon commented 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 #23587

The bound-tightening is technically a:

[breaking-change]

but no code should break in practice.

r? @alexcrichton
cc @Kimundi

@alexcrichton
Copy link
Member

@bors: r+ ac6517f

I'm super stoked for this!

@@ -207,8 +207,10 @@ pub trait Iterator {
/// both produce the same output.
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn zip<U: Iterator>(self, other: U) -> Zip<Self, U> where Self: Sized {
Zip{a: self, b: other}
fn zip<U: Iterator>(self, other: U) -> Zip<Self, U::IntoIter> where
Copy link
Contributor

Choose a reason for hiding this comment

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

is the Iterator bound on U still necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, will fix.

@Kimundi
Copy link
Member

Kimundi commented Apr 9, 2015

Looks good at first glance

Manishearth added a commit to Manishearth/rust that referenced this pull request 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
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.
@alexcrichton
Copy link
Member

@bors: r+ e3f324c

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 9, 2015
@bors bors merged commit e3f324c into rust-lang:master Apr 9, 2015
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 this pull request may close these issues.

IteratorExt::rev should be bounded by DoubleEndedIterator
5 participants