Skip to content

Commit

Permalink
Rollup merge of rust-lang#51511 - Centril:feature/stabilize_iterator_…
Browse files Browse the repository at this point in the history
…flatten, r=SimonSapin

Stabilize Iterator::flatten in 1.29, fixes rust-lang#48213.

This PR stabilizes [`Iterator::flatten`](https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#method.flatten) in *version 1.29* (1.28 goes to beta in 10 days, I don't think there's enough time to land it in that time, but let's see...).

Tracking issue is:  rust-lang#48213.

cc @bluss re. itertools.
r? @SimonSapin
ping @pietroalbini -- let's do a crater run when this passes CI :)
  • Loading branch information
kennytm committed Jun 30, 2018
2 parents 96b4733 + 85796dd commit 2bccea4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
8 changes: 1 addition & 7 deletions src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,6 @@ pub trait Iterator {
/// Basic usage:
///
/// ```
/// #![feature(iterator_flatten)]
///
/// let data = vec![vec![1, 2, 3, 4], vec![5, 6]];
/// let flattened = data.into_iter().flatten().collect::<Vec<u8>>();
/// assert_eq!(flattened, &[1, 2, 3, 4, 5, 6]);
Expand All @@ -1046,8 +1044,6 @@ pub trait Iterator {
/// Mapping and then flattening:
///
/// ```
/// #![feature(iterator_flatten)]
///
/// let words = ["alpha", "beta", "gamma"];
///
/// // chars() returns an iterator
Expand All @@ -1074,8 +1070,6 @@ pub trait Iterator {
/// Flattening once only removes one level of nesting:
///
/// ```
/// #![feature(iterator_flatten)]
///
/// let d3 = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
///
/// let d2 = d3.iter().flatten().collect::<Vec<_>>();
Expand All @@ -1093,7 +1087,7 @@ pub trait Iterator {
///
/// [`flat_map()`]: #method.flat_map
#[inline]
#[unstable(feature = "iterator_flatten", issue = "48213")]
#[stable(feature = "iterator_flatten", since = "1.29")]
fn flatten(self) -> Flatten<Self>
where Self: Sized, Self::Item: IntoIterator {
Flatten { inner: flatten_compat(self) }
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2575,13 +2575,13 @@ impl<I, U, F> FusedIterator for FlatMap<I, U, F>
/// [`flatten`]: trait.Iterator.html#method.flatten
/// [`Iterator`]: trait.Iterator.html
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
#[unstable(feature = "iterator_flatten", issue = "48213")]
#[stable(feature = "iterator_flatten", since = "1.29")]
pub struct Flatten<I: Iterator>
where I::Item: IntoIterator {
inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>,
}

#[unstable(feature = "iterator_flatten", issue = "48213")]
#[stable(feature = "iterator_flatten", since = "1.29")]
impl<I, U> fmt::Debug for Flatten<I>
where I: Iterator + fmt::Debug, U: Iterator + fmt::Debug,
I::Item: IntoIterator<IntoIter = U, Item = U::Item>,
Expand All @@ -2591,15 +2591,15 @@ impl<I, U> fmt::Debug for Flatten<I>
}
}

#[unstable(feature = "iterator_flatten", issue = "48213")]
#[stable(feature = "iterator_flatten", since = "1.29")]
impl<I, U> Clone for Flatten<I>
where I: Iterator + Clone, U: Iterator + Clone,
I::Item: IntoIterator<IntoIter = U, Item = U::Item>,
{
fn clone(&self) -> Self { Flatten { inner: self.inner.clone() } }
}

#[unstable(feature = "iterator_flatten", issue = "48213")]
#[stable(feature = "iterator_flatten", since = "1.29")]
impl<I, U> Iterator for Flatten<I>
where I: Iterator, U: Iterator,
I::Item: IntoIterator<IntoIter = U, Item = U::Item>
Expand Down Expand Up @@ -2627,7 +2627,7 @@ impl<I, U> Iterator for Flatten<I>
}
}

#[unstable(feature = "iterator_flatten", issue = "48213")]
#[stable(feature = "iterator_flatten", since = "1.29")]
impl<I, U> DoubleEndedIterator for Flatten<I>
where I: DoubleEndedIterator, U: DoubleEndedIterator,
I::Item: IntoIterator<IntoIter = U, Item = U::Item>
Expand All @@ -2650,7 +2650,7 @@ impl<I, U> DoubleEndedIterator for Flatten<I>
}
}

#[unstable(feature = "iterator_flatten", issue = "48213")]
#[stable(feature = "iterator_flatten", since = "1.29")]
impl<I, U> FusedIterator for Flatten<I>
where I: FusedIterator, U: Iterator,
I::Item: IntoIterator<IntoIter = U, Item = U::Item> {}
Expand Down
1 change: 0 additions & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
#![feature(extern_types)]
#![feature(fundamental)]
#![feature(intrinsics)]
#![feature(iterator_flatten)]
#![feature(lang_items)]
#![feature(link_llvm_intrinsics)]
#![feature(never_type)]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#![feature(flt2dec)]
#![feature(fmt_internals)]
#![feature(hashmap_internals)]
#![feature(iterator_flatten)]
#![feature(pattern)]
#![feature(range_is_empty)]
#![feature(raw)]
Expand Down

0 comments on commit 2bccea4

Please sign in to comment.