From 0e4448409ef61c703b98e4c5b2fd99447308942d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 1 Feb 2015 12:15:36 -0800 Subject: [PATCH] std: Remove extra type params on iter adaptors Now that associated types are fully implemented the iterator adaptors only need type parameters which are associated with actual storage. All other type parameters can either be derived from these (e.g. they are an associated type) or can be bare on the `impl` block itself. This is a breaking change due to the removal of type parameters on these iterator adaptors, but code can fairly easily migrate by just deleting the relevant type parameters for each adaptor. Other behavior should not be affected. Closes #21839 [breaking-change] --- src/libcollections/btree/map.rs | 4 +- src/libcollections/btree/set.rs | 20 +- src/libcollections/vec_map.rs | 8 +- src/libcore/iter.rs | 350 ++++++++---------------- src/libcore/str/mod.rs | 4 +- src/librustc_trans/trans/basic_block.rs | 7 +- src/libstd/collections/hash/map.rs | 18 +- src/libstd/collections/hash/set.rs | 4 +- src/libstd/path/posix.rs | 2 +- src/libstd/path/windows.rs | 4 +- src/libsyntax/parse/mod.rs | 4 +- src/libunicode/u_str.rs | 2 +- 12 files changed, 137 insertions(+), 290 deletions(-) diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index ce5e8f07be1..b007f275980 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -116,13 +116,13 @@ pub struct IntoIter { /// An iterator over a BTreeMap's keys. #[stable(feature = "rust1", since = "1.0.0")] pub struct Keys<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> + inner: Map, fn((&'a K, &'a V)) -> &'a K> } /// An iterator over a BTreeMap's values. #[stable(feature = "rust1", since = "1.0.0")] pub struct Values<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> + inner: Map, fn((&'a K, &'a V)) -> &'a V> } /// An iterator over a sub-range of BTreeMap's entries. diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 72d5bf6d799..1445db12a90 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -45,40 +45,40 @@ pub struct Iter<'a, T: 'a> { /// An owning iterator over a BTreeSet's items. #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { - iter: Map<(T, ()), T, ::btree_map::IntoIter, fn((T, ())) -> T> + iter: Map<::btree_map::IntoIter, fn((T, ())) -> T> } /// An iterator over a sub-range of BTreeSet's items. pub struct Range<'a, T: 'a> { - iter: Map<(&'a T, &'a ()), &'a T, ::btree_map::Range<'a, T, ()>, fn((&'a T, &'a ())) -> &'a T> + iter: Map<::btree_map::Range<'a, T, ()>, fn((&'a T, &'a ())) -> &'a T> } /// A lazy iterator producing elements in the set difference (in-order). #[stable(feature = "rust1", since = "1.0.0")] pub struct Difference<'a, T:'a> { - a: Peekable<&'a T, Iter<'a, T>>, - b: Peekable<&'a T, Iter<'a, T>>, + a: Peekable>, + b: Peekable>, } /// A lazy iterator producing elements in the set symmetric difference (in-order). #[stable(feature = "rust1", since = "1.0.0")] pub struct SymmetricDifference<'a, T:'a> { - a: Peekable<&'a T, Iter<'a, T>>, - b: Peekable<&'a T, Iter<'a, T>>, + a: Peekable>, + b: Peekable>, } /// A lazy iterator producing elements in the set intersection (in-order). #[stable(feature = "rust1", since = "1.0.0")] pub struct Intersection<'a, T:'a> { - a: Peekable<&'a T, Iter<'a, T>>, - b: Peekable<&'a T, Iter<'a, T>>, + a: Peekable>, + b: Peekable>, } /// A lazy iterator producing elements in the set union (in-order). #[stable(feature = "rust1", since = "1.0.0")] pub struct Union<'a, T:'a> { - a: Peekable<&'a T, Iter<'a, T>>, - b: Peekable<&'a T, Iter<'a, T>>, + a: Peekable>, + b: Peekable>, } impl BTreeSet { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index f2a9bb4392c..b677b361300 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -687,7 +687,7 @@ double_ended_iterator! { impl IterMut -> (uint, &'a mut V), as_mut } /// An iterator over the keys of a map. #[stable(feature = "rust1", since = "1.0.0")] pub struct Keys<'a, V: 'a> { - iter: Map<(uint, &'a V), uint, Iter<'a, V>, fn((uint, &'a V)) -> uint> + iter: Map, fn((uint, &'a V)) -> uint> } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` @@ -702,7 +702,7 @@ impl<'a, V> Clone for Keys<'a, V> { /// An iterator over the values of a map. #[stable(feature = "rust1", since = "1.0.0")] pub struct Values<'a, V: 'a> { - iter: Map<(uint, &'a V), &'a V, Iter<'a, V>, fn((uint, &'a V)) -> &'a V> + iter: Map, fn((uint, &'a V)) -> &'a V> } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` @@ -718,8 +718,6 @@ impl<'a, V> Clone for Values<'a, V> { #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { iter: FilterMap< - (uint, Option), - (uint, V), Enumerate>>, fn((uint, Option)) -> Option<(uint, V)>> } @@ -727,8 +725,6 @@ pub struct IntoIter { #[unstable(feature = "collections")] pub struct Drain<'a, V> { iter: FilterMap< - (uint, Option), - (uint, V), Enumerate>>, fn((uint, Option)) -> Option<(uint, V)>> } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 751b5959d8b..84db07266b8 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -239,9 +239,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn zip(self, other: U) -> Zip where - U: Iterator, - { + fn zip(self, other: U) -> Zip { Zip{a: self, b: other} } @@ -259,7 +257,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn map(self, f: F) -> Map where + fn map(self, f: F) -> Map where F: FnMut(Self::Item) -> B, { Map{iter: self, f: f} @@ -279,7 +277,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn filter

(self, predicate: P) -> Filter where + fn filter

(self, predicate: P) -> Filter where P: FnMut(&Self::Item) -> bool, { Filter{iter: self, predicate: predicate} @@ -299,7 +297,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn filter_map(self, f: F) -> FilterMap where + fn filter_map(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option, { FilterMap { iter: self, f: f } @@ -342,7 +340,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn peekable(self) -> Peekable { + fn peekable(self) -> Peekable { Peekable{iter: self, peeked: None} } @@ -362,7 +360,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn skip_while

(self, predicate: P) -> SkipWhile where + fn skip_while

(self, predicate: P) -> SkipWhile where P: FnMut(&Self::Item) -> bool, { SkipWhile{iter: self, flag: false, predicate: predicate} @@ -383,7 +381,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn take_while

(self, predicate: P) -> TakeWhile where + fn take_while

(self, predicate: P) -> TakeWhile where P: FnMut(&Self::Item) -> bool, { TakeWhile{iter: self, flag: false, predicate: predicate} @@ -448,12 +446,8 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn scan( - self, - initial_state: St, - f: F, - ) -> Scan where - F: FnMut(&mut St, Self::Item) -> Option, + fn scan(self, initial_state: St, f: F) -> Scan + where F: FnMut(&mut St, Self::Item) -> Option, { Scan{iter: self, f: f, state: initial_state} } @@ -474,9 +468,8 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn flat_map(self, f: F) -> FlatMap where - U: Iterator, - F: FnMut(Self::Item) -> U, + fn flat_map(self, f: F) -> FlatMap + where U: Iterator, F: FnMut(Self::Item) -> U, { FlatMap{iter: self, f: f, frontiter: None, backiter: None } } @@ -534,7 +527,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn inspect(self, f: F) -> Inspect where + fn inspect(self, f: F) -> Inspect where F: FnMut(&Self::Item), { Inspect{iter: self, f: f} @@ -1077,16 +1070,14 @@ pub trait ExactSizeIterator: Iterator { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Enumerate where I: ExactSizeIterator {} #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for Inspect where - I: ExactSizeIterator, - F: FnMut(&A), +impl ExactSizeIterator for Inspect where + F: FnMut(&I::Item), {} #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Rev where I: ExactSizeIterator + DoubleEndedIterator {} #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for Map where - I: ExactSizeIterator, - F: FnMut(A) -> B, +impl ExactSizeIterator for Map where + F: FnMut(I::Item) -> B, {} #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Zip where A: ExactSizeIterator, B: ExactSizeIterator {} @@ -1561,28 +1552,15 @@ impl RandomAccessIterator for Zip where /// An iterator that maps the values of `iter` with `f` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Map, F: FnMut(A) -> B> { +#[derive(Clone)] +pub struct Map { iter: I, f: F, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Map where - I: Clone + Iterator, - F: Clone + FnMut(A) -> B, -{ - fn clone(&self) -> Map { - Map { - iter: self.iter.clone(), - f: self.f.clone(), - } - } -} - -impl Map where I: Iterator, F: FnMut(A) -> B { +impl Map where F: FnMut(I::Item) -> B { #[inline] - fn do_map(&mut self, elt: Option) -> Option { + fn do_map(&mut self, elt: Option) -> Option { match elt { Some(a) => Some((self.f)(a)), _ => None @@ -1591,7 +1569,7 @@ impl Map where I: Iterator, F: FnMut(A) -> B { } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Map where I: Iterator, F: FnMut(A) -> B { +impl Iterator for Map where F: FnMut(I::Item) -> B { type Item = B; #[inline] @@ -1607,9 +1585,8 @@ impl Iterator for Map where I: Iterator, F: FnMu } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for Map where - I: DoubleEndedIterator, - F: FnMut(A) -> B, +impl DoubleEndedIterator for Map where + F: FnMut(I::Item) -> B, { #[inline] fn next_back(&mut self) -> Option { @@ -1619,9 +1596,8 @@ impl DoubleEndedIterator for Map where } #[unstable(feature = "core", reason = "trait is experimental")] -impl RandomAccessIterator for Map where - I: RandomAccessIterator, - F: FnMut(A) -> B, +impl RandomAccessIterator for Map where + F: FnMut(I::Item) -> B, { #[inline] fn indexable(&self) -> usize { @@ -1638,31 +1614,18 @@ impl RandomAccessIterator for Map where /// An iterator that filters the elements of `iter` with `predicate` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Filter where I: Iterator, P: FnMut(&A) -> bool { +#[derive(Clone)] +pub struct Filter { iter: I, predicate: P, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Filter where - I: Clone + Iterator, - P: Clone + FnMut(&A) -> bool, -{ - fn clone(&self) -> Filter { - Filter { - iter: self.iter.clone(), - predicate: self.predicate.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Filter where I: Iterator, P: FnMut(&A) -> bool { - type Item = A; +impl Iterator for Filter where P: FnMut(&I::Item) -> bool { + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { for x in self.iter.by_ref() { if (self.predicate)(&x) { return Some(x); @@ -1681,12 +1644,11 @@ impl Iterator for Filter where I: Iterator, P: FnMut(& } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for Filter where - I: DoubleEndedIterator, - P: FnMut(&A) -> bool, +impl DoubleEndedIterator for Filter + where P: FnMut(&I::Item) -> bool, { #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option { for x in self.iter.by_ref().rev() { if (self.predicate)(&x) { return Some(x); @@ -1699,29 +1661,15 @@ impl DoubleEndedIterator for Filter where /// An iterator that uses `f` to both filter and map elements from `iter` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct FilterMap where I: Iterator, F: FnMut(A) -> Option { +#[derive(Clone)] +pub struct FilterMap { iter: I, f: F, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for FilterMap where - I: Clone + Iterator, - F: Clone + FnMut(A) -> Option, -{ - fn clone(&self) -> FilterMap { - FilterMap { - iter: self.iter.clone(), - f: self.f.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for FilterMap where - I: Iterator, - F: FnMut(A) -> Option, +impl Iterator for FilterMap + where F: FnMut(I::Item) -> Option, { type Item = B; @@ -1744,9 +1692,8 @@ impl Iterator for FilterMap where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for FilterMap where - I: DoubleEndedIterator, - F: FnMut(A) -> Option, +impl DoubleEndedIterator for FilterMap + where F: FnMut(I::Item) -> Option, { #[inline] fn next_back(&mut self) -> Option { @@ -1824,20 +1771,28 @@ impl RandomAccessIterator for Enumerate where I: RandomAccessIterator { } /// An iterator with a `peek()` that returns an optional reference to the next element. -#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Peekable where I: Iterator { +pub struct Peekable { iter: I, - peeked: Option, + peeked: Option, +} + +impl Clone for Peekable where I::Item: Clone { + fn clone(&self) -> Peekable { + Peekable { + iter: self.iter.clone(), + peeked: self.peeked.clone(), + } + } } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Peekable where I: Iterator { - type Item = T; +impl Iterator for Peekable { + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.peeked.is_some() { self.peeked.take() } else { self.iter.next() } } @@ -1859,14 +1814,14 @@ impl Iterator for Peekable where I: Iterator { } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for Peekable where I: ExactSizeIterator {} +impl ExactSizeIterator for Peekable {} #[stable(feature = "rust1", since = "1.0.0")] -impl Peekable where I: Iterator { - /// Return a reference to the next element of the iterator with out advancing it, - /// or None if the iterator is exhausted. +impl Peekable { + /// Return a reference to the next element of the iterator with out + /// advancing it, or None if the iterator is exhausted. #[inline] - pub fn peek(&mut self) -> Option<&T> { + pub fn peek(&mut self) -> Option<&I::Item> { if self.peeked.is_none() { self.peeked = self.iter.next(); } @@ -1886,33 +1841,21 @@ impl Peekable where I: Iterator { /// An iterator that rejects elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct SkipWhile where I: Iterator, P: FnMut(&A) -> bool { +#[derive(Clone)] +pub struct SkipWhile { iter: I, flag: bool, predicate: P, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for SkipWhile where - I: Clone + Iterator, - P: Clone + FnMut(&A) -> bool, +impl Iterator for SkipWhile + where P: FnMut(&I::Item) -> bool { - fn clone(&self) -> SkipWhile { - SkipWhile { - iter: self.iter.clone(), - flag: self.flag, - predicate: self.predicate.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for SkipWhile where I: Iterator, P: FnMut(&A) -> bool { - type Item = A; + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { for x in self.iter.by_ref() { if self.flag || !(self.predicate)(&x) { self.flag = true; @@ -1932,33 +1875,21 @@ impl Iterator for SkipWhile where I: Iterator, P: FnMu /// An iterator that only accepts elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct TakeWhile where I: Iterator, P: FnMut(&A) -> bool { +#[derive(Clone)] +pub struct TakeWhile { iter: I, flag: bool, predicate: P, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for TakeWhile where - I: Clone + Iterator, - P: Clone + FnMut(&A) -> bool, +impl Iterator for TakeWhile + where P: FnMut(&I::Item) -> bool { - fn clone(&self) -> TakeWhile { - TakeWhile { - iter: self.iter.clone(), - flag: self.flag, - predicate: self.predicate.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for TakeWhile where I: Iterator, P: FnMut(&A) -> bool { - type Item = A; + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.flag { None } else { @@ -2118,7 +2049,8 @@ impl ExactSizeIterator for Take where I: ExactSizeIterator {} /// An iterator to maintain state while iterating another iterator #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Option { +#[derive(Clone)] +pub struct Scan { iter: I, f: F, @@ -2126,26 +2058,9 @@ pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Optio pub state: St, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Scan where - I: Clone + Iterator, - St: Clone, - F: Clone + FnMut(&mut St, A) -> Option, -{ - fn clone(&self) -> Scan { - Scan { - iter: self.iter.clone(), - f: self.f.clone(), - state: self.state.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Scan where - I: Iterator, - F: FnMut(&mut St, A) -> Option, +impl Iterator for Scan where + F: FnMut(&mut St, I::Item) -> Option, { type Item = B; @@ -2166,44 +2081,22 @@ impl Iterator for Scan where /// #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct FlatMap where - I: Iterator, - U: Iterator, - F: FnMut(A) -> U, -{ +#[derive(Clone)] +pub struct FlatMap { iter: I, f: F, frontiter: Option, backiter: Option, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for FlatMap where - I: Clone + Iterator, - U: Clone + Iterator, - F: Clone + FnMut(A) -> U, +impl Iterator for FlatMap + where F: FnMut(I::Item) -> U, { - fn clone(&self) -> FlatMap { - FlatMap { - iter: self.iter.clone(), - f: self.f.clone(), - frontiter: self.frontiter.clone(), - backiter: self.backiter.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for FlatMap where - I: Iterator, - U: Iterator, - F: FnMut(A) -> U, -{ - type Item = B; + type Item = U::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { loop { for inner in self.frontiter.iter_mut() { for x in inner.by_ref() { @@ -2230,13 +2123,12 @@ impl Iterator for FlatMap where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for FlatMap where - I: DoubleEndedIterator, - U: DoubleEndedIterator, - F: FnMut(A) -> U, +impl DoubleEndedIterator + for FlatMap + where F: FnMut(I::Item) -> U { #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option { loop { for inner in self.backiter.iter_mut() { match inner.next_back() { @@ -2340,28 +2232,15 @@ impl Fuse { /// element before yielding it. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Inspect where I: Iterator, F: FnMut(&A) { +#[derive(Clone)] +pub struct Inspect { iter: I, f: F, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Inspect where - I: Clone + Iterator, - F: Clone + FnMut(&A), -{ - fn clone(&self) -> Inspect { - Inspect { - iter: self.iter.clone(), - f: self.f.clone(), - } - } -} - -impl Inspect where I: Iterator, F: FnMut(&A) { +impl Inspect where F: FnMut(&I::Item) { #[inline] - fn do_inspect(&mut self, elt: Option) -> Option { + fn do_inspect(&mut self, elt: Option) -> Option { match elt { Some(ref a) => (self.f)(a), None => () @@ -2372,11 +2251,11 @@ impl Inspect where I: Iterator, F: FnMut(&A) { } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Inspect where I: Iterator, F: FnMut(&A) { - type Item = A; +impl Iterator for Inspect where F: FnMut(&I::Item) { + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { let next = self.iter.next(); self.do_inspect(next) } @@ -2388,21 +2267,19 @@ impl Iterator for Inspect where I: Iterator, F: FnMut( } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for Inspect where - I: DoubleEndedIterator, - F: FnMut(&A), +impl DoubleEndedIterator for Inspect + where F: FnMut(&I::Item), { #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option { let next = self.iter.next_back(); self.do_inspect(next) } } #[unstable(feature = "core", reason = "trait is experimental")] -impl RandomAccessIterator for Inspect where - I: RandomAccessIterator, - F: FnMut(&A), +impl RandomAccessIterator for Inspect + where F: FnMut(&I::Item), { #[inline] fn indexable(&self) -> usize { @@ -2410,7 +2287,7 @@ impl RandomAccessIterator for Inspect where } #[inline] - fn idx(&mut self, index: usize) -> Option { + fn idx(&mut self, index: usize) -> Option { let element = self.iter.idx(index); self.do_inspect(element) } @@ -2426,9 +2303,11 @@ impl RandomAccessIterator for Inspect where /// use std::iter::Unfold; /// use std::num::Int; // For `.checked_add()` /// -/// // This iterator will yield up to the last Fibonacci number before the max value of `u32`. -/// // You can simply change `u32` to `u64` in this line if you want higher values than that. -/// let mut fibonacci = Unfold::new((Some(0u32), Some(1u32)), |&mut (ref mut x2, ref mut x1)| { +/// // This iterator will yield up to the last Fibonacci number before the max +/// // value of `u32`. You can simply change `u32` to `u64` in this line if +/// // you want higher values than that. +/// let mut fibonacci = Unfold::new((Some(0u32), Some(1u32)), +/// |&mut (ref mut x2, ref mut x1)| { /// // Attempt to get the next Fibonacci number /// // `x1` will be `None` if previously overflowed. /// let next = match (*x2, *x1) { @@ -2449,32 +2328,19 @@ impl RandomAccessIterator for Inspect where /// } /// ``` #[unstable(feature = "core")] -pub struct Unfold where F: FnMut(&mut St) -> Option { +#[derive(Clone)] +pub struct Unfold { f: F, /// Internal state that will be passed to the closure on the next iteration pub state: St, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Unfold where - F: Clone + FnMut(&mut St) -> Option, - St: Clone, -{ - fn clone(&self) -> Unfold { - Unfold { - f: self.f.clone(), - state: self.state.clone(), - } - } -} - #[unstable(feature = "core")] -impl Unfold where F: FnMut(&mut St) -> Option { +impl Unfold where F: FnMut(&mut St) -> Option { /// Creates a new iterator with the specified closure as the "iterator /// function" and an initial state to eventually pass to the closure #[inline] - pub fn new(initial_state: St, f: F) -> Unfold { + pub fn new(initial_state: St, f: F) -> Unfold { Unfold { f: f, state: initial_state @@ -2483,7 +2349,7 @@ impl Unfold where F: FnMut(&mut St) -> Option { } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Unfold where F: FnMut(&mut St) -> Option { +impl Iterator for Unfold where F: FnMut(&mut St) -> Option { type Item = A; #[inline] @@ -2921,7 +2787,7 @@ type IterateState = (F, Option, bool); /// An iterator that repeatedly applies a given function, starting /// from a given seed value. #[unstable(feature = "core")] -pub type Iterate = Unfold, fn(&mut IterateState) -> Option>; +pub type Iterate = Unfold, fn(&mut IterateState) -> Option>; /// Create a new iterator that produces an infinite sequence of /// repeated applications of the given function `f`. diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index cb7af3b3d35..85b4a202644 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -478,7 +478,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> { /// Created with `StrExt::bytes` #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone)] -pub struct Bytes<'a>(Map<&'a u8, u8, slice::Iter<'a, u8>, BytesDeref>); +pub struct Bytes<'a>(Map, BytesDeref>); delegate_iter!{exact u8 : Bytes<'a>} /// A temporary fn new type that ensures that the `Bytes` iterator @@ -526,7 +526,7 @@ pub struct Lines<'a> { /// An iterator over the lines of a string, separated by either `\n` or (`\r\n`). #[stable(feature = "rust1", since = "1.0.0")] pub struct LinesAny<'a> { - inner: Map<&'a str, &'a str, Lines<'a>, fn(&str) -> &str>, + inner: Map, fn(&str) -> &str>, } impl<'a, Sep> CharSplits<'a, Sep> { diff --git a/src/librustc_trans/trans/basic_block.rs b/src/librustc_trans/trans/basic_block.rs index d3ff432b5e4..f11c3154274 100644 --- a/src/librustc_trans/trans/basic_block.rs +++ b/src/librustc_trans/trans/basic_block.rs @@ -16,12 +16,7 @@ use std::iter::{Filter, Map}; #[derive(Copy)] pub struct BasicBlock(pub BasicBlockRef); -pub type Preds = Map< - Value, - BasicBlock, - Filter bool>, - fn(Value) -> BasicBlock, ->; +pub type Preds = Map bool>, fn(Value) -> BasicBlock>; /// Wrapper for LLVM BasicBlockRef impl BasicBlock { diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 3e2c7627dbe..852d5a86fc0 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1300,18 +1300,13 @@ pub struct IterMut<'a, K: 'a, V: 'a> { /// HashMap move iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { - inner: iter::Map< - (SafeHash, K, V), - (K, V), - table::IntoIter, - fn((SafeHash, K, V)) -> (K, V), - > + inner: iter::Map, fn((SafeHash, K, V)) -> (K, V)> } /// HashMap keys iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct Keys<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> + inner: Map, fn((&'a K, &'a V)) -> &'a K> } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` @@ -1326,7 +1321,7 @@ impl<'a, K, V> Clone for Keys<'a, K, V> { /// HashMap values iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct Values<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> + inner: Map, fn((&'a K, &'a V)) -> &'a V> } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` @@ -1342,12 +1337,7 @@ impl<'a, K, V> Clone for Values<'a, K, V> { #[unstable(feature = "std_misc", reason = "matches collection reform specification, waiting for dust to settle")] pub struct Drain<'a, K: 'a, V: 'a> { - inner: iter::Map< - (SafeHash, K, V), - (K, V), - table::Drain<'a, K, V>, - fn((SafeHash, K, V)) -> (K, V), - > + inner: iter::Map, fn((SafeHash, K, V)) -> (K, V)> } /// A view into a single occupied location in a HashMap. diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index c6dcb0d230f..e6b06e5ef1f 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -794,13 +794,13 @@ pub struct Iter<'a, K: 'a> { /// HashSet move iterator #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { - iter: Map<(K, ()), K, map::IntoIter, fn((K, ())) -> K> + iter: Map, fn((K, ())) -> K> } /// HashSet drain iterator #[stable(feature = "rust1", since = "1.0.0")] pub struct Drain<'a, K: 'a> { - iter: Map<(K, ()), K, map::Drain<'a, K, ()>, fn((K, ())) -> K>, + iter: Map, fn((K, ())) -> K>, } /// Intersection iterator diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 6a0c8a93010..69f815e3f8b 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -31,7 +31,7 @@ pub type Components<'a> = Split<'a, u8, fn(&u8) -> bool>; /// Iterator that yields successive components of a Path as Option<&str> pub type StrComponents<'a> = - Map<&'a [u8], Option<&'a str>, Components<'a>, fn(&[u8]) -> Option<&str>>; + Map, fn(&[u8]) -> Option<&str>>; /// Represents a POSIX file path #[derive(Clone)] diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index b524b89ef9f..750af47ff8c 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -40,11 +40,11 @@ use super::{contains_nul, BytesContainer, GenericPath, GenericPathUnsafe}; /// Each component is yielded as Option<&str> for compatibility with PosixPath, but /// every component in WindowsPath is guaranteed to be Some. pub type StrComponents<'a> = - Map<&'a str, Option<&'a str>, SplitTerminator<'a, char>, fn(&'a str) -> Option<&'a str>>; + Map, fn(&'a str) -> Option<&'a str>>; /// Iterator that yields successive components of a Path as &[u8] pub type Components<'a> = - Map, &'a [u8], StrComponents<'a>, fn(Option<&str>) -> &[u8]>; + Map, fn(Option<&str>) -> &[u8]>; /// Represents a Windows path // Notes for Windows path impl: diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 8ac5b6e5274..3e8eab39d88 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -436,7 +436,7 @@ pub fn str_lit(lit: &str) -> String { let error = |&: i| format!("lexer should have rejected {} at {}", lit, i); /// Eat everything up to a non-whitespace - fn eat<'a>(it: &mut iter::Peekable<(usize, char), str::CharIndices<'a>>) { + fn eat<'a>(it: &mut iter::Peekable>) { loop { match it.peek().map(|x| x.1) { Some(' ') | Some('\n') | Some('\r') | Some('\t') => { @@ -605,7 +605,7 @@ pub fn binary_lit(lit: &str) -> Rc> { let error = |&: i| format!("lexer should have rejected {} at {}", lit, i); /// Eat everything up to a non-whitespace - fn eat<'a, I: Iterator>(it: &mut iter::Peekable<(usize, u8), I>) { + fn eat<'a, I: Iterator>(it: &mut iter::Peekable) { loop { match it.peek().map(|x| x.1) { Some(b' ') | Some(b'\n') | Some(b'\r') | Some(b'\t') => { diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 9a757c0c980..0e3aacbc09a 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -32,7 +32,7 @@ use tables::grapheme::GraphemeCat; /// An iterator over the words of a string, separated by a sequence of whitespace #[stable(feature = "rust1", since = "1.0.0")] pub struct Words<'a> { - inner: Filter<&'a str, Split<'a, fn(char) -> bool>, fn(&&str) -> bool>, + inner: Filter bool>, fn(&&str) -> bool>, } /// Methods for Unicode string slices