Skip to content

Commit

Permalink
Rollup merge of rust-lang#49607 - cuviper:stable-iter-1.27, r=alexcri…
Browse files Browse the repository at this point in the history
…chton

Stabilize iterator methods in 1.27

- Closes rust-lang#39480, feature  `iter_rfind`
  - `DoubleEndedIterator::rfind`
- Closes rust-lang#44705, feature `iter_rfold`
  - `DoubleEndedIterator::rfold`
- Closes rust-lang#45594, feature `iterator_try_fold`
  - `Iterator::try_fold`
  - `Iterator::try_for_each`
  - `DoubleEndedIterator::try_rfold`
  • Loading branch information
kennytm authored Apr 4, 2018
2 parents 52fd162 + 9db63bb commit dd2ec6a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
#![feature(fundamental)]
#![feature(generic_param_attrs)]
#![cfg_attr(stage0, feature(i128_type))]
#![feature(iter_rfold)]
#![feature(lang_items)]
#![feature(needs_allocator)]
#![feature(nonzero)]
Expand Down
7 changes: 2 additions & 5 deletions src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,6 @@ pub trait Iterator {
/// Basic usage:
///
/// ```
/// #![feature(iterator_try_fold)]
/// let a = [1, 2, 3];
///
/// // the checked sum of all of the elements of the array
Expand All @@ -1459,7 +1458,6 @@ pub trait Iterator {
/// Short-circuiting:
///
/// ```
/// #![feature(iterator_try_fold)]
/// let a = [10, 20, 30, 100, 40, 50];
/// let mut it = a.iter();
///
Expand All @@ -1473,7 +1471,7 @@ pub trait Iterator {
/// assert_eq!(it.next(), Some(&40));
/// ```
#[inline]
#[unstable(feature = "iterator_try_fold", issue = "45594")]
#[stable(feature = "iterator_try_fold", since = "1.27.0")]
fn try_fold<B, F, R>(&mut self, init: B, mut f: F) -> R where
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
{
Expand All @@ -1496,7 +1494,6 @@ pub trait Iterator {
/// # Examples
///
/// ```
/// #![feature(iterator_try_fold)]
/// use std::fs::rename;
/// use std::io::{stdout, Write};
/// use std::path::Path;
Expand All @@ -1513,7 +1510,7 @@ pub trait Iterator {
/// assert_eq!(it.next(), Some("stale_bread.json"));
/// ```
#[inline]
#[unstable(feature = "iterator_try_fold", issue = "45594")]
#[stable(feature = "iterator_try_fold", since = "1.27.0")]
fn try_for_each<F, R>(&mut self, mut f: F) -> R where
Self: Sized, F: FnMut(Self::Item) -> R, R: Try<Ok=()>
{
Expand Down
16 changes: 4 additions & 12 deletions src/libcore/iter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ pub trait DoubleEndedIterator: Iterator {
/// Basic usage:
///
/// ```
/// #![feature(iterator_try_fold)]
/// let a = ["1", "2", "3"];
/// let sum = a.iter()
/// .map(|&s| s.parse::<i32>())
Expand All @@ -438,7 +437,6 @@ pub trait DoubleEndedIterator: Iterator {
/// Short-circuiting:
///
/// ```
/// #![feature(iterator_try_fold)]
/// let a = ["1", "rust", "3"];
/// let mut it = a.iter();
/// let sum = it
Expand All @@ -452,7 +450,7 @@ pub trait DoubleEndedIterator: Iterator {
/// assert_eq!(it.next_back(), Some(&"1"));
/// ```
#[inline]
#[unstable(feature = "iterator_try_fold", issue = "45594")]
#[stable(feature = "iterator_try_fold", since = "1.27.0")]
fn try_rfold<B, F, R>(&mut self, init: B, mut f: F) -> R where
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
{
Expand Down Expand Up @@ -491,7 +489,6 @@ pub trait DoubleEndedIterator: Iterator {
/// Basic usage:
///
/// ```
/// #![feature(iter_rfold)]
/// let a = [1, 2, 3];
///
/// // the sum of all of the elements of a
Expand All @@ -505,7 +502,6 @@ pub trait DoubleEndedIterator: Iterator {
/// and continuing with each element from the back until the front:
///
/// ```
/// #![feature(iter_rfold)]
/// let numbers = [1, 2, 3, 4, 5];
///
/// let zero = "0".to_string();
Expand All @@ -517,14 +513,14 @@ pub trait DoubleEndedIterator: Iterator {
/// assert_eq!(result, "(1 + (2 + (3 + (4 + (5 + 0)))))");
/// ```
#[inline]
#[unstable(feature = "iter_rfold", issue = "44705")]
#[stable(feature = "iter_rfold", since = "1.27.0")]
fn rfold<B, F>(mut self, accum: B, mut f: F) -> B where
Self: Sized, F: FnMut(B, Self::Item) -> B,
{
self.try_rfold(accum, move |acc, x| AlwaysOk(f(acc, x))).0
}

/// Searches for an element of an iterator from the right that satisfies a predicate.
/// Searches for an element of an iterator from the back that satisfies a predicate.
///
/// `rfind()` takes a closure that returns `true` or `false`. It applies
/// this closure to each element of the iterator, starting at the end, and if any
Expand All @@ -547,8 +543,6 @@ pub trait DoubleEndedIterator: Iterator {
/// Basic usage:
///
/// ```
/// #![feature(iter_rfind)]
///
/// let a = [1, 2, 3];
///
/// assert_eq!(a.iter().rfind(|&&x| x == 2), Some(&2));
Expand All @@ -559,8 +553,6 @@ pub trait DoubleEndedIterator: Iterator {
/// Stopping at the first `true`:
///
/// ```
/// #![feature(iter_rfind)]
///
/// let a = [1, 2, 3];
///
/// let mut iter = a.iter();
Expand All @@ -571,7 +563,7 @@ pub trait DoubleEndedIterator: Iterator {
/// assert_eq!(iter.next_back(), Some(&1));
/// ```
#[inline]
#[unstable(feature = "iter_rfind", issue = "39480")]
#[stable(feature = "iter_rfind", since = "1.27.0")]
fn rfind<P>(&mut self, mut predicate: P) -> Option<Self::Item> where
Self: Sized,
P: FnMut(&Self::Item) -> bool
Expand Down
3 changes: 0 additions & 3 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
#![feature(iterator_step_by)]
#![cfg_attr(stage0, feature(i128_type))]
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
#![feature(iterator_try_fold)]
#![feature(iterator_flatten)]
#![cfg_attr(stage0, feature(conservative_impl_trait))]
#![feature(iter_rfind)]
#![feature(iter_rfold)]
#![feature(iterator_repeat_with)]
#![feature(nonzero)]
#![feature(pattern)]
Expand Down

0 comments on commit dd2ec6a

Please sign in to comment.