diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-16 11:30:21 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-17 06:23:40 +0530 |
| commit | d264ef2b11683337c24cfb16e0335ab386df02ab (patch) | |
| tree | 7470205f60983dd337b6ebcec633e8bd07725330 | |
| parent | e337a5728a3bedbae542c0c71e1c4185c75be21b (diff) | |
| parent | e7273784c7a80d8099e495015753d70e63e6d432 (diff) | |
Rollup merge of #22313 - japaric:iter, r=aturon
`IntoIterator` now has an extra associated item:
``` rust
trait IntoIterator {
type Item;
type IntoIter: Iterator<Self=Self::Item>;
}
```
This lets you bind the iterator \"`Item`\" directly when writing generic functions:
``` rust
// hypothetical change, not included in this PR
impl Extend<T> for Vec<T> {
// you can now write
fn extend<I>(&mut self, it: I) where I: IntoIterator<Item=T> { .. }
// instead of
fn extend<I: IntoIterator>(&mut self, it: I) where I::IntoIter: Iterator<Item=T> { .. }
}
```
The downside is that now you have to write an extra associated type in your `IntoIterator` implementations:
``` diff
impl<T> IntoIterator for Vec<T> {
+ type Item = T;
type IntoIter = IntoIter<T>;
fn into_iter(self) -> IntoIter<T> { .. }
}
```
Because this breaks all downstream implementations of `IntoIterator`, this is a [breaking-change]
---
r? @aturon
| -rw-r--r-- | src/libcollections/binary_heap.rs | 24 | ||||
| -rw-r--r-- | src/libcollections/bit.rs | 24 | ||||
| -rw-r--r-- | src/libcollections/btree/map.rs | 36 | ||||
| -rw-r--r-- | src/libcollections/btree/set.rs | 24 | ||||
| -rw-r--r-- | src/libcollections/dlist.rs | 36 | ||||
| -rw-r--r-- | src/libcollections/enum_set.rs | 12 | ||||
| -rw-r--r-- | src/libcollections/ring_buf.rs | 36 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 36 | ||||
| -rw-r--r-- | src/libcollections/vec_map.rs | 36 | ||||
| -rw-r--r-- | src/libcore/array.rs | 24 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 25 | ||||
| -rw-r--r-- | src/libcore/slice.rs | 24 | ||||
| -rw-r--r-- | src/librustc/middle/subst.rs | 24 | ||||
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 48 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 32 |
15 files changed, 441 insertions, 0 deletions
diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 66374b639c1..1d994839d99 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -655,6 +655,8 @@ impl<T: Ord> FromIterator<T> for BinaryHeap<T> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<T: Ord> IntoIterator for BinaryHeap<T> { type IntoIter = IntoIter<T>; @@ -663,6 +665,18 @@ impl<T: Ord> IntoIterator for BinaryHeap<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<T: Ord> IntoIterator for BinaryHeap<T> { + type Item = T; + type IntoIter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord { type IntoIter = Iter<'a, T>; @@ -671,6 +685,16 @@ impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<T: Ord> Extend<T> for BinaryHeap<T> { fn extend<Iter: Iterator<Item=T>>(&mut self, iter: Iter) { diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 6d15a264172..ca598a8d4d2 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -1070,6 +1070,8 @@ impl<'a> RandomAccessIterator for Iter<'a> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a> IntoIterator for &'a Bitv { type IntoIter = Iter<'a>; @@ -1078,6 +1080,16 @@ impl<'a> IntoIterator for &'a Bitv { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a> IntoIterator for &'a Bitv { + type Item = bool; + type IntoIter = Iter<'a>; + + fn into_iter(self) -> Iter<'a> { + self.iter() + } +} + /// An implementation of a set using a bit vector as an underlying /// representation for holding unsigned numerical elements. /// @@ -1882,6 +1894,8 @@ impl<'a> Iterator for SymmetricDifference<'a> { #[inline] fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a> IntoIterator for &'a BitvSet { type IntoIter = SetIter<'a>; @@ -1890,6 +1904,16 @@ impl<'a> IntoIterator for &'a BitvSet { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a> IntoIterator for &'a BitvSet { + type Item = usize; + type IntoIter = SetIter<'a>; + + fn into_iter(self) -> SetIter<'a> { + self.iter() + } +} + #[cfg(test)] mod tests { use prelude::*; diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 895fa076ab6..84f9825e989 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -462,6 +462,8 @@ impl<K: Ord, V> BTreeMap<K, V> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<K, V> IntoIterator for BTreeMap<K, V> { type IntoIter = IntoIter<K, V>; @@ -470,6 +472,18 @@ impl<K, V> IntoIterator for BTreeMap<K, V> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<K, V> IntoIterator for BTreeMap<K, V> { + type Item = (K, V); + type IntoIter = IntoIter<K, V>; + + fn into_iter(self) -> IntoIter<K, V> { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> { type IntoIter = Iter<'a, K, V>; @@ -478,6 +492,18 @@ impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> { + type Item = (&'a K, &'a V); + type IntoIter = Iter<'a, K, V>; + + fn into_iter(self) -> Iter<'a, K, V> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> { type IntoIter = IterMut<'a, K, V>; @@ -486,6 +512,16 @@ impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> { + type Item = (&'a K, &'a mut V); + type IntoIter = IterMut<'a, K, V>; + + fn into_iter(mut self) -> IterMut<'a, K, V> { + self.iter_mut() + } +} + /// A helper enum useful for deciding whether to continue a loop since we can't /// return from a closure enum Continuation<A, B> { diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 8628879295b..aecf5940311 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -480,6 +480,8 @@ impl<T: Ord> FromIterator<T> for BTreeSet<T> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<T> IntoIterator for BTreeSet<T> { type IntoIter = IntoIter<T>; @@ -488,6 +490,18 @@ impl<T> IntoIterator for BTreeSet<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<T> IntoIterator for BTreeSet<T> { + type Item = T; + type IntoIter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a BTreeSet<T> { type IntoIter = Iter<'a, T>; @@ -496,6 +510,16 @@ impl<'a, T> IntoIterator for &'a BTreeSet<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a BTreeSet<T> { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<T: Ord> Extend<T> for BTreeSet<T> { #[inline] diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 423646e5acd..27b282ee9a9 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -837,6 +837,8 @@ impl<A> FromIterator<A> for DList<A> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<T> IntoIterator for DList<T> { type IntoIter = IntoIter<T>; @@ -845,7 +847,29 @@ impl<T> IntoIterator for DList<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<T> IntoIterator for DList<T> { + type Item = T; + type IntoIter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a DList<T> { + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a DList<T> { + type Item = &'a T; type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { @@ -853,7 +877,19 @@ impl<'a, T> IntoIterator for &'a DList<T> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a mut DList<T> { + type IntoIter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut DList<T> { + type Item = &'a mut T; type IntoIter = IterMut<'a, T>; fn into_iter(mut self) -> IterMut<'a, T> { diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index da533d34703..5c37be188fe 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -257,6 +257,8 @@ impl<E:CLike> FromIterator<E> for EnumSet<E> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike { type IntoIter = Iter<E>; @@ -265,6 +267,16 @@ impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike { + type Item = E; + type IntoIter = Iter<E>; + + fn into_iter(self) -> Iter<E> { + self.iter() + } +} + impl<E:CLike> Extend<E> for EnumSet<E> { fn extend<I: Iterator<Item=E>>(&mut self, iterator: I) { for element in iterator { diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index ec1e648939a..0a4ccde9236 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1699,6 +1699,8 @@ impl<A> FromIterator<A> for RingBuf<A> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<T> IntoIterator for RingBuf<T> { type IntoIter = IntoIter<T>; @@ -1707,6 +1709,18 @@ impl<T> IntoIterator for RingBuf<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<T> IntoIterator for RingBuf<T> { + type Item = T; + type IntoIter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a RingBuf<T> { type IntoIter = Iter<'a, T>; @@ -1715,6 +1729,18 @@ impl<'a, T> IntoIterator for &'a RingBuf<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a RingBuf<T> { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a mut RingBuf<T> { type IntoIter = IterMut<'a, T>; @@ -1723,6 +1749,16 @@ impl<'a, T> IntoIterator for &'a mut RingBuf<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a mut RingBuf<T> { + type Item = &'a mut T; + type IntoIter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<A> Extend<A> for RingBuf<A> { fn extend<T: Iterator<Item=A>>(&mut self, iterator: T) { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 4fb8f52a57b..6653b960d8d 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1403,6 +1403,8 @@ impl<T> FromIterator<T> for Vec<T> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<T> IntoIterator for Vec<T> { type IntoIter = IntoIter<T>; @@ -1411,6 +1413,18 @@ impl<T> IntoIterator for Vec<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<T> IntoIterator for Vec<T> { + type Item = T; + type IntoIter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a Vec<T> { type IntoIter = slice::Iter<'a, T>; @@ -1419,7 +1433,29 @@ impl<'a, T> IntoIterator for &'a Vec<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a Vec<T> { + type Item = &'a T; + type IntoIter = slice::Iter<'a, T>; + + fn into_iter(self) -> slice::Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a mut Vec<T> { + type IntoIter = slice::IterMut<'a, T>; + + fn into_iter(mut self) -> slice::IterMut<'a, T> { + self.iter_mut() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut Vec<T> { + type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; fn into_iter(mut self) -> slice::IterMut<'a, T> { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index ba358ada0ad..7f9484c58a1 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -668,6 +668,8 @@ impl<V> FromIterator<(usize, V)> for VecMap<V> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<T> IntoIterator for VecMap<T> { type IntoIter = IntoIter<T>; @@ -676,7 +678,29 @@ impl<T> IntoIterator for VecMap<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<T> IntoIterator for VecMap<T> { + type Item = (usize, T); + type IntoIter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a VecMap<T> { + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a VecMap<T> { + type Item = (usize, &'a T); type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { @@ -684,7 +708,19 @@ impl<'a, T> IntoIterator for &'a VecMap<T> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a mut VecMap<T> { + type IntoIter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut VecMap<T> { + type Item = (usize, &'a mut T); type IntoIter = IterMut<'a, T>; fn into_iter(mut self) -> IterMut<'a, T> { diff --git a/src/libcore/array.rs b/src/libcore/array.rs index a596fe4a588..abaa7594d04 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -48,6 +48,8 @@ macro_rules! array_impls { } } + // NOTE(stage0): remove impl after a snapshot + #[cfg(stage0)] impl<'a, T> IntoIterator for &'a [T; $N] { type IntoIter = Iter<'a, T>; @@ -56,7 +58,29 @@ macro_rules! array_impls { } } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + impl<'a, T> IntoIterator for &'a [T; $N] { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } + } + + // NOTE(stage0): remove impl after a snapshot + #[cfg(stage0)] + impl<'a, T> IntoIterator for &'a mut [T; $N] { + type IntoIter = IterMut<'a, T>; + + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } + } + + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut [T; $N] { + type Item = &'a mut T; type IntoIter = IterMut<'a, T>; fn into_iter(self) -> IterMut<'a, T> { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index f4d560cb4c9..03c473ed967 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -118,6 +118,8 @@ pub trait FromIterator<A> { fn from_iter<T: Iterator<Item=A>>(iterator: T) -> Self; } +// NOTE(stage0): remove trait after a snapshot +#[cfg(stage0)] /// Conversion into an `Iterator` pub trait IntoIterator { type IntoIter: Iterator; @@ -127,6 +129,19 @@ pub trait IntoIterator { fn into_iter(self) -> Self::IntoIter; } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +/// Conversion into an `Iterator` +pub trait IntoIterator { + type Item; + type IntoIter: Iterator<Item=Self::Item>; + + /// Consumes `Self` and returns an iterator over it + #[stable(feature = "rust1", since = "1.0.0")] + fn into_iter(self) -> Self::IntoIter; +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<I> IntoIterator for I where I: Iterator { type IntoIter = I; @@ -135,6 +150,16 @@ impl<I> IntoIterator for I where I: Iterator { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<I: Iterator> IntoIterator for I { + type Item = I::Item; + type IntoIter = I; + + fn into_iter(self) -> I { + self + } +} + /// A type growable from an `Iterator` implementation #[stable(feature = "rust1", since = "1.0.0")] pub trait Extend<A> { diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 097633b7063..cd91843f359 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -626,6 +626,8 @@ impl<'a, T> Default for &'a [T] { // Iterators // +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a [T] { type IntoIter = Iter<'a, T>; @@ -634,7 +636,29 @@ impl<'a, T> IntoIterator for &'a [T] { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a [T] { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a mut [T] { + type IntoIter = IterMut<'a, T>; + + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut [T] { + type Item = &'a mut T; type IntoIter = IterMut<'a, T>; fn into_iter(self) -> IterMut<'a, T> { diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index e20968a9ac9..e27e7a80246 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -530,6 +530,8 @@ impl<'a,T> Iterator for EnumeratedItems<'a,T> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<T> IntoIterator for VecPerParamSpace<T> { type IntoIter = IntoIter<T>; @@ -538,7 +540,29 @@ impl<T> IntoIterator for VecPerParamSpace<T> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<T> IntoIterator for VecPerParamSpace<T> { + type Item = T; + type IntoIter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_vec().into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a,T> IntoIterator for &'a VecPerParamSpace<T> { + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.as_slice().into_iter() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a,T> IntoIterator for &'a VecPerParamSpace<T> { + type Item = &'a T; type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 18dd122891d..241e409910f 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1372,6 +1372,8 @@ enum VacantEntryState<K, V, M> { NoElem(EmptyBucket<K, V, M>), } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V, S, H> IntoIterator for &'a HashMap<K, V, S> where K: Eq + Hash<H>, S: HashState<Hasher=H>, @@ -1384,6 +1386,22 @@ impl<'a, K, V, S, H> IntoIterator for &'a HashMap<K, V, S> } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V, S, H> IntoIterator for &'a HashMap<K, V, S> + where K: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type Item = (&'a K, &'a V); + type IntoIter = Iter<'a, K, V>; + + fn into_iter(self) -> Iter<'a, K, V> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap<K, V, S> where K: Eq + Hash<H>, S: HashState<Hasher=H>, @@ -1396,6 +1414,22 @@ impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap<K, V, S> } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap<K, V, S> + where K: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type Item = (&'a K, &'a mut V); + type IntoIter = IterMut<'a, K, V>; + + fn into_iter(mut self) -> IterMut<'a, K, V> { + self.iter_mut() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<K, V, S, H> IntoIterator for HashMap<K, V, S> where K: Eq + Hash<H>, S: HashState<Hasher=H>, @@ -1408,6 +1442,20 @@ impl<K, V, S, H> IntoIterator for HashMap<K, V, S> } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<K, V, S, H> IntoIterator for HashMap<K, V, S> + where K: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type Item = (K, V); + type IntoIter = IntoIter<K, V>; + + fn into_iter(self) -> IntoIter<K, V> { + self.into_iter() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V> Iterator for Iter<'a, K, V> { type Item = (&'a K, &'a V); diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 96af556dbcc..300e2089317 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -835,6 +835,8 @@ pub struct Union<'a, T: 'a, S: 'a> { iter: Chain<Iter<'a, T>, Difference<'a, T, S>> } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T, S, H> IntoIterator for &'a HashSet<T, S> where T: Eq + Hash<H>, S: HashState<Hasher=H>, @@ -847,11 +849,41 @@ impl<'a, T, S, H> IntoIterator for &'a HashSet<T, S> } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T, S, H> IntoIterator for &'a HashSet<T, S> + where T: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<T, S, H> IntoIterator for HashSet<T, S> + where T: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type IntoIter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<T, S, H> IntoIterator for HashSet<T, S> where T: Eq + Hash<H>, S: HashState<Hasher=H>, H: hash::Hasher<Output=u64> { + type Item = T; type IntoIter = IntoIter<T>; fn into_iter(self) -> IntoIter<T> { |
