From 87941b079ab29a3831c659bf467d7fb87d347c36 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Tue, 29 May 2018 23:30:16 -0600 Subject: [PATCH] Stabilize iterator_repeat_with Fixes #48169 --- src/libcore/iter/mod.rs | 2 +- src/libcore/iter/sources.rs | 26 +++++++------------------- src/libcore/lib.rs | 1 - src/libcore/tests/iter.rs | 12 ------------ src/libcore/tests/lib.rs | 1 - 5 files changed, 8 insertions(+), 34 deletions(-) diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 1e8476d3880..f313f0d9147 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -333,7 +333,7 @@ pub use self::range::Step; #[stable(feature = "rust1", since = "1.0.0")] pub use self::sources::{Repeat, repeat}; -#[unstable(feature = "iterator_repeat_with", issue = "48169")] +#[stable(feature = "iterator_repeat_with", since = "1.28.0")] pub use self::sources::{RepeatWith, repeat_with}; #[stable(feature = "iter_empty", since = "1.2.0")] pub use self::sources::{Empty, empty}; diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index 0fc1a3aa8ac..d500cc99fa1 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -113,12 +113,12 @@ pub fn repeat(elt: T) -> Repeat { /// /// [`repeat_with`]: fn.repeat_with.html #[derive(Copy, Clone, Debug)] -#[unstable(feature = "iterator_repeat_with", issue = "48169")] +#[stable(feature = "iterator_repeat_with", since = "1.28.0")] pub struct RepeatWith { repeater: F } -#[unstable(feature = "iterator_repeat_with", issue = "48169")] +#[stable(feature = "iterator_repeat_with", since = "1.28.0")] impl A> Iterator for RepeatWith { type Item = A; @@ -129,13 +129,7 @@ impl A> Iterator for RepeatWith { fn size_hint(&self) -> (usize, Option) { (usize::MAX, None) } } -#[unstable(feature = "iterator_repeat_with", issue = "48169")] -impl A> DoubleEndedIterator for RepeatWith { - #[inline] - fn next_back(&mut self) -> Option { self.next() } -} - -#[unstable(feature = "iterator_repeat_with", issue = "48169")] +#[stable(feature = "iterator_repeat_with", since = "1.28.0")] impl A> FusedIterator for RepeatWith {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -158,19 +152,15 @@ unsafe impl A> TrustedLen for RepeatWith {} /// /// [`repeat`]: fn.repeat.html /// -/// An iterator produced by `repeat_with()` is a `DoubleEndedIterator`. -/// It is important to note that reversing `repeat_with(f)` will produce -/// the exact same sequence as the non-reversed iterator. In other words, -/// `repeat_with(f).rev().collect::>()` is equivalent to -/// `repeat_with(f).collect::>()`. +/// An iterator produced by `repeat_with()` is not a `DoubleEndedIterator`. +/// If you need `repeat_with()` to return a `DoubleEndedIterator`, +/// please open a GitHub issue explaining your use case. /// /// # Examples /// /// Basic usage: /// /// ``` -/// #![feature(iterator_repeat_with)] -/// /// use std::iter; /// /// // let's assume we have some value of a type that is not `Clone` @@ -191,8 +181,6 @@ unsafe impl A> TrustedLen for RepeatWith {} /// Using mutation and going finite: /// /// ```rust -/// #![feature(iterator_repeat_with)] -/// /// use std::iter; /// /// // From the zeroth to the third power of two: @@ -209,7 +197,7 @@ unsafe impl A> TrustedLen for RepeatWith {} /// assert_eq!(None, pow2.next()); /// ``` #[inline] -#[unstable(feature = "iterator_repeat_with", issue = "48169")] +#[stable(feature = "iterator_repeat_with", since = "1.28.0")] pub fn repeat_with A>(repeater: F) -> RepeatWith { RepeatWith { repeater } } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 32cf31231c3..ce86f469695 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -89,7 +89,6 @@ #![feature(fundamental)] #![feature(intrinsics)] #![feature(iterator_flatten)] -#![feature(iterator_repeat_with)] #![feature(lang_items)] #![feature(link_llvm_intrinsics)] #![feature(never_type)] diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 2abac0cf1d5..9b8d7031f8e 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -1722,18 +1722,6 @@ fn test_repeat_with() { assert_eq!(repeat_with(|| NotClone(42)).size_hint(), (usize::MAX, None)); } -#[test] -fn test_repeat_with_rev() { - let mut curr = 1; - let mut pow2 = repeat_with(|| { let tmp = curr; curr *= 2; tmp }) - .rev().take(4); - assert_eq!(pow2.next(), Some(1)); - assert_eq!(pow2.next(), Some(2)); - assert_eq!(pow2.next(), Some(4)); - assert_eq!(pow2.next(), Some(8)); - assert_eq!(pow2.next(), None); -} - #[test] fn test_repeat_with_take() { let mut it = repeat_with(|| 42).take(3); diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 13189d532ab..b17c240f0eb 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -25,7 +25,6 @@ #![feature(hashmap_internals)] #![feature(iterator_step_by)] #![feature(iterator_flatten)] -#![feature(iterator_repeat_with)] #![feature(pattern)] #![feature(range_is_empty)] #![feature(raw)]