diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index f748c8ad1eb2a..da461ae2d4d53 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -573,7 +573,9 @@ impl<'a, T> Clone for Iter<'a, T> { } #[stable] -impl<'a, T> Iterator<&'a T> for Iter<'a, T> { +impl<'a, T> Iterator for Iter<'a, T> { + type Item = &'a T; + #[inline] fn next(&mut self) -> Option<&'a T> { self.iter.next() } @@ -582,13 +584,13 @@ impl<'a, T> Iterator<&'a T> for Iter<'a, T> { } #[stable] -impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { +impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() } } #[stable] -impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} +impl<'a, T> ExactSizeIterator for Iter<'a, T> {} /// An iterator that moves out of a `BinaryHeap`. pub struct IntoIter { @@ -596,7 +598,9 @@ pub struct IntoIter { } #[stable] -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = T; + #[inline] fn next(&mut self) -> Option { self.iter.next() } @@ -605,13 +609,13 @@ impl Iterator for IntoIter { } #[stable] -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back() } } #[stable] -impl ExactSizeIterator for IntoIter {} +impl ExactSizeIterator for IntoIter {} /// An iterator that drains a `BinaryHeap`. pub struct Drain<'a, T: 'a> { @@ -619,7 +623,9 @@ pub struct Drain<'a, T: 'a> { } #[stable] -impl<'a, T: 'a> Iterator for Drain<'a, T> { +impl<'a, T: 'a> Iterator for Drain<'a, T> { + type Item = T; + #[inline] fn next(&mut self) -> Option { self.iter.next() } @@ -628,24 +634,24 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> { } #[stable] -impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { +impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back() } } #[stable] -impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {} +impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {} #[stable] impl FromIterator for BinaryHeap { - fn from_iter>(iter: Iter) -> BinaryHeap { + fn from_iter>(iter: Iter) -> BinaryHeap { BinaryHeap::from_vec(iter.collect()) } } #[stable] impl Extend for BinaryHeap { - fn extend>(&mut self, mut iter: Iter) { + fn extend>(&mut self, mut iter: Iter) { let (lower, _) = iter.size_hint(); self.reserve(lower); diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index a5b8c5f3e5718..9674885c857c4 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -164,6 +164,8 @@ pub struct Bitv { nbits: uint } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] // FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing) impl Index for Bitv { #[inline] @@ -176,6 +178,21 @@ impl Index for Bitv { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +// FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing) +impl Index for Bitv { + type Output = bool; + + #[inline] + fn index(&self, i: &uint) -> &bool { + if self.get(*i).expect("index out of bounds") { + &TRUE + } else { + &FALSE + } + } +} + /// Computes how many blocks are needed to store that many bits fn blocks_for_bits(bits: uint) -> uint { // If we want 17 bits, dividing by 32 will produce 0. So we add 1 to make sure we @@ -938,7 +955,7 @@ impl Default for Bitv { #[stable] impl FromIterator for Bitv { - fn from_iter>(iterator: I) -> Bitv { + fn from_iter>(iterator: I) -> Bitv { let mut ret = Bitv::new(); ret.extend(iterator); ret @@ -948,7 +965,7 @@ impl FromIterator for Bitv { #[stable] impl Extend for Bitv { #[inline] - fn extend>(&mut self, mut iterator: I) { + fn extend>(&mut self, mut iterator: I) { let (min, _) = iterator.size_hint(); self.reserve(min); for element in iterator { @@ -1031,7 +1048,9 @@ pub struct Iter<'a> { } #[stable] -impl<'a> Iterator for Iter<'a> { +impl<'a> Iterator for Iter<'a> { + type Item = bool; + #[inline] fn next(&mut self) -> Option { if self.next_idx != self.end_idx { @@ -1050,7 +1069,7 @@ impl<'a> Iterator for Iter<'a> { } #[stable] -impl<'a> DoubleEndedIterator for Iter<'a> { +impl<'a> DoubleEndedIterator for Iter<'a> { #[inline] fn next_back(&mut self) -> Option { if self.next_idx != self.end_idx { @@ -1063,10 +1082,10 @@ impl<'a> DoubleEndedIterator for Iter<'a> { } #[stable] -impl<'a> ExactSizeIterator for Iter<'a> {} +impl<'a> ExactSizeIterator for Iter<'a> {} #[stable] -impl<'a> RandomAccessIterator for Iter<'a> { +impl<'a> RandomAccessIterator for Iter<'a> { #[inline] fn indexable(&self) -> uint { self.end_idx - self.next_idx @@ -1134,7 +1153,7 @@ impl Default for BitvSet { #[stable] impl FromIterator for BitvSet { - fn from_iter>(iterator: I) -> BitvSet { + fn from_iter>(iterator: I) -> BitvSet { let mut ret = BitvSet::new(); ret.extend(iterator); ret @@ -1144,7 +1163,7 @@ impl FromIterator for BitvSet { #[stable] impl Extend for BitvSet { #[inline] - fn extend>(&mut self, mut iterator: I) { + fn extend>(&mut self, mut iterator: I) { for i in iterator { self.insert(i); } @@ -1792,7 +1811,9 @@ pub struct Difference<'a>(TwoBitPositions<'a>); pub struct SymmetricDifference<'a>(TwoBitPositions<'a>); #[stable] -impl<'a> Iterator for SetIter<'a> { +impl<'a> Iterator for SetIter<'a> { + type Item = uint; + fn next(&mut self) -> Option { while self.next_idx < self.set.bitv.len() { let idx = self.next_idx; @@ -1813,7 +1834,9 @@ impl<'a> Iterator for SetIter<'a> { } #[stable] -impl<'a> Iterator for TwoBitPositions<'a> { +impl<'a> Iterator for TwoBitPositions<'a> { + type Item = uint; + fn next(&mut self) -> Option { while self.next_idx < self.set.bitv.len() || self.next_idx < self.other.bitv.len() { @@ -1849,25 +1872,33 @@ impl<'a> Iterator for TwoBitPositions<'a> { } #[stable] -impl<'a> Iterator for Union<'a> { +impl<'a> Iterator for Union<'a> { + type Item = uint; + #[inline] fn next(&mut self) -> Option { self.0.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.0.size_hint() } } #[stable] -impl<'a> Iterator for Intersection<'a> { +impl<'a> Iterator for Intersection<'a> { + type Item = uint; + #[inline] fn next(&mut self) -> Option { self.0.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.0.size_hint() } } #[stable] -impl<'a> Iterator for Difference<'a> { +impl<'a> Iterator for Difference<'a> { + type Item = uint; + #[inline] fn next(&mut self) -> Option { self.0.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.0.size_hint() } } #[stable] -impl<'a> Iterator for SymmetricDifference<'a> { +impl<'a> Iterator for SymmetricDifference<'a> { + type Item = uint; + #[inline] fn next(&mut self) -> Option { self.0.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.0.size_hint() } } diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index da98c19e888fa..e86e93266652a 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -823,7 +823,7 @@ mod stack { #[stable] impl FromIterator<(K, V)> for BTreeMap { - fn from_iter>(iter: T) -> BTreeMap { + fn from_iter>(iter: T) -> BTreeMap { let mut map = BTreeMap::new(); map.extend(iter); map @@ -833,7 +833,7 @@ impl FromIterator<(K, V)> for BTreeMap { #[stable] impl Extend<(K, V)> for BTreeMap { #[inline] - fn extend>(&mut self, mut iter: T) { + fn extend>(&mut self, mut iter: T) { for (k, v) in iter { self.insert(k, v); } @@ -898,6 +898,8 @@ impl Show for BTreeMap { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl Index for BTreeMap where Q: BorrowFrom + Ord @@ -907,6 +909,20 @@ impl Index for BTreeMap } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl Index for BTreeMap + where Q: BorrowFrom + Ord +{ + type Output = V; + + fn index(&self, key: &Q) -> &V { + self.get(key).expect("no entry found for key") + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl IndexMut for BTreeMap where Q: BorrowFrom + Ord @@ -916,6 +932,18 @@ impl IndexMut for BTreeMap } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl IndexMut for BTreeMap + where Q: BorrowFrom + Ord +{ + type Output = V; + + fn index_mut(&mut self, key: &Q) -> &mut V { + self.get_mut(key).expect("no entry found for key") + } +} + /// Genericises over how to get the correct type of iterator from the correct type /// of Node ownership. trait Traverse { @@ -949,8 +977,11 @@ enum StackOp { Pop, } -impl + DoubleEndedIterator>> - Iterator<(K, V)> for AbsIter { +impl Iterator for AbsIter where + T: DoubleEndedIterator + Iterator> + Traverse, +{ + type Item = (K, V); + // This function is pretty long, but only because there's a lot of cases to consider. // Our iterator represents two search paths, left and right, to the smallest and largest // elements we have yet to yield. lca represents the least common ancestor of these two paths, @@ -1015,8 +1046,9 @@ impl + DoubleEndedIterator>> } } -impl + DoubleEndedIterator>> - DoubleEndedIterator<(K, V)> for AbsIter { +impl DoubleEndedIterator for AbsIter where + T: DoubleEndedIterator + Iterator> + Traverse, +{ // next_back is totally symmetric to next fn next_back(&mut self) -> Option<(K, V)> { loop { @@ -1054,64 +1086,75 @@ impl + DoubleEndedIterator>> } #[stable] -impl<'a, K, V> Iterator<(&'a K, &'a V)> for Iter<'a, K, V> { +impl<'a, K, V> Iterator for Iter<'a, K, V> { + type Item = (&'a K, &'a V); + fn next(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a V)> for Iter<'a, K, V> { +impl<'a, K, V> DoubleEndedIterator for Iter<'a, K, V> { fn next_back(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next_back() } } #[stable] -impl<'a, K, V> ExactSizeIterator<(&'a K, &'a V)> for Iter<'a, K, V> {} +impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {} #[stable] -impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { +impl<'a, K, V> Iterator for IterMut<'a, K, V> { + type Item = (&'a K, &'a mut V); + fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { +impl<'a, K, V> DoubleEndedIterator for IterMut<'a, K, V> { fn next_back(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next_back() } } #[stable] -impl<'a, K, V> ExactSizeIterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> {} +impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {} #[stable] -impl Iterator<(K, V)> for IntoIter { +impl Iterator for IntoIter { + type Item = (K, V); + fn next(&mut self) -> Option<(K, V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl DoubleEndedIterator<(K, V)> for IntoIter { +impl DoubleEndedIterator for IntoIter { fn next_back(&mut self) -> Option<(K, V)> { self.inner.next_back() } } #[stable] -impl ExactSizeIterator<(K, V)> for IntoIter {} +impl ExactSizeIterator for IntoIter {} #[stable] -impl<'a, K, V> Iterator<&'a K> for Keys<'a, K, V> { +impl<'a, K, V> Iterator for Keys<'a, K, V> { + type Item = &'a K; + fn next(&mut self) -> Option<(&'a K)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl<'a, K, V> DoubleEndedIterator<&'a K> for Keys<'a, K, V> { +impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> { fn next_back(&mut self) -> Option<(&'a K)> { self.inner.next_back() } } #[stable] -impl<'a, K, V> ExactSizeIterator<&'a K> for Keys<'a, K, V> {} +impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {} + #[stable] -impl<'a, K, V> Iterator<&'a V> for Values<'a, K, V> { +impl<'a, K, V> Iterator for Values<'a, K, V> { + type Item = &'a V; + fn next(&mut self) -> Option<(&'a V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl<'a, K, V> DoubleEndedIterator<&'a V> for Values<'a, K, V> { +impl<'a, K, V> DoubleEndedIterator for Values<'a, K, V> { fn next_back(&mut self) -> Option<(&'a V)> { self.inner.next_back() } } #[stable] -impl<'a, K, V> ExactSizeIterator<&'a V> for Values<'a, K, V> {} +impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {} impl<'a, K: Ord, V> VacantEntry<'a, K, V> { diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index 3dddcae11ce7c..f50650c2c8be3 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -210,7 +210,9 @@ impl RawItems { } } -impl Iterator for RawItems { +impl Iterator for RawItems { + type Item = T; + fn next(&mut self) -> Option { if self.head == self.tail { None @@ -230,7 +232,7 @@ impl Iterator for RawItems { } } -impl DoubleEndedIterator for RawItems { +impl DoubleEndedIterator for RawItems { fn next_back(&mut self) -> Option { if self.head == self.tail { None @@ -1321,8 +1323,10 @@ trait TraversalImpl { /// as no deallocation needs to be done. struct ElemsAndEdges(Elems, Edges); -impl, Edges: DoubleEndedIterator> - TraversalImpl for ElemsAndEdges { +impl + TraversalImpl for ElemsAndEdges + where Elems : Iterator, Edges : Iterator +{ fn next_kv(&mut self) -> Option<(K, V)> { self.0.next() } fn next_kv_back(&mut self) -> Option<(K, V)> { self.0.next_back() } @@ -1414,8 +1418,8 @@ pub type MutTraversal<'a, K, V> = AbsTraversal = AbsTraversal>; -impl> - Iterator> for AbsTraversal { +impl> Iterator for AbsTraversal { + type Item = TraversalItem; fn next(&mut self) -> Option> { let head_is_edge = self.head_is_edge; @@ -1429,9 +1433,7 @@ impl> } } -impl> - DoubleEndedIterator> for AbsTraversal { - +impl> DoubleEndedIterator for AbsTraversal { fn next_back(&mut self) -> Option> { let tail_is_edge = self.tail_is_edge; self.tail_is_edge = !tail_is_edge; diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 3e8988530e63e..a2899f76dad4c 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -436,7 +436,7 @@ impl BTreeSet { #[stable] impl FromIterator for BTreeSet { - fn from_iter>(iter: Iter) -> BTreeSet { + fn from_iter>(iter: Iter) -> BTreeSet { let mut set = BTreeSet::new(); set.extend(iter); set @@ -446,7 +446,7 @@ impl FromIterator for BTreeSet { #[stable] impl Extend for BTreeSet { #[inline] - fn extend>(&mut self, mut iter: Iter) { + fn extend>(&mut self, mut iter: Iter) { for elem in iter { self.insert(elem); } @@ -462,7 +462,9 @@ impl Default for BTreeSet { } #[stable] -impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet, BTreeSet> for &'a BTreeSet { +impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet> for &'a BTreeSet { + type Output = BTreeSet; + /// Returns the difference of `self` and `rhs` as a new `BTreeSet`. /// /// # Examples @@ -483,7 +485,9 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet, BTreeSet> for &'a BTreeSet< } #[stable] -impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet, BTreeSet> for &'a BTreeSet { +impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet> for &'a BTreeSet { + type Output = BTreeSet; + /// Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet`. /// /// # Examples @@ -504,7 +508,9 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet, BTreeSet> for &'a BTreeS } #[stable] -impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet, BTreeSet> for &'a BTreeSet { +impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet> for &'a BTreeSet { + type Output = BTreeSet; + /// Returns the intersection of `self` and `rhs` as a new `BTreeSet`. /// /// # Examples @@ -525,7 +531,9 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet, BTreeSet> for &'a BTreeS } #[stable] -impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet, BTreeSet> for &'a BTreeSet { +impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet> for &'a BTreeSet { + type Output = BTreeSet; + /// Returns the union of `self` and `rhs` as a new `BTreeSet`. /// /// # Examples @@ -560,28 +568,33 @@ impl Show for BTreeSet { } #[stable] -impl<'a, T> Iterator<&'a T> for Iter<'a, T> { +impl<'a, T> Iterator for Iter<'a, T> { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[stable] -impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { +impl<'a, T> DoubleEndedIterator for Iter<'a, T> { fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() } } #[stable] -impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} +impl<'a, T> ExactSizeIterator for Iter<'a, T> {} + #[stable] -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = T; + fn next(&mut self) -> Option { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[stable] -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter { fn next_back(&mut self) -> Option { self.iter.next_back() } } #[stable] -impl ExactSizeIterator for IntoIter {} +impl ExactSizeIterator for IntoIter {} /// Compare `x` and `y`, but return `short` if x is None and `long` if y is None fn cmp_opt(x: Option<&T>, y: Option<&T>, @@ -594,7 +607,9 @@ fn cmp_opt(x: Option<&T>, y: Option<&T>, } #[stable] -impl<'a, T: Ord> Iterator<&'a T> for Difference<'a, T> { +impl<'a, T: Ord> Iterator for Difference<'a, T> { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { loop { match cmp_opt(self.a.peek(), self.b.peek(), Less, Less) { @@ -607,7 +622,9 @@ impl<'a, T: Ord> Iterator<&'a T> for Difference<'a, T> { } #[stable] -impl<'a, T: Ord> Iterator<&'a T> for SymmetricDifference<'a, T> { +impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { loop { match cmp_opt(self.a.peek(), self.b.peek(), Greater, Less) { @@ -620,7 +637,9 @@ impl<'a, T: Ord> Iterator<&'a T> for SymmetricDifference<'a, T> { } #[stable] -impl<'a, T: Ord> Iterator<&'a T> for Intersection<'a, T> { +impl<'a, T: Ord> Iterator for Intersection<'a, T> { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { loop { let o_cmp = match (self.a.peek(), self.b.peek()) { @@ -639,7 +658,9 @@ impl<'a, T: Ord> Iterator<&'a T> for Intersection<'a, T> { } #[stable] -impl<'a, T: Ord> Iterator<&'a T> for Union<'a, T> { +impl<'a, T: Ord> Iterator for Union<'a, T> { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { loop { match cmp_opt(self.a.peek(), self.b.peek(), Greater, Less) { diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 68acbfcb3c3c8..b3d61f445639b 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -508,7 +508,9 @@ impl Drop for DList { } #[stable] -impl<'a, A> Iterator<&'a A> for Iter<'a, A> { +impl<'a, A> Iterator for Iter<'a, A> { + type Item = &'a A; + #[inline] fn next(&mut self) -> Option<&'a A> { if self.nelem == 0 { @@ -528,7 +530,7 @@ impl<'a, A> Iterator<&'a A> for Iter<'a, A> { } #[stable] -impl<'a, A> DoubleEndedIterator<&'a A> for Iter<'a, A> { +impl<'a, A> DoubleEndedIterator for Iter<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a A> { if self.nelem == 0 { @@ -543,10 +545,11 @@ impl<'a, A> DoubleEndedIterator<&'a A> for Iter<'a, A> { } #[stable] -impl<'a, A> ExactSizeIterator<&'a A> for Iter<'a, A> {} +impl<'a, A> ExactSizeIterator for Iter<'a, A> {} #[stable] -impl<'a, A> Iterator<&'a mut A> for IterMut<'a, A> { +impl<'a, A> Iterator for IterMut<'a, A> { + type Item = &'a mut A; #[inline] fn next(&mut self) -> Option<&'a mut A> { if self.nelem == 0 { @@ -569,7 +572,7 @@ impl<'a, A> Iterator<&'a mut A> for IterMut<'a, A> { } #[stable] -impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> { +impl<'a, A> DoubleEndedIterator for IterMut<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a mut A> { if self.nelem == 0 { @@ -584,7 +587,7 @@ impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> { } #[stable] -impl<'a, A> ExactSizeIterator<&'a mut A> for IterMut<'a, A> {} +impl<'a, A> ExactSizeIterator for IterMut<'a, A> {} /// Allows mutating a `DList` while iterating. #[deprecated = "Trait is deprecated, use inherent methods on the iterator instead"] @@ -676,7 +679,9 @@ impl<'a, A> IterMut<'a, A> { } #[stable] -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = A; + #[inline] fn next(&mut self) -> Option { self.list.pop_front() } @@ -687,14 +692,14 @@ impl Iterator for IntoIter { } #[stable] -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.list.pop_back() } } #[stable] impl FromIterator for DList { - fn from_iter>(iterator: T) -> DList { + fn from_iter>(iterator: T) -> DList { let mut ret = DList::new(); ret.extend(iterator); ret @@ -703,7 +708,7 @@ impl FromIterator for DList { #[stable] impl Extend for DList { - fn extend>(&mut self, mut iterator: T) { + fn extend>(&mut self, mut iterator: T) { for elt in iterator { self.push_back(elt); } } } diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index ea3d8659f54a4..81e1541bea0bf 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -185,25 +185,33 @@ impl EnumSet { } } -impl Sub, EnumSet> for EnumSet { +impl Sub for EnumSet { + type Output = EnumSet; + fn sub(self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits & !e.bits} } } -impl BitOr, EnumSet> for EnumSet { +impl BitOr for EnumSet { + type Output = EnumSet; + fn bitor(self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits | e.bits} } } -impl BitAnd, EnumSet> for EnumSet { +impl BitAnd for EnumSet { + type Output = EnumSet; + fn bitand(self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits & e.bits} } } -impl BitXor, EnumSet> for EnumSet { +impl BitXor for EnumSet { + type Output = EnumSet; + fn bitxor(self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits ^ e.bits} } @@ -231,7 +239,9 @@ impl Iter { } } -impl Iterator for Iter { +impl Iterator for Iter { + type Item = E; + fn next(&mut self) -> Option { if self.bits == 0 { return None; @@ -254,7 +264,7 @@ impl Iterator for Iter { } impl FromIterator for EnumSet { - fn from_iter>(iterator: I) -> EnumSet { + fn from_iter>(iterator: I) -> EnumSet { let mut ret = EnumSet::new(); ret.extend(iterator); ret @@ -262,7 +272,7 @@ impl FromIterator for EnumSet { } impl Extend for EnumSet { - fn extend>(&mut self, mut iterator: I) { + fn extend>(&mut self, mut iterator: I) { for element in iterator { self.insert(element); } diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index fac9ab8107a72..fb9530882db35 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -110,7 +110,7 @@ mod prelude { pub use core::iter::range; pub use core::iter::{FromIterator, Extend, IteratorExt}; pub use core::iter::{Iterator, DoubleEndedIterator, RandomAccessIterator}; - pub use core::iter::{IteratorCloneExt, CloneIteratorExt, DoubleEndedIteratorExt}; + pub use core::iter::{IteratorCloneExt, CloneIteratorExt}; pub use core::iter::{IteratorOrdExt, MutableDoubleEndedIterator, ExactSizeIterator}; pub use core::kinds::{Copy, Send, Sized, Sync}; pub use core::mem::drop; diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index e4c9e51a8455b..dd78ae03c5af7 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1151,7 +1151,9 @@ impl<'a, T> Clone for Iter<'a, T> { } #[stable] -impl<'a, T> Iterator<&'a T> for Iter<'a, T> { +impl<'a, T> Iterator for Iter<'a, T> { + type Item = &'a T; + #[inline] fn next(&mut self) -> Option<&'a T> { if self.tail == self.head { @@ -1170,7 +1172,7 @@ impl<'a, T> Iterator<&'a T> for Iter<'a, T> { } #[stable] -impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { +impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { if self.tail == self.head { @@ -1182,10 +1184,10 @@ impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { } #[stable] -impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} +impl<'a, T> ExactSizeIterator for Iter<'a, T> {} #[stable] -impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> { +impl<'a, T> RandomAccessIterator for Iter<'a, T> { #[inline] fn indexable(&self) -> uint { let (len, _) = self.size_hint(); @@ -1217,7 +1219,9 @@ pub struct IterMut<'a, T:'a> { } #[stable] -impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> { +impl<'a, T> Iterator for IterMut<'a, T> { + type Item = &'a mut T; + #[inline] fn next(&mut self) -> Option<&'a mut T> { if self.tail == self.head { @@ -1239,7 +1243,7 @@ impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> { } #[stable] -impl<'a, T> DoubleEndedIterator<&'a mut T> for IterMut<'a, T> { +impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut T> { if self.tail == self.head { @@ -1254,7 +1258,7 @@ impl<'a, T> DoubleEndedIterator<&'a mut T> for IterMut<'a, T> { } #[stable] -impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {} +impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} /// A by-value RingBuf iterator #[stable] @@ -1263,7 +1267,9 @@ pub struct IntoIter { } #[stable] -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = T; + #[inline] fn next(&mut self) -> Option { self.inner.pop_front() @@ -1277,7 +1283,7 @@ impl Iterator for IntoIter { } #[stable] -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.inner.pop_back() @@ -1285,7 +1291,7 @@ impl DoubleEndedIterator for IntoIter { } #[stable] -impl ExactSizeIterator for IntoIter {} +impl ExactSizeIterator for IntoIter {} /// A draining RingBuf iterator #[unstable = "matches collection reform specification, waiting for dust to settle"] @@ -1304,7 +1310,9 @@ impl<'a, T: 'a> Drop for Drain<'a, T> { } #[stable] -impl<'a, T: 'a> Iterator for Drain<'a, T> { +impl<'a, T: 'a> Iterator for Drain<'a, T> { + type Item = T; + #[inline] fn next(&mut self) -> Option { self.inner.pop_front() @@ -1318,7 +1326,7 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> { } #[stable] -impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { +impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { #[inline] fn next_back(&mut self) -> Option { self.inner.pop_back() @@ -1326,7 +1334,7 @@ impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { } #[stable] -impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {} +impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {} #[stable] impl PartialEq for RingBuf { @@ -1364,6 +1372,8 @@ impl> Hash for RingBuf { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl Index for RingBuf { #[inline] @@ -1372,6 +1382,19 @@ impl Index for RingBuf { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl Index for RingBuf { + type Output = A; + + #[inline] + fn index<'a>(&'a self, i: &uint) -> &'a A { + self.get(*i).expect("Out of bounds access") + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl IndexMut for RingBuf { #[inline] @@ -1380,9 +1403,20 @@ impl IndexMut for RingBuf { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl IndexMut for RingBuf { + type Output = A; + + #[inline] + fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut A { + self.get_mut(*i).expect("Out of bounds access") + } +} + #[stable] impl FromIterator for RingBuf { - fn from_iter>(iterator: T) -> RingBuf { + fn from_iter>(iterator: T) -> RingBuf { let (lower, _) = iterator.size_hint(); let mut deq = RingBuf::with_capacity(lower); deq.extend(iterator); @@ -1392,7 +1426,7 @@ impl FromIterator for RingBuf { #[stable] impl Extend for RingBuf { - fn extend>(&mut self, mut iterator: T) { + fn extend>(&mut self, mut iterator: T) { for elt in iterator { self.push_back(elt); } diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 1c1b48f8cef67..5db4e8580d0a4 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1140,7 +1140,9 @@ struct SizeDirection { dir: Direction, } -impl Iterator<(uint, uint)> for ElementSwaps { +impl Iterator for ElementSwaps { + type Item = (uint, uint); + #[inline] fn next(&mut self) -> Option<(uint, uint)> { fn new_pos(i: uint, s: Direction) -> uint { @@ -1207,7 +1209,9 @@ pub struct Permutations { } #[unstable = "trait is unstable"] -impl Iterator> for Permutations { +impl Iterator for Permutations { + type Item = Vec; + #[inline] fn next(&mut self) -> Option> { match self.swaps.next() { @@ -1445,7 +1449,7 @@ pub mod raw { mod tests { use std::boxed::Box; use prelude::{Some, None, range, Vec, ToString, Clone, Greater, Less, Equal}; - use prelude::{SliceExt, Iterator, IteratorExt, DoubleEndedIteratorExt}; + use prelude::{SliceExt, Iterator, IteratorExt}; use prelude::AsSlice; use prelude::{RandomAccessIterator, Ord, SliceConcatExt}; use core::cell::Cell; diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 129ba77d9f7a6..6c51480931b3b 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -181,7 +181,9 @@ pub struct Decompositions<'a> { sorted: bool } -impl<'a> Iterator for Decompositions<'a> { +impl<'a> Iterator for Decompositions<'a> { + type Item = char; + #[inline] fn next(&mut self) -> Option { match self.buffer.first() { @@ -268,7 +270,9 @@ pub struct Recompositions<'a> { last_ccc: Option } -impl<'a> Iterator for Recompositions<'a> { +impl<'a> Iterator for Recompositions<'a> { + type Item = char; + #[inline] fn next(&mut self) -> Option { loop { @@ -357,7 +361,9 @@ pub struct Utf16Units<'a> { encoder: Utf16Encoder> } -impl<'a> Iterator for Utf16Units<'a> { +impl<'a> Iterator for Utf16Units<'a> { + type Item = u16; + #[inline] fn next(&mut self) -> Option { self.encoder.next() } @@ -3272,7 +3278,7 @@ mod tests { #[cfg(test)] mod bench { use super::*; - use prelude::{SliceExt, IteratorExt, DoubleEndedIteratorExt, SliceConcatExt}; + use prelude::{SliceExt, IteratorExt, SliceConcatExt}; use test::Bencher; use test::black_box; diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 769679ec4d448..35fa3fb55de23 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -781,7 +781,7 @@ impl fmt::Show for FromUtf16Error { #[experimental = "waiting on FromIterator stabilization"] impl FromIterator for String { - fn from_iter>(iterator: I) -> String { + fn from_iter>(iterator: I) -> String { let mut buf = String::new(); buf.extend(iterator); buf @@ -790,7 +790,7 @@ impl FromIterator for String { #[experimental = "waiting on FromIterator stabilization"] impl<'a> FromIterator<&'a str> for String { - fn from_iter>(iterator: I) -> String { + fn from_iter>(iterator: I) -> String { let mut buf = String::new(); buf.extend(iterator); buf @@ -799,7 +799,7 @@ impl<'a> FromIterator<&'a str> for String { #[experimental = "waiting on Extend stabilization"] impl Extend for String { - fn extend>(&mut self, mut iterator: I) { + fn extend>(&mut self, mut iterator: I) { let (lower_bound, _) = iterator.size_hint(); self.reserve(lower_bound); for ch in iterator { @@ -810,7 +810,7 @@ impl Extend for String { #[experimental = "waiting on Extend stabilization"] impl<'a> Extend<&'a str> for String { - fn extend>(&mut self, mut iterator: I) { + fn extend>(&mut self, mut iterator: I) { // A guess that at least one byte per iterator element will be needed. let (lower_bound, _) = iterator.size_hint(); self.reserve(lower_bound); @@ -911,7 +911,9 @@ impl<'a, S: Str> Equiv for String { } #[experimental = "waiting on Add stabilization"] -impl<'a> Add<&'a str, String> for String { +impl<'a> Add<&'a str> for String { + type Output = String; + fn add(mut self, other: &str) -> String { self.push_str(other); self diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 7e36792742171..073388018725a 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1164,7 +1164,7 @@ impl Vec { /// Deprecated: use `unzip` directly on the iterator instead. #[deprecated = "use unzip directly on the iterator instead"] -pub fn unzip>(iter: V) -> (Vec, Vec) { +pub fn unzip>(iter: V) -> (Vec, Vec) { iter.unzip() } @@ -1245,6 +1245,8 @@ impl> Hash for Vec { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[experimental = "waiting on Index stability"] impl Index for Vec { #[inline] @@ -1253,6 +1255,19 @@ impl Index for Vec { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[experimental = "waiting on Index stability"] +impl Index for Vec { + type Output = T; + + #[inline] + fn index<'a>(&'a self, index: &uint) -> &'a T { + &self.as_slice()[*index] + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IndexMut for Vec { #[inline] fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T { @@ -1260,6 +1275,16 @@ impl IndexMut for Vec { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IndexMut for Vec { + type Output = T; + + #[inline] + fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T { + &mut self.as_mut_slice()[*index] + } +} + impl ops::Slice for Vec { #[inline] fn as_slice_<'a>(&'a self) -> &'a [T] { @@ -1317,7 +1342,7 @@ impl ops::DerefMut for Vec { #[experimental = "waiting on FromIterator stability"] impl FromIterator for Vec { #[inline] - fn from_iter>(mut iterator: I) -> Vec { + fn from_iter>(mut iterator: I) -> Vec { let (lower, _) = iterator.size_hint(); let mut vector = Vec::with_capacity(lower); for element in iterator { @@ -1330,7 +1355,7 @@ impl FromIterator for Vec { #[experimental = "waiting on Extend stability"] impl Extend for Vec { #[inline] - fn extend>(&mut self, mut iterator: I) { + fn extend>(&mut self, mut iterator: I) { let (lower, _) = iterator.size_hint(); self.reserve(lower); for element in iterator { @@ -1451,7 +1476,9 @@ impl AsSlice for Vec { } } -impl<'a, T: Clone> Add<&'a [T], Vec> for Vec { +impl<'a, T: Clone> Add<&'a [T]> for Vec { + type Output = Vec; + #[inline] fn add(mut self, rhs: &[T]) -> Vec { self.push_all(rhs); @@ -1506,7 +1533,7 @@ impl<'a> fmt::Writer for Vec { pub type CowVec<'a, T> = Cow<'a, Vec, [T]>; impl<'a, T> FromIterator for CowVec<'a, T> where T: Clone { - fn from_iter>(it: I) -> CowVec<'a, T> { + fn from_iter>(it: I) -> CowVec<'a, T> { Cow::Owned(FromIterator::from_iter(it)) } } @@ -1557,7 +1584,9 @@ impl IntoIter { pub fn unwrap(self) -> Vec { self.into_inner() } } -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = T; + #[inline] fn next<'a>(&'a mut self) -> Option { unsafe { @@ -1591,7 +1620,7 @@ impl Iterator for IntoIter { } } -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back<'a>(&'a mut self) -> Option { unsafe { @@ -1614,7 +1643,7 @@ impl DoubleEndedIterator for IntoIter { } } -impl ExactSizeIterator for IntoIter {} +impl ExactSizeIterator for IntoIter {} #[unsafe_destructor] impl Drop for IntoIter { @@ -1638,7 +1667,9 @@ pub struct Drain<'a, T> { marker: ContravariantLifetime<'a>, } -impl<'a, T> Iterator for Drain<'a, T> { +impl<'a, T> Iterator for Drain<'a, T> { + type Item = T; + #[inline] fn next(&mut self) -> Option { unsafe { @@ -1672,7 +1703,7 @@ impl<'a, T> Iterator for Drain<'a, T> { } } -impl<'a, T> DoubleEndedIterator for Drain<'a, T> { +impl<'a, T> DoubleEndedIterator for Drain<'a, T> { #[inline] fn next_back(&mut self) -> Option { unsafe { @@ -1695,7 +1726,7 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T> { } } -impl<'a, T> ExactSizeIterator for Drain<'a, T> {} +impl<'a, T> ExactSizeIterator for Drain<'a, T> {} #[unsafe_destructor] impl<'a, T> Drop for Drain<'a, T> { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 172fd56ed3962..91edbc7b54e41 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -546,7 +546,7 @@ impl fmt::Show for VecMap { #[stable] impl FromIterator<(uint, V)> for VecMap { - fn from_iter>(iter: Iter) -> VecMap { + fn from_iter>(iter: Iter) -> VecMap { let mut map = VecMap::new(); map.extend(iter); map @@ -555,13 +555,15 @@ impl FromIterator<(uint, V)> for VecMap { #[stable] impl Extend<(uint, V)> for VecMap { - fn extend>(&mut self, mut iter: Iter) { + fn extend>(&mut self, mut iter: Iter) { for (k, v) in iter { self.insert(k, v); } } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl Index for VecMap { #[inline] @@ -570,6 +572,18 @@ impl Index for VecMap { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl Index for VecMap { + type Output = V; + + #[inline] + fn index<'a>(&'a self, i: &uint) -> &'a V { + self.get(i).expect("key not present") + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl IndexMut for VecMap { #[inline] @@ -578,10 +592,23 @@ impl IndexMut for VecMap { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl IndexMut for VecMap { + type Output = V; + + #[inline] + fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut V { + self.get_mut(i).expect("key not present") + } +} + macro_rules! iterator { (impl $name:ident -> $elem:ty, $($getter:ident),+) => { #[stable] - impl<'a, V> Iterator<$elem> for $name<'a, V> { + impl<'a, V> Iterator for $name<'a, V> { + type Item = $elem; + #[inline] fn next(&mut self) -> Option<$elem> { while self.front < self.back { @@ -614,7 +641,7 @@ macro_rules! iterator { macro_rules! double_ended_iterator { (impl $name:ident -> $elem:ty, $($getter:ident),+) => { #[stable] - impl<'a, V> DoubleEndedIterator<$elem> for $name<'a, V> { + impl<'a, V> DoubleEndedIterator for $name<'a, V> { #[inline] fn next_back(&mut self) -> Option<$elem> { while self.front < self.back { @@ -713,32 +740,38 @@ pub struct IntoIter { } #[stable] -impl<'a, V> Iterator for Keys<'a, V> { +impl<'a, V> Iterator for Keys<'a, V> { + type Item = uint; + fn next(&mut self) -> Option { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[stable] -impl<'a, V> DoubleEndedIterator for Keys<'a, V> { +impl<'a, V> DoubleEndedIterator for Keys<'a, V> { fn next_back(&mut self) -> Option { self.iter.next_back() } } #[stable] -impl<'a, V> Iterator<&'a V> for Values<'a, V> { +impl<'a, V> Iterator for Values<'a, V> { + type Item = &'a V; + fn next(&mut self) -> Option<(&'a V)> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[stable] -impl<'a, V> DoubleEndedIterator<&'a V> for Values<'a, V> { +impl<'a, V> DoubleEndedIterator for Values<'a, V> { fn next_back(&mut self) -> Option<(&'a V)> { self.iter.next_back() } } #[stable] -impl Iterator<(uint, V)> for IntoIter { +impl Iterator for IntoIter { + type Item = (uint, V); + fn next(&mut self) -> Option<(uint, V)> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[stable] -impl DoubleEndedIterator<(uint, V)> for IntoIter { +impl DoubleEndedIterator for IntoIter { fn next_back(&mut self) -> Option<(uint, V)> { self.iter.next_back() } } diff --git a/src/libcore/char.rs b/src/libcore/char.rs index f0151dda8d71e..aa6028a19b323 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -446,7 +446,9 @@ enum EscapeUnicodeState { Done, } -impl Iterator for EscapeUnicode { +impl Iterator for EscapeUnicode { + type Item = char; + fn next(&mut self) -> Option { match self.state { EscapeUnicodeState::Backslash => { @@ -501,7 +503,9 @@ enum EscapeDefaultState { Unicode(EscapeUnicode), } -impl Iterator for EscapeDefault { +impl Iterator for EscapeDefault { + type Item = char; + fn next(&mut self) -> Option { match self.state { EscapeDefaultState::Backslash(c) => { diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index a39168ec1ec82..27023fab858d9 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -17,7 +17,7 @@ pub use self::SignFormat::*; use char; use char::Char; use fmt; -use iter::{range, DoubleEndedIteratorExt}; +use iter::{IteratorExt, range}; use num::{cast, Float, ToPrimitive}; use num::FpCategory as Fp; use ops::FnOnce; diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index 4f0cecbb24353..e680230265aa6 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -15,7 +15,7 @@ #![allow(unsigned_negation)] use fmt; -use iter::DoubleEndedIteratorExt; +use iter::IteratorExt; use num::{Int, cast}; use slice::SliceExt; use str; diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index d7a675b3104ec..f65857b37fb2d 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -82,9 +82,11 @@ use uint; /// else. #[lang="iterator"] #[unstable = "just split up for object safety"] -pub trait Iterator { +pub trait Iterator { + type Item; + /// Advance the iterator and return the next value. Return `None` when the end is reached. - fn next(&mut self) -> Option; + fn next(&mut self) -> Option; /// Returns a lower and upper bound on the remaining length of the iterator. /// @@ -98,19 +100,19 @@ pub trait Iterator { #[unstable = "may be replaced by a more general conversion trait"] pub trait FromIterator { /// Build a container with elements from an external iterator. - fn from_iter>(iterator: T) -> Self; + fn from_iter>(iterator: T) -> Self; } /// A type growable from an `Iterator` implementation #[unstable = "just renamed as part of collections reform"] pub trait Extend { /// Extend a container with the elements yielded by an arbitrary iterator - fn extend>(&mut self, iterator: T); + fn extend>(&mut self, iterator: T); } #[unstable = "new convention for extension traits"] /// An extension trait providing numerous methods applicable to all iterators. -pub trait IteratorExt: Iterator + Sized { +pub trait IteratorExt: Iterator + Sized { /// Chain this iterator with another, returning a new iterator that will /// finish iterating over the current iterator, and then iterate /// over the other specified iterator. @@ -127,7 +129,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable] - fn chain>(self, other: U) -> Chain { + fn chain(self, other: U) -> Chain where + U: Iterator::Item>, + { Chain{a: self, b: other, flag: false} } @@ -148,7 +152,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable] - fn zip>(self, other: U) -> Zip { + fn zip(self, other: U) -> Zip where + U: Iterator, + { Zip{a: self, b: other} } @@ -166,7 +172,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn map B>(self, f: F) -> Map { + fn map(self, f: F) -> Map< ::Item, B, Self, F> where + F: FnMut(::Item) -> B, + { Map{iter: self, f: f} } @@ -184,7 +192,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn filter

(self, predicate: P) -> Filter where P: FnMut(&A) -> bool { + fn filter

(self, predicate: P) -> Filter< ::Item, Self, P> where + P: FnMut(&::Item) -> bool, + { Filter{iter: self, predicate: predicate} } @@ -202,7 +212,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn filter_map(self, f: F) -> FilterMap where F: FnMut(A) -> Option { + fn filter_map(self, f: F) -> FilterMap< ::Item, B, Self, F> where + F: FnMut(::Item) -> Option, + { FilterMap { iter: self, f: f } } @@ -244,7 +256,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable] - fn peekable(self) -> Peekable { + fn peekable(self) -> Peekable< ::Item, Self> { Peekable{iter: self, peeked: None} } @@ -264,7 +276,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn skip_while

(self, predicate: P) -> SkipWhile where P: FnMut(&A) -> bool { + fn skip_while

(self, predicate: P) -> SkipWhile< ::Item, Self, P> where + P: FnMut(&::Item) -> bool, + { SkipWhile{iter: self, flag: false, predicate: predicate} } @@ -283,7 +297,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, may want to require peek"] - fn take_while

(self, predicate: P) -> TakeWhile where P: FnMut(&A) -> bool { + fn take_while

(self, predicate: P) -> TakeWhile< ::Item, Self, P> where + P: FnMut(&::Item) -> bool, + { TakeWhile{iter: self, flag: false, predicate: predicate} } @@ -346,8 +362,12 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn scan(self, initial_state: St, f: F) -> Scan where - F: FnMut(&mut St, A) -> Option, + fn scan( + self, + initial_state: St, + f: F, + ) -> Scan< ::Item, B, Self, St, F> where + F: FnMut(&mut St, ::Item) -> Option, { Scan{iter: self, f: f, state: initial_state} } @@ -372,9 +392,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn flat_map(self, f: F) -> FlatMap where - U: Iterator, - F: FnMut(A) -> U, + fn flat_map(self, f: F) -> FlatMap< ::Item, B, Self, U, F> where + U: Iterator, + F: FnMut(::Item) -> U, { FlatMap{iter: self, f: f, frontiter: None, backiter: None } } @@ -386,7 +406,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Example /// /// ```rust - /// fn process>(it: U) -> int { + /// fn process>(it: U) -> int { /// let mut it = it.fuse(); /// let mut sum = 0; /// for x in it { @@ -432,7 +452,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn inspect(self, f: F) -> Inspect where F: FnMut(&A) { + fn inspect(self, f: F) -> Inspect< ::Item, Self, F> where + F: FnMut(&::Item), + { Inspect{iter: self, f: f} } @@ -468,7 +490,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for general conversion traits, just changed to take self by value"] - fn collect>(self) -> B { + fn collect::Item>>(self) -> B { FromIterator::from_iter(self) } @@ -485,7 +507,8 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[unstable = "recently added as part of collections reform"] fn partition(mut self, mut f: F) -> (B, B) where - B: Default + Extend, F: FnMut(&A) -> bool + B: Default + Extend< ::Item>, + F: FnMut(&::Item) -> bool { let mut left: B = Default::default(); let mut right: B = Default::default(); @@ -514,7 +537,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable] - fn nth(&mut self, mut n: uint) -> Option { + fn nth(&mut self, mut n: uint) -> Option< ::Item> { for x in *self { if n == 0 { return Some(x) } n -= 1; @@ -533,7 +556,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "just changed to take self by value"] - fn last(mut self) -> Option { + fn last(mut self) -> Option< ::Item> { let mut last = None; for x in self { last = Some(x); } last @@ -550,7 +573,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn fold(mut self, init: B, mut f: F) -> B where F: FnMut(B, A) -> B { + fn fold(mut self, init: B, mut f: F) -> B where + F: FnMut(B, ::Item) -> B, + { let mut accum = init; for x in self { accum = f(accum, x); @@ -584,7 +609,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn all(mut self, mut f: F) -> bool where F: FnMut(A) -> bool { + fn all(mut self, mut f: F) -> bool where F: FnMut(::Item) -> bool { for x in self { if !f(x) { return false; } } true } @@ -602,7 +627,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn any(&mut self, mut f: F) -> bool where F: FnMut(A) -> bool { + fn any(&mut self, mut f: F) -> bool where F: FnMut(::Item) -> bool { for x in *self { if f(x) { return true; } } false } @@ -612,7 +637,9 @@ pub trait IteratorExt: Iterator + Sized { /// Does not consume the iterator past the first found element. #[inline] #[unstable = "waiting for unboxed closures"] - fn find

(&mut self, mut predicate: P) -> Option where P: FnMut(&A) -> bool { + fn find

(&mut self, mut predicate: P) -> Option< ::Item> where + P: FnMut(&::Item) -> bool, + { for x in *self { if predicate(&x) { return Some(x) } } @@ -622,7 +649,9 @@ pub trait IteratorExt: Iterator + Sized { /// Return the index of the first element satisfying the specified predicate #[inline] #[unstable = "waiting for unboxed closures"] - fn position

(&mut self, mut predicate: P) -> Option where P: FnMut(A) -> bool { + fn position

(&mut self, mut predicate: P) -> Option where + P: FnMut(::Item) -> bool, + { let mut i = 0; for x in *self { if predicate(x) { @@ -646,8 +675,10 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn max_by(self, mut f: F) -> Option where F: FnMut(&A) -> B { - self.fold(None, |max: Option<(A, B)>, x| { + fn max_by(self, mut f: F) -> Option< ::Item> where + F: FnMut(&::Item) -> B, + { + self.fold(None, |max: Option<(::Item, B)>, x| { let x_val = f(&x); match max { None => Some((x, x_val)), @@ -673,8 +704,10 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn min_by(self, mut f: F) -> Option where F: FnMut(&A) -> B { - self.fold(None, |min: Option<(A, B)>, x| { + fn min_by(self, mut f: F) -> Option< ::Item> where + F: FnMut(&::Item) -> B, + { + self.fold(None, |min: Option<(::Item, B)>, x| { let x_val = f(&x); match min { None => Some((x, x_val)), @@ -686,23 +719,38 @@ pub trait IteratorExt: Iterator + Sized { } }).map(|(x, _)| x) } -} -#[unstable = "trait is unstable"] -impl IteratorExt for I where I: Iterator {} + /// Change the direction of the iterator + /// + /// The flipped iterator swaps the ends on an iterator that can already + /// be iterated from the front and from the back. + /// + /// + /// If the iterator also implements RandomAccessIterator, the flipped + /// iterator is also random access, with the indices starting at the back + /// of the original iterator. + /// + /// Note: Random access with flipped indices still only applies to the first + /// `uint::MAX` elements of the original iterator. + #[inline] + #[stable] + fn rev(self) -> Rev { + Rev{iter: self} + } -/// Extention trait for iterators of pairs. -#[unstable = "newly added trait, likely to be merged with IteratorExt"] -pub trait IteratorPairExt: Iterator<(A, B)> + Sized { /// Converts an iterator of pairs into a pair of containers. /// /// Loops through the entire iterator, collecting the first component of /// each item into one new container, and the second component into another. - fn unzip(mut self) -> (FromA, FromB) where - FromA: Default + Extend, FromB: Default + Extend + fn unzip(mut self) -> (FromA, FromB) where + FromA: Default + Extend, + FromB: Default + Extend, + Self: Iterator, { struct SizeHint(uint, Option); - impl Iterator for SizeHint { + impl Iterator for SizeHint { + type Item = A; + fn next(&mut self) -> Option { None } fn size_hint(&self) -> (uint, Option) { (self.0, self.1) @@ -725,43 +773,19 @@ pub trait IteratorPairExt: Iterator<(A, B)> + Sized { } } -impl IteratorPairExt for I where I: Iterator<(A, B)> {} +#[unstable = "trait is unstable"] +impl IteratorExt for I where I: Iterator {} /// A range iterator able to yield elements from both ends /// /// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust /// elements from the *same* range, and do not work independently of each other. #[unstable = "recently split into two traits"] -pub trait DoubleEndedIterator: Iterator { +pub trait DoubleEndedIterator: Iterator { /// Yield an element from the end of the range, returning `None` if the range is empty. - fn next_back(&mut self) -> Option; -} - -/// Extension methods for double-ended iterators. -#[unstable = "new extension trait convention"] -pub trait DoubleEndedIteratorExt: DoubleEndedIterator + Sized { - /// Change the direction of the iterator - /// - /// The flipped iterator swaps the ends on an iterator that can already - /// be iterated from the front and from the back. - /// - /// - /// If the iterator also implements RandomAccessIterator, the flipped - /// iterator is also random access, with the indices starting at the back - /// of the original iterator. - /// - /// Note: Random access with flipped indices still only applies to the first - /// `uint::MAX` elements of the original iterator. - #[inline] - #[stable] - fn rev(self) -> Rev { - Rev{iter: self} - } + fn next_back(&mut self) -> Option< ::Item>; } -#[unstable = "trait is unstable"] -impl DoubleEndedIteratorExt for I where I: DoubleEndedIterator {} - /// A double-ended iterator yielding mutable references #[experimental = "not widely used"] pub trait MutableDoubleEndedIterator { @@ -771,7 +795,9 @@ pub trait MutableDoubleEndedIterator { } #[experimental = "trait is experimental"] -impl<'a, A:'a, T: DoubleEndedIterator<&'a mut A>> MutableDoubleEndedIterator for T { +impl<'a, T:'a, I> MutableDoubleEndedIterator for I where + I: DoubleEndedIterator + Iterator, +{ // FIXME: #5898: should be called `reverse` /// Use an iterator to reverse a container in-place fn reverse_(&mut self) { @@ -792,13 +818,13 @@ impl<'a, A:'a, T: DoubleEndedIterator<&'a mut A>> MutableDoubleEndedIterator for /// reduces the indexable range accordingly. That is, `it.idx(1)` will become `it.idx(0)` /// after `it.next()` is called. #[experimental = "not widely used, may be better decomposed into Index and ExactSizeIterator"] -pub trait RandomAccessIterator: Iterator { +pub trait RandomAccessIterator: Iterator { /// Return the number of indexable elements. At most `std::uint::MAX` /// elements are indexable, even if the iterator represents a longer range. fn indexable(&self) -> uint; /// Return an element at an index, or `None` if the index is out of bounds - fn idx(&mut self, index: uint) -> Option; + fn idx(&mut self, index: uint) -> Option< ::Item>; } /// An iterator that knows its exact length @@ -809,12 +835,14 @@ pub trait RandomAccessIterator: Iterator { /// `Iterator::size_hint` *must* return the exact size of the iterator. /// Note that the size must fit in `uint`. #[unstable = "could move DoubleEndedIterator bound onto rposition with method-level where clauses"] -pub trait ExactSizeIterator : DoubleEndedIterator { +pub trait ExactSizeIterator: DoubleEndedIterator { /// Return the index of the last element satisfying the specified predicate /// /// If no element matches, None is returned. #[inline] - fn rposition

(&mut self, mut predicate: P) -> Option where P: FnMut(A) -> bool { + fn rposition

(&mut self, mut predicate: P) -> Option where + P: FnMut(::Item) -> bool, + { let len = self.len(); for i in range(0, len).rev() { if predicate(self.next_back().expect("rposition: incorrect ExactSizeIterator")) { @@ -840,22 +868,21 @@ pub trait ExactSizeIterator : DoubleEndedIterator { // All adaptors that preserve the size of the wrapped iterator are fine // Adaptors that may overflow in `size_hint` are not, i.e. `Chain`. #[unstable = "trait is unstable"] -impl> ExactSizeIterator<(uint, A)> for Enumerate {} +impl ExactSizeIterator for Enumerate where I: ExactSizeIterator {} #[unstable = "trait is unstable"] -impl ExactSizeIterator for Inspect where - I: ExactSizeIterator, +impl ExactSizeIterator for Inspect where + I: ExactSizeIterator + Iterator, F: FnMut(&A), {} #[unstable = "trait is unstable"] -impl> ExactSizeIterator for Rev {} +impl ExactSizeIterator for Rev where I: ExactSizeIterator {} #[unstable = "trait is unstable"] -impl ExactSizeIterator for Map where - I: ExactSizeIterator, +impl ExactSizeIterator for Map where + I: ExactSizeIterator + Iterator, F: FnMut(A) -> B, {} #[unstable = "trait is unstable"] -impl ExactSizeIterator<(A, B)> for Zip - where T: ExactSizeIterator, U: ExactSizeIterator {} +impl ExactSizeIterator for Zip where A: ExactSizeIterator, B: ExactSizeIterator {} /// An double-ended iterator with the direction inverted #[deriving(Clone)] @@ -866,26 +893,27 @@ pub struct Rev { } #[unstable = "trait is unstable"] -impl> Iterator for Rev { +impl Iterator for Rev where I: DoubleEndedIterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { self.iter.next_back() } + fn next(&mut self) -> Option< ::Item> { self.iter.next_back() } #[inline] fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[unstable = "trait is unstable"] -impl> DoubleEndedIterator for Rev { +impl DoubleEndedIterator for Rev where I: DoubleEndedIterator { #[inline] - fn next_back(&mut self) -> Option { self.iter.next() } + fn next_back(&mut self) -> Option< ::Item> { self.iter.next() } } #[experimental = "trait is experimental"] -impl + RandomAccessIterator> RandomAccessIterator - for Rev { +impl RandomAccessIterator for Rev where I: DoubleEndedIterator + RandomAccessIterator { #[inline] fn indexable(&self) -> uint { self.iter.indexable() } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { let amt = self.indexable(); self.iter.idx(amt - index - 1) } @@ -894,22 +922,24 @@ impl + RandomAccessIterator> RandomAccessIterato /// A mutable reference to an iterator #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct ByRef<'a, T:'a> { - iter: &'a mut T +pub struct ByRef<'a, I:'a> { + iter: &'a mut I, } #[unstable = "trait is unstable"] -impl<'a, A, T: Iterator+'a> Iterator for ByRef<'a, T> { +impl<'a, I> Iterator for ByRef<'a, I> where I: 'a + Iterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { self.iter.next() } + fn next(&mut self) -> Option< ::Item> { self.iter.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[unstable = "trait is unstable"] -impl<'a, A, T: DoubleEndedIterator+'a> DoubleEndedIterator for ByRef<'a, T> { +impl<'a, I> DoubleEndedIterator for ByRef<'a, I> where I: 'a + DoubleEndedIterator { #[inline] - fn next_back(&mut self) -> Option { self.iter.next_back() } + fn next_back(&mut self) -> Option< ::Item> { self.iter.next_back() } } /// A trait for iterators over elements which can be added together @@ -932,7 +962,7 @@ pub trait AdditiveIterator { macro_rules! impl_additive { ($A:ty, $init:expr) => { #[experimental = "trait is experimental"] - impl> AdditiveIterator<$A> for T { + impl> AdditiveIterator<$A> for T { #[inline] fn sum(self) -> $A { self.fold($init, |acc, x| acc + x) @@ -976,7 +1006,7 @@ pub trait MultiplicativeIterator { macro_rules! impl_multiplicative { ($A:ty, $init:expr) => { #[experimental = "trait is experimental"] - impl> MultiplicativeIterator<$A> for T { + impl> MultiplicativeIterator<$A> for T { #[inline] fn product(self) -> $A { self.fold($init, |acc, x| acc * x) @@ -1057,9 +1087,9 @@ pub trait IteratorOrdExt { } #[unstable = "trait is unstable"] -impl> IteratorOrdExt for T { +impl IteratorOrdExt for I where I: Iterator, T: Ord { #[inline] - fn max(self) -> Option { + fn max(self) -> Option { self.fold(None, |max, x| { match max { None => Some(x), @@ -1069,7 +1099,7 @@ impl> IteratorOrdExt for T { } #[inline] - fn min(self) -> Option { + fn min(self) -> Option { self.fold(None, |min, x| { match min { None => Some(x), @@ -1078,7 +1108,7 @@ impl> IteratorOrdExt for T { }) } - fn min_max(mut self) -> MinMaxResult { + fn min_max(mut self) -> MinMaxResult { let (mut min, mut max) = match self.next() { None => return NoElements, Some(x) => { @@ -1175,7 +1205,11 @@ pub trait IteratorCloneExt { } #[unstable = "trait is unstable"] -impl, I: Iterator> IteratorCloneExt for I { +impl IteratorCloneExt for I where + T: Clone, + D: Deref, + I: Iterator, +{ fn cloned(self) -> Cloned { Cloned { it: self } } @@ -1186,8 +1220,14 @@ pub struct Cloned { it: I, } -impl, I: Iterator> Iterator for Cloned { - fn next(&mut self) -> Option { +impl Iterator for Cloned where + T: Clone, + D: Deref, + I: Iterator, +{ + type Item = T; + + fn next(&mut self) -> Option { self.it.next().cloned() } @@ -1196,15 +1236,22 @@ impl, I: Iterator> Iterator for Cloned { } } -impl, I: DoubleEndedIterator> - DoubleEndedIterator for Cloned { - fn next_back(&mut self) -> Option { +impl DoubleEndedIterator for Cloned where + T: Clone, + D: Deref, + I: DoubleEndedIterator + Iterator, +{ + fn next_back(&mut self) -> Option { self.it.next_back().cloned() } } #[unstable = "trait is unstable"] -impl, I: ExactSizeIterator> ExactSizeIterator for Cloned {} +impl ExactSizeIterator for Cloned where + T: Clone, + D: Deref, + I: ExactSizeIterator + Iterator, +{} #[unstable = "recently renamed for extension trait conventions"] /// An extension trait for cloneable iterators. @@ -1225,7 +1272,7 @@ pub trait CloneIteratorExt { fn cycle(self) -> Cycle; } -impl CloneIteratorExt for I where I: Iterator + Clone { +impl CloneIteratorExt for I where I: Iterator + Clone { #[inline] fn cycle(self) -> Cycle { Cycle{orig: self.clone(), iter: self} @@ -1236,14 +1283,16 @@ impl CloneIteratorExt for I where I: Iterator + Clone { #[deriving(Clone, Copy)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Cycle { - orig: T, - iter: T, +pub struct Cycle { + orig: I, + iter: I, } -impl> Iterator for Cycle { +impl Iterator for Cycle where I: Clone + Iterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option< ::Item> { match self.iter.next() { None => { self.iter = self.orig.clone(); self.iter.next() } y => y @@ -1262,7 +1311,9 @@ impl> Iterator for Cycle { } #[experimental = "trait is experimental"] -impl> RandomAccessIterator for Cycle { +impl RandomAccessIterator for Cycle where + I: Clone + RandomAccessIterator, +{ #[inline] fn indexable(&self) -> uint { if self.orig.indexable() > 0 { @@ -1273,7 +1324,7 @@ impl> RandomAccessIterator for Cycle } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { let liter = self.iter.indexable(); let lorig = self.orig.indexable(); if lorig == 0 { @@ -1290,16 +1341,18 @@ impl> RandomAccessIterator for Cycle #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Chain { - a: T, - b: U, +pub struct Chain { + a: A, + b: B, flag: bool, } #[unstable = "trait is unstable"] -impl, U: Iterator> Iterator for Chain { +impl Iterator for Chain where A: Iterator, B: Iterator { + type Item = T; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.flag { self.b.next() } else { @@ -1329,10 +1382,12 @@ impl, U: Iterator> Iterator for Chain { } #[unstable = "trait is unstable"] -impl, U: DoubleEndedIterator> DoubleEndedIterator -for Chain { +impl DoubleEndedIterator for Chain where + A: DoubleEndedIterator + Iterator, + B: DoubleEndedIterator + Iterator, +{ #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option { match self.b.next_back() { Some(x) => Some(x), None => self.a.next_back() @@ -1341,8 +1396,10 @@ for Chain { } #[experimental = "trait is experimental"] -impl, U: RandomAccessIterator> RandomAccessIterator -for Chain { +impl RandomAccessIterator for Chain where + A: RandomAccessIterator + Iterator, + B: RandomAccessIterator + Iterator, +{ #[inline] fn indexable(&self) -> uint { let (a, b) = (self.a.indexable(), self.b.indexable()); @@ -1350,7 +1407,7 @@ for Chain { } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option { let len = self.a.indexable(); if index < len { self.a.idx(index) @@ -1364,15 +1421,20 @@ for Chain { #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Zip { - a: T, - b: U +pub struct Zip { + a: A, + b: B } #[unstable = "trait is unstable"] -impl, U: Iterator> Iterator<(A, B)> for Zip { +impl Iterator for Zip where + A: Iterator, + B: Iterator, +{ + type Item = (T, U); + #[inline] - fn next(&mut self) -> Option<(A, B)> { + fn next(&mut self) -> Option<(T, U)> { match self.a.next() { None => None, Some(x) => match self.b.next() { @@ -1401,10 +1463,12 @@ impl, U: Iterator> Iterator<(A, B)> for Zip { } #[unstable = "trait is unstable"] -impl, U: ExactSizeIterator> DoubleEndedIterator<(A, B)> -for Zip { +impl DoubleEndedIterator for Zip where + A: ExactSizeIterator + Iterator, + B: ExactSizeIterator + Iterator, +{ #[inline] - fn next_back(&mut self) -> Option<(A, B)> { + fn next_back(&mut self) -> Option<(T, U)> { let a_sz = self.a.len(); let b_sz = self.b.len(); if a_sz != b_sz { @@ -1424,15 +1488,17 @@ for Zip { } #[experimental = "trait is experimental"] -impl, U: RandomAccessIterator> -RandomAccessIterator<(A, B)> for Zip { +impl RandomAccessIterator for Zip where + A: RandomAccessIterator + Iterator, + B: RandomAccessIterator + Iterator, +{ #[inline] fn indexable(&self) -> uint { cmp::min(self.a.indexable(), self.b.indexable()) } #[inline] - fn idx(&mut self, index: uint) -> Option<(A, B)> { + fn idx(&mut self, index: uint) -> Option<(T, U)> { match self.a.idx(index) { None => None, Some(x) => match self.b.idx(index) { @@ -1446,7 +1512,7 @@ RandomAccessIterator<(A, B)> for Zip { /// An iterator that maps the values of `iter` with `f` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Map, F: FnMut(A) -> B> { +pub struct Map, F: FnMut(A) -> B> { iter: I, f: F, } @@ -1454,7 +1520,7 @@ pub struct Map, F: FnMut(A) -> B> { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for Map where - I: Clone + Iterator, + I: Clone + Iterator, F: Clone + FnMut(A) -> B, { fn clone(&self) -> Map { @@ -1465,7 +1531,7 @@ impl Clone for Map where } } -impl Map where I: Iterator, F: FnMut(A) -> B { +impl Map where I: Iterator, F: FnMut(A) -> B { #[inline] fn do_map(&mut self, elt: Option) -> Option { match elt { @@ -1476,7 +1542,9 @@ impl Map where I: Iterator, F: FnMut(A) -> B { } #[unstable = "trait is unstable"] -impl Iterator for Map where I: Iterator, F: FnMut(A) -> B { +impl Iterator for Map where I: Iterator, F: FnMut(A) -> B { + type Item = B; + #[inline] fn next(&mut self) -> Option { let next = self.iter.next(); @@ -1490,8 +1558,8 @@ impl Iterator for Map where I: Iterator, F: FnMut( } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Map where - I: DoubleEndedIterator, +impl DoubleEndedIterator for Map where + I: DoubleEndedIterator + Iterator, F: FnMut(A) -> B, { #[inline] @@ -1502,8 +1570,8 @@ impl DoubleEndedIterator for Map where } #[experimental = "trait is experimental"] -impl RandomAccessIterator for Map where - I: RandomAccessIterator, +impl RandomAccessIterator for Map where + I: RandomAccessIterator + Iterator, F: FnMut(A) -> B, { #[inline] @@ -1521,7 +1589,7 @@ 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] -pub struct Filter where I: Iterator, P: FnMut(&A) -> bool { +pub struct Filter where I: Iterator, P: FnMut(&A) -> bool { iter: I, predicate: P, } @@ -1529,7 +1597,7 @@ pub struct Filter where I: Iterator, P: FnMut(&A) -> bool { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for Filter where - I: Clone + Iterator, + I: Clone + Iterator, P: Clone + FnMut(&A) -> bool, { fn clone(&self) -> Filter { @@ -1541,7 +1609,9 @@ impl Clone for Filter where } #[unstable = "trait is unstable"] -impl Iterator for Filter where I: Iterator, P: FnMut(&A) -> bool { +impl Iterator for Filter where I: Iterator, P: FnMut(&A) -> bool { + type Item = A; + #[inline] fn next(&mut self) -> Option { for x in self.iter { @@ -1562,8 +1632,8 @@ impl Iterator for Filter where I: Iterator, P: FnMut(&A) } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Filter where - I: DoubleEndedIterator, +impl DoubleEndedIterator for Filter where + I: DoubleEndedIterator + Iterator, P: FnMut(&A) -> bool, { #[inline] @@ -1580,7 +1650,7 @@ 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] -pub struct FilterMap where I: Iterator, F: FnMut(A) -> Option { +pub struct FilterMap where I: Iterator, F: FnMut(A) -> Option { iter: I, f: F, } @@ -1588,7 +1658,7 @@ pub struct FilterMap where I: Iterator, F: FnMut(A) -> Option // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for FilterMap where - I: Clone + Iterator, + I: Clone + Iterator, F: Clone + FnMut(A) -> Option, { fn clone(&self) -> FilterMap { @@ -1600,10 +1670,12 @@ impl Clone for FilterMap where } #[unstable = "trait is unstable"] -impl Iterator for FilterMap where - I: Iterator, +impl Iterator for FilterMap where + I: Iterator, F: FnMut(A) -> Option, { + type Item = B; + #[inline] fn next(&mut self) -> Option { for x in self.iter { @@ -1623,8 +1695,8 @@ impl Iterator for FilterMap where } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for FilterMap where - I: DoubleEndedIterator, +impl DoubleEndedIterator for FilterMap where + I: DoubleEndedIterator + Iterator, F: FnMut(A) -> Option, { #[inline] @@ -1643,15 +1715,17 @@ impl DoubleEndedIterator for FilterMap where #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Enumerate { - iter: T, +pub struct Enumerate { + iter: I, count: uint } #[unstable = "trait is unstable"] -impl> Iterator<(uint, A)> for Enumerate { +impl Iterator for Enumerate where I: Iterator { + type Item = (uint, ::Item); + #[inline] - fn next(&mut self) -> Option<(uint, A)> { + fn next(&mut self) -> Option<(uint, ::Item)> { match self.iter.next() { Some(a) => { let ret = Some((self.count, a)); @@ -1669,9 +1743,9 @@ impl> Iterator<(uint, A)> for Enumerate { } #[unstable = "trait is unstable"] -impl> DoubleEndedIterator<(uint, A)> for Enumerate { +impl DoubleEndedIterator for Enumerate where I: ExactSizeIterator { #[inline] - fn next_back(&mut self) -> Option<(uint, A)> { + fn next_back(&mut self) -> Option<(uint, ::Item)> { match self.iter.next_back() { Some(a) => { let len = self.iter.len(); @@ -1683,14 +1757,14 @@ impl> DoubleEndedIterator<(uint, A)> for Enumerate } #[experimental = "trait is experimental"] -impl> RandomAccessIterator<(uint, A)> for Enumerate { +impl RandomAccessIterator for Enumerate where I: RandomAccessIterator { #[inline] fn indexable(&self) -> uint { self.iter.indexable() } #[inline] - fn idx(&mut self, index: uint) -> Option<(uint, A)> { + fn idx(&mut self, index: uint) -> Option<(uint, ::Item)> { match self.iter.idx(index) { Some(a) => Some((self.count + index, a)), _ => None, @@ -1702,14 +1776,16 @@ impl> RandomAccessIterator<(uint, A)> for Enumerat #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] #[deriving(Copy)] -pub struct Peekable { - iter: T, - peeked: Option, +pub struct Peekable where I: Iterator { + iter: I, + peeked: Option, } -impl> Iterator for Peekable { +impl Iterator for Peekable where I: Iterator { + type Item = T; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.peeked.is_some() { self.peeked.take() } else { self.iter.next() } } @@ -1731,11 +1807,11 @@ impl> Iterator for Peekable { } #[stable] -impl<'a, A, T: Iterator> Peekable { +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. #[inline] - pub fn peek(&'a mut self) -> Option<&'a A> { + pub fn peek(&mut self) -> Option<&T> { if self.peeked.is_none() { self.peeked = self.iter.next(); } @@ -1755,7 +1831,7 @@ impl<'a, A, T: Iterator> Peekable { /// An iterator that rejects elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct SkipWhile where I: Iterator, P: FnMut(&A) -> bool { +pub struct SkipWhile where I: Iterator, P: FnMut(&A) -> bool { iter: I, flag: bool, predicate: P, @@ -1764,7 +1840,7 @@ pub struct SkipWhile where I: Iterator, P: FnMut(&A) -> bool { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for SkipWhile where - I: Clone + Iterator, + I: Clone + Iterator, P: Clone + FnMut(&A) -> bool, { fn clone(&self) -> SkipWhile { @@ -1777,7 +1853,9 @@ impl Clone for SkipWhile where } #[unstable = "trait is unstable"] -impl Iterator for SkipWhile where I: Iterator, P: FnMut(&A) -> bool { +impl Iterator for SkipWhile where I: Iterator, P: FnMut(&A) -> bool { + type Item = A; + #[inline] fn next(&mut self) -> Option { for x in self.iter { @@ -1799,7 +1877,7 @@ impl Iterator for SkipWhile where I: Iterator, P: FnMut( /// An iterator that only accepts elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct TakeWhile where I: Iterator, P: FnMut(&A) -> bool { +pub struct TakeWhile where I: Iterator, P: FnMut(&A) -> bool { iter: I, flag: bool, predicate: P, @@ -1808,7 +1886,7 @@ pub struct TakeWhile where I: Iterator, P: FnMut(&A) -> bool { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for TakeWhile where - I: Clone + Iterator, + I: Clone + Iterator, P: Clone + FnMut(&A) -> bool, { fn clone(&self) -> TakeWhile { @@ -1821,7 +1899,9 @@ impl Clone for TakeWhile where } #[unstable = "trait is unstable"] -impl Iterator for TakeWhile where I: Iterator, P: FnMut(&A) -> bool { +impl Iterator for TakeWhile where I: Iterator, P: FnMut(&A) -> bool { + type Item = A; + #[inline] fn next(&mut self) -> Option { if self.flag { @@ -1852,15 +1932,17 @@ impl Iterator for TakeWhile where I: Iterator, P: FnMut( #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Skip { - iter: T, +pub struct Skip { + iter: I, n: uint } #[unstable = "trait is unstable"] -impl> Iterator for Skip { +impl Iterator for Skip where I: Iterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option< ::Item> { let mut next = self.iter.next(); if self.n == 0 { next @@ -1900,14 +1982,14 @@ impl> Iterator for Skip { } #[experimental = "trait is experimental"] -impl> RandomAccessIterator for Skip { +impl RandomAccessIterator for Skip where I: RandomAccessIterator{ #[inline] fn indexable(&self) -> uint { self.iter.indexable().saturating_sub(self.n) } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { if index >= self.indexable() { None } else { @@ -1920,15 +2002,17 @@ impl> RandomAccessIterator for Skip { #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Take { - iter: T, +pub struct Take { + iter: I, n: uint } #[unstable = "trait is unstable"] -impl> Iterator for Take { +impl Iterator for Take where I: Iterator{ + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option< ::Item> { if self.n != 0 { self.n -= 1; self.iter.next() @@ -1953,14 +2037,14 @@ impl> Iterator for Take { } #[experimental = "trait is experimental"] -impl> RandomAccessIterator for Take { +impl RandomAccessIterator for Take where I: RandomAccessIterator{ #[inline] fn indexable(&self) -> uint { cmp::min(self.iter.indexable(), self.n) } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { if index >= self.n { None } else { @@ -1973,7 +2057,7 @@ impl> RandomAccessIterator for Take { /// An iterator to maintain state while iterating another iterator #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[unstable = "waiting for unboxed closures"] -pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Option { +pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Option { iter: I, f: F, @@ -1984,7 +2068,7 @@ pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Op // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for Scan where - I: Clone + Iterator, + I: Clone + Iterator, St: Clone, F: Clone + FnMut(&mut St, A) -> Option, { @@ -1998,10 +2082,12 @@ impl Clone for Scan where } #[unstable = "trait is unstable"] -impl Iterator for Scan where - I: Iterator, +impl Iterator for Scan where + I: Iterator, F: FnMut(&mut St, A) -> Option, { + type Item = B; + #[inline] fn next(&mut self) -> Option { self.iter.next().and_then(|a| (self.f)(&mut self.state, a)) @@ -2019,7 +2105,11 @@ impl Iterator for Scan where /// #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[unstable = "waiting for unboxed closures"] -pub struct FlatMap where I: Iterator, U: Iterator, F: FnMut(A) -> U { +pub struct FlatMap where + I: Iterator, + U: Iterator, + F: FnMut(A) -> U, +{ iter: I, f: F, frontiter: Option, @@ -2029,8 +2119,8 @@ pub struct FlatMap where I: Iterator, U: Iterator, F: FnMut // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for FlatMap where - I: Clone + Iterator, - U: Clone + Iterator, + I: Clone + Iterator, + U: Clone + Iterator, F: Clone + FnMut(A) -> U, { fn clone(&self) -> FlatMap { @@ -2044,11 +2134,13 @@ impl Clone for FlatMap where } #[unstable = "trait is unstable"] -impl Iterator for FlatMap where - I: Iterator, - U: Iterator, +impl Iterator for FlatMap where + I: Iterator, + U: Iterator, F: FnMut(A) -> U, { + type Item = B; + #[inline] fn next(&mut self) -> Option { loop { @@ -2077,9 +2169,9 @@ impl Iterator for FlatMap where } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for FlatMap where - I: DoubleEndedIterator, - U: DoubleEndedIterator, +impl DoubleEndedIterator for FlatMap where + I: DoubleEndedIterator + Iterator, + U: DoubleEndedIterator + Iterator, F: FnMut(A) -> U, { #[inline] @@ -2104,15 +2196,17 @@ impl DoubleEndedIterator for FlatMap where #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Fuse { - iter: T, +pub struct Fuse { + iter: I, done: bool } #[unstable = "trait is unstable"] -impl> Iterator for Fuse { +impl Iterator for Fuse where I: Iterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option< ::Item> { if self.done { None } else { @@ -2137,9 +2231,9 @@ impl> Iterator for Fuse { } #[unstable = "trait is unstable"] -impl> DoubleEndedIterator for Fuse { +impl DoubleEndedIterator for Fuse where I: DoubleEndedIterator { #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option< ::Item> { if self.done { None } else { @@ -2156,20 +2250,20 @@ impl> DoubleEndedIterator for Fuse { // Allow RandomAccessIterators to be fused without affecting random-access behavior #[experimental = "trait is experimental"] -impl> RandomAccessIterator for Fuse { +impl RandomAccessIterator for Fuse where I: RandomAccessIterator { #[inline] fn indexable(&self) -> uint { self.iter.indexable() } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { self.iter.idx(index) } } #[experimental = "seems marginal"] -impl Fuse { +impl Fuse { /// Resets the fuse such that the next call to .next() or .next_back() will /// call the underlying iterator again even if it previously returned None. #[inline] @@ -2182,7 +2276,7 @@ impl Fuse { /// element before yielding it. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[unstable = "waiting for unboxed closures"] -pub struct Inspect where I: Iterator, F: FnMut(&A) { +pub struct Inspect where I: Iterator, F: FnMut(&A) { iter: I, f: F, } @@ -2190,7 +2284,7 @@ pub struct Inspect where I: Iterator, F: FnMut(&A) { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for Inspect where - I: Clone + Iterator, + I: Clone + Iterator, F: Clone + FnMut(&A), { fn clone(&self) -> Inspect { @@ -2201,7 +2295,7 @@ impl Clone for Inspect where } } -impl Inspect where I: Iterator, F: FnMut(&A) { +impl Inspect where I: Iterator, F: FnMut(&A) { #[inline] fn do_inspect(&mut self, elt: Option) -> Option { match elt { @@ -2214,7 +2308,9 @@ impl Inspect where I: Iterator, F: FnMut(&A) { } #[unstable = "trait is unstable"] -impl Iterator for Inspect where I: Iterator, F: FnMut(&A) { +impl Iterator for Inspect where I: Iterator, F: FnMut(&A) { + type Item = A; + #[inline] fn next(&mut self) -> Option { let next = self.iter.next(); @@ -2228,8 +2324,8 @@ impl Iterator for Inspect where I: Iterator, F: FnMut(&A } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Inspect where - I: DoubleEndedIterator, +impl DoubleEndedIterator for Inspect where + I: DoubleEndedIterator + Iterator, F: FnMut(&A), { #[inline] @@ -2240,8 +2336,8 @@ impl DoubleEndedIterator for Inspect where } #[experimental = "trait is experimental"] -impl RandomAccessIterator for Inspect where - I: RandomAccessIterator, +impl RandomAccessIterator for Inspect where + I: RandomAccessIterator + Iterator, F: FnMut(&A), { #[inline] @@ -2323,7 +2419,9 @@ impl Unfold where F: FnMut(&mut St) -> Option { } #[experimental] -impl Iterator for Unfold where F: FnMut(&mut St) -> Option { +impl Iterator for Unfold where F: FnMut(&mut St) -> Option { + type Item = A; + #[inline] fn next(&mut self) -> Option { (self.f)(&mut self.state) @@ -2355,7 +2453,9 @@ pub fn count(start: A, step: A) -> Counter { } #[unstable = "trait is unstable"] -impl + Clone> Iterator for Counter { +impl + Clone> Iterator for Counter { + type Item = A; + #[inline] fn next(&mut self) -> Option { let result = self.state.clone(); @@ -2402,7 +2502,9 @@ pub fn range(start: A, stop: A) -> Range { // FIXME: #10414: Unfortunate type bound #[unstable = "trait is unstable"] -impl Iterator for Range { +impl Iterator for Range { + type Item = A; + #[inline] fn next(&mut self) -> Option { if self.state < self.stop { @@ -2450,7 +2552,7 @@ impl Iterator for Range { /// `Int` is required to ensure the range will be the same regardless of /// the direction it is consumed. #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Range { +impl DoubleEndedIterator for Range { #[inline] fn next_back(&mut self) -> Option { if self.stop > self.state { @@ -2481,7 +2583,9 @@ pub fn range_inclusive(start: A, stop: A) -> RangeInclusive { } #[unstable = "trait is unstable"] -impl Iterator for RangeInclusive { +impl Iterator for RangeInclusive { + type Item = A; + #[inline] fn next(&mut self) -> Option { match self.range.next() { @@ -2514,7 +2618,7 @@ impl Iterator for RangeInclusive { } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for RangeInclusive { +impl DoubleEndedIterator for RangeInclusive { #[inline] fn next_back(&mut self) -> Option { if self.range.stop > self.range.state { @@ -2549,7 +2653,9 @@ pub fn range_step(start: A, stop: A, step: A) -> RangeStep { } #[unstable = "trait is unstable"] -impl Iterator for RangeStep { +impl Iterator for RangeStep { + type Item = A; + #[inline] fn next(&mut self) -> Option { if (self.rev && self.state > self.stop) || (!self.rev && self.state < self.stop) { @@ -2591,7 +2697,9 @@ pub fn range_step_inclusive(start: A, stop: A, step: A) -> RangeStepIncl } #[unstable = "trait is unstable"] -impl Iterator for RangeStepInclusive { +impl Iterator for RangeStepInclusive { + type Item = A; + #[inline] fn next(&mut self) -> Option { if !self.done && ((self.rev && self.state >= self.stop) || @@ -2683,7 +2791,9 @@ impl Repeat { } #[unstable = "trait is unstable"] -impl Iterator for Repeat { +impl Iterator for Repeat { + type Item = A; + #[inline] fn next(&mut self) -> Option { self.idx(0) } #[inline] @@ -2691,13 +2801,13 @@ impl Iterator for Repeat { } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Repeat { +impl DoubleEndedIterator for Repeat { #[inline] fn next_back(&mut self) -> Option { self.idx(0) } } #[experimental = "trait is experimental"] -impl RandomAccessIterator for Repeat { +impl RandomAccessIterator for Repeat { #[inline] fn indexable(&self) -> uint { uint::MAX } #[inline] @@ -2766,7 +2876,11 @@ pub mod order { use super::Iterator; /// Compare `a` and `b` for equality using `Eq` - pub fn equals, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn equals(mut a: T, mut b: S) -> bool where + A: Eq, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return true, @@ -2777,7 +2891,11 @@ pub mod order { } /// Order `a` and `b` lexicographically using `Ord` - pub fn cmp, S: Iterator>(mut a: T, mut b: S) -> cmp::Ordering { + pub fn cmp(mut a: T, mut b: S) -> cmp::Ordering where + A: Ord, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return Equal, @@ -2792,8 +2910,11 @@ pub mod order { } /// Order `a` and `b` lexicographically using `PartialOrd` - pub fn partial_cmp, S: Iterator>(mut a: T, mut b: S) - -> Option { + pub fn partial_cmp(mut a: T, mut b: S) -> Option where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return Some(Equal), @@ -2810,8 +2931,8 @@ pub mod order { /// Compare `a` and `b` for equality (Using partial equality, `PartialEq`) pub fn eq(mut a: L, mut b: R) -> bool where A: PartialEq, - L: Iterator, - R: Iterator, + L: Iterator, + R: Iterator, { loop { match (a.next(), b.next()) { @@ -2825,8 +2946,8 @@ pub mod order { /// Compare `a` and `b` for nonequality (Using partial equality, `PartialEq`) pub fn ne(mut a: L, mut b: R) -> bool where A: PartialEq, - L: Iterator, - R: Iterator, + L: Iterator, + R: Iterator, { loop { match (a.next(), b.next()) { @@ -2838,7 +2959,11 @@ pub mod order { } /// Return `a` < `b` lexicographically (Using partial order, `PartialOrd`) - pub fn lt, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn lt(mut a: T, mut b: S) -> bool where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return false, @@ -2850,7 +2975,11 @@ pub mod order { } /// Return `a` <= `b` lexicographically (Using partial order, `PartialOrd`) - pub fn le, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn le(mut a: T, mut b: S) -> bool where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return true, @@ -2862,7 +2991,11 @@ pub mod order { } /// Return `a` > `b` lexicographically (Using partial order, `PartialOrd`) - pub fn gt, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn gt(mut a: T, mut b: S) -> bool where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return false, @@ -2874,7 +3007,11 @@ pub mod order { } /// Return `a` >= `b` lexicographically (Using partial order, `PartialOrd`) - pub fn ge, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn ge(mut a: T, mut b: S) -> bool where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return true, diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index d16478dd6cc7e..254788f9a75f1 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -35,7 +35,7 @@ use str::{FromStr, from_str, StrExt}; /// Simultaneous division and remainder #[inline] #[deprecated = "use division and remainder directly"] -pub fn div_rem + Rem>(x: T, y: T) -> (T, T) { +pub fn div_rem + Rem>(x: T, y: T) -> (T, T) { (x.clone() / y.clone(), x % y) } @@ -53,17 +53,17 @@ pub trait Int + NumCast + PartialOrd + Ord + PartialEq + Eq - + Add - + Sub - + Mul - + Div - + Rem - + Not - + BitAnd - + BitOr - + BitXor - + Shl - + Shr + + Add + + Sub + + Mul + + Div + + Rem + + Not + + BitAnd + + BitOr + + BitXor + + Shl + + Shr { /// Returns the `0` value of this integer type. // FIXME (#5527): Should be an associated constant @@ -613,7 +613,7 @@ int_impl! { int = i64, u64, 64, #[unstable = "recently settled as part of numerics reform"] pub trait SignedInt : Int - + Neg + + Neg { /// Computes the absolute value of `self`. `Int::min_value()` will be /// returned if the number is `Int::min_value()`. @@ -1245,12 +1245,12 @@ pub trait Float + NumCast + PartialOrd + PartialEq - + Neg - + Add - + Sub - + Mul - + Div - + Rem + + Neg + + Add + + Sub + + Mul + + Div + + Rem { /// Returns the NaN value. fn nan() -> Self; @@ -1718,12 +1718,12 @@ macro_rules! trait_impl { #[deprecated = "Generalised numbers are no longer supported"] #[allow(deprecated)] pub trait Num: PartialEq + Zero + One - + Neg - + Add - + Sub - + Mul - + Div - + Rem {} + + Neg + + Add + + Sub + + Mul + + Div + + Rem {} trait_impl! { Num for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } #[deprecated = "Generalised unsigned numbers are no longer supported"] @@ -1737,7 +1737,7 @@ pub trait Primitive: Copy + Clone + Num + NumCast + PartialOrd {} trait_impl! { Primitive for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } #[deprecated = "The generic `Zero` trait will be removed soon."] -pub trait Zero: Add { +pub trait Zero: Add { #[deprecated = "Use `Int::zero()` or `Float::zero()`."] fn zero() -> Self; #[deprecated = "Use `x == Int::zero()` or `x == Float::zero()`."] @@ -1768,7 +1768,7 @@ zero_impl! { f32, 0.0f32 } zero_impl! { f64, 0.0f64 } #[deprecated = "The generic `One` trait will be removed soon."] -pub trait One: Mul { +pub trait One: Mul { #[deprecated = "Use `Int::one()` or `Float::one()`."] fn one() -> Self; } diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index b51d4d91c2f55..bef91dbd76047 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -25,6 +25,8 @@ //! demonstrates adding and subtracting two `Point`s. //! //! ```rust +//! #![feature(associated_types)] +//! //! use std::ops::{Add, Sub}; //! //! #[deriving(Show)] @@ -33,13 +35,17 @@ //! y: int //! } //! -//! impl Add for Point { +//! impl Add for Point { +//! type Output = Point; +//! //! fn add(self, other: Point) -> Point { //! Point {x: self.x + other.x, y: self.y + other.y} //! } //! } //! -//! impl Sub for Point { +//! impl Sub for Point { +//! type Output = Point; +//! //! fn sub(self, other: Point) -> Point { //! Point {x: self.x - other.x, y: self.y - other.y} //! } @@ -93,12 +99,16 @@ pub trait Drop { /// calling `add`, and therefore, `main` prints `Adding!`. /// /// ```rust +/// #![feature(associated_types)] +/// /// use std::ops::Add; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl Add for Foo { +/// impl Add for Foo { +/// type Output = Foo; +/// /// fn add(self, _rhs: Foo) -> Foo { /// println!("Adding!"); /// self @@ -110,14 +120,18 @@ pub trait Drop { /// } /// ``` #[lang="add"] -pub trait Add { +pub trait Add { + type Output; + /// The method for the `+` operator - fn add(self, rhs: RHS) -> Result; + fn add(self, rhs: RHS) -> Self::Output; } macro_rules! add_impl { ($($t:ty)*) => ($( - impl Add<$t, $t> for $t { + impl Add for $t { + type Output = $t; + #[inline] fn add(self, other: $t) -> $t { self + other } } @@ -134,12 +148,16 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `sub`, and therefore, `main` prints `Subtracting!`. /// /// ```rust +/// #![feature(associated_types)] +/// /// use std::ops::Sub; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl Sub for Foo { +/// impl Sub for Foo { +/// type Output = Foo; +/// /// fn sub(self, _rhs: Foo) -> Foo { /// println!("Subtracting!"); /// self @@ -151,14 +169,18 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="sub"] -pub trait Sub { +pub trait Sub { + type Output; + /// The method for the `-` operator - fn sub(self, rhs: RHS) -> Result; + fn sub(self, rhs: RHS) -> Self::Output; } macro_rules! sub_impl { ($($t:ty)*) => ($( - impl Sub<$t, $t> for $t { + impl Sub for $t { + type Output = $t; + #[inline] fn sub(self, other: $t) -> $t { self - other } } @@ -175,12 +197,16 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `mul`, and therefore, `main` prints `Multiplying!`. /// /// ```rust +/// #![feature(associated_types)] +/// /// use std::ops::Mul; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl Mul for Foo { +/// impl Mul for Foo { +/// type Output = Foo; +/// /// fn mul(self, _rhs: Foo) -> Foo { /// println!("Multiplying!"); /// self @@ -192,14 +218,18 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="mul"] -pub trait Mul { +pub trait Mul { + type Output; + /// The method for the `*` operator - fn mul(self, rhs: RHS) -> Result; + fn mul(self, rhs: RHS) -> Self::Output; } macro_rules! mul_impl { ($($t:ty)*) => ($( - impl Mul<$t, $t> for $t { + impl Mul for $t { + type Output = $t; + #[inline] fn mul(self, other: $t) -> $t { self * other } } @@ -216,12 +246,16 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `div`, and therefore, `main` prints `Dividing!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::Div; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl Div for Foo { +/// impl Div for Foo { +/// type Output = Foo; +/// /// fn div(self, _rhs: Foo) -> Foo { /// println!("Dividing!"); /// self @@ -233,14 +267,18 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="div"] -pub trait Div { +pub trait Div { + type Output; + /// The method for the `/` operator - fn div(self, rhs: RHS) -> Result; + fn div(self, rhs: RHS) -> Self::Output; } macro_rules! div_impl { ($($t:ty)*) => ($( - impl Div<$t, $t> for $t { + impl Div for $t { + type Output = $t; + #[inline] fn div(self, other: $t) -> $t { self / other } } @@ -257,12 +295,16 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `rem`, and therefore, `main` prints `Remainder-ing!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::Rem; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl Rem for Foo { +/// impl Rem for Foo { +/// type Output = Foo; +/// /// fn rem(self, _rhs: Foo) -> Foo { /// println!("Remainder-ing!"); /// self @@ -274,14 +316,18 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="rem"] -pub trait Rem { +pub trait Rem { + type Output = Self; + /// The method for the `%` operator - fn rem(self, rhs: RHS) -> Result; + fn rem(self, rhs: RHS) -> Self::Output; } macro_rules! rem_impl { ($($t:ty)*) => ($( - impl Rem<$t, $t> for $t { + impl Rem for $t { + type Output = $t; + #[inline] fn rem(self, other: $t) -> $t { self % other } } @@ -290,7 +336,9 @@ macro_rules! rem_impl { macro_rules! rem_float_impl { ($t:ty, $fmod:ident) => { - impl Rem<$t, $t> for $t { + impl Rem for $t { + type Output = $t; + #[inline] fn rem(self, other: $t) -> $t { extern { fn $fmod(a: $t, b: $t) -> $t; } @@ -312,13 +360,17 @@ rem_float_impl! { f64, fmod } /// `neg`, and therefore, `main` prints `Negating!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::Neg; /// /// struct Foo; /// /// impl Copy for Foo {} /// -/// impl Neg for Foo { +/// impl Neg for Foo { +/// type Output = Foo; +/// /// fn neg(self) -> Foo { /// println!("Negating!"); /// self @@ -330,14 +382,18 @@ rem_float_impl! { f64, fmod } /// } /// ``` #[lang="neg"] -pub trait Neg { +pub trait Neg { + type Output; + /// The method for the unary `-` operator - fn neg(self) -> Result; + fn neg(self) -> Self::Output; } macro_rules! neg_impl { ($($t:ty)*) => ($( - impl Neg<$t> for $t { + impl Neg for $t { + type Output = $t; + #[inline] fn neg(self) -> $t { -self } } @@ -346,7 +402,9 @@ macro_rules! neg_impl { macro_rules! neg_uint_impl { ($t:ty, $t_signed:ty) => { - impl Neg<$t> for $t { + impl Neg for $t { + type Output = $t; + #[inline] fn neg(self) -> $t { -(self as $t_signed) as $t } } @@ -370,13 +428,17 @@ neg_uint_impl! { u64, i64 } /// `not`, and therefore, `main` prints `Not-ing!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::Not; /// /// struct Foo; /// /// impl Copy for Foo {} /// -/// impl Not for Foo { +/// impl Not for Foo { +/// type Output = Foo; +/// /// fn not(self) -> Foo { /// println!("Not-ing!"); /// self @@ -388,14 +450,18 @@ neg_uint_impl! { u64, i64 } /// } /// ``` #[lang="not"] -pub trait Not { +pub trait Not { + type Output; + /// The method for the unary `!` operator - fn not(self) -> Result; + fn not(self) -> Self::Output; } macro_rules! not_impl { ($($t:ty)*) => ($( - impl Not<$t> for $t { + impl Not for $t { + type Output = $t; + #[inline] fn not(self) -> $t { !self } } @@ -412,12 +478,16 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::BitAnd; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl BitAnd for Foo { +/// impl BitAnd for Foo { +/// type Output = Foo; +/// /// fn bitand(self, _rhs: Foo) -> Foo { /// println!("Bitwise And-ing!"); /// self @@ -429,14 +499,18 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="bitand"] -pub trait BitAnd { +pub trait BitAnd { + type Output; + /// The method for the `&` operator - fn bitand(self, rhs: RHS) -> Result; + fn bitand(self, rhs: RHS) -> Self::Output; } macro_rules! bitand_impl { ($($t:ty)*) => ($( - impl BitAnd<$t, $t> for $t { + impl BitAnd for $t { + type Output = $t; + #[inline] fn bitand(self, rhs: $t) -> $t { self & rhs } } @@ -453,12 +527,16 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::BitOr; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl BitOr for Foo { +/// impl BitOr for Foo { +/// type Output = Foo; +/// /// fn bitor(self, _rhs: Foo) -> Foo { /// println!("Bitwise Or-ing!"); /// self @@ -470,14 +548,18 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="bitor"] -pub trait BitOr { +pub trait BitOr { + type Output; + /// The method for the `|` operator - fn bitor(self, rhs: RHS) -> Result; + fn bitor(self, rhs: RHS) -> Self::Output; } macro_rules! bitor_impl { ($($t:ty)*) => ($( - impl BitOr<$t,$t> for $t { + impl BitOr for $t { + type Output = $t; + #[inline] fn bitor(self, rhs: $t) -> $t { self | rhs } } @@ -494,12 +576,16 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::BitXor; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl BitXor for Foo { +/// impl BitXor for Foo { +/// type Output = Foo; +/// /// fn bitxor(self, _rhs: Foo) -> Foo { /// println!("Bitwise Xor-ing!"); /// self @@ -511,14 +597,18 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="bitxor"] -pub trait BitXor { +pub trait BitXor { + type Output; + /// The method for the `^` operator - fn bitxor(self, rhs: RHS) -> Result; + fn bitxor(self, rhs: RHS) -> Self::Output; } macro_rules! bitxor_impl { ($($t:ty)*) => ($( - impl BitXor<$t, $t> for $t { + impl BitXor for $t { + type Output = $t; + #[inline] fn bitxor(self, other: $t) -> $t { self ^ other } } @@ -535,12 +625,16 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `shl`, and therefore, `main` prints `Shifting left!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::Shl; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl Shl for Foo { +/// impl Shl for Foo { +/// type Output = Foo; +/// /// fn shl(self, _rhs: Foo) -> Foo { /// println!("Shifting left!"); /// self @@ -552,14 +646,18 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="shl"] -pub trait Shl { +pub trait Shl { + type Output; + /// The method for the `<<` operator - fn shl(self, rhs: RHS) -> Result; + fn shl(self, rhs: RHS) -> Self::Output; } macro_rules! shl_impl { ($($t:ty)*) => ($( - impl Shl for $t { + impl Shl for $t { + type Output = $t; + #[inline] fn shl(self, other: uint) -> $t { self << other @@ -578,12 +676,16 @@ shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `shr`, and therefore, `main` prints `Shifting right!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::Shr; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl Shr for Foo { +/// impl Shr for Foo { +/// type Output = Foo; +/// /// fn shr(self, _rhs: Foo) -> Foo { /// println!("Shifting right!"); /// self @@ -595,14 +697,18 @@ shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="shr"] -pub trait Shr { +pub trait Shr { + type Output; + /// The method for the `>>` operator - fn shr(self, rhs: RHS) -> Result; + fn shr(self, rhs: RHS) -> Self::Output; } macro_rules! shr_impl { ($($t:ty)*) => ($( - impl Shr for $t { + impl Shr for $t { + type Output = $t; + #[inline] fn shr(self, other: uint) -> $t { self >> other } } @@ -611,6 +717,15 @@ macro_rules! shr_impl { shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } +// NOTE(stage0) remove trait after a snapshot +#[cfg(stage0)] +#[allow(missing_docs)] +#[lang="index"] +pub trait Index for Sized? { + /// The method for the indexing (`Foo[Bar]`) operation + fn index<'a>(&'a self, index: &Index) -> &'a Result; +} + /// The `Index` trait is used to specify the functionality of indexing operations /// like `arr[idx]` when used in an immutable context. /// @@ -620,12 +735,16 @@ shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `index`, and therefore, `main` prints `Indexing!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::Index; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl Index for Foo { +/// impl Index for Foo { +/// type Output = Foo; +/// /// fn index<'a>(&'a self, _index: &Foo) -> &'a Foo { /// println!("Indexing!"); /// self @@ -636,10 +755,22 @@ shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// Foo[Foo]; /// } /// ``` +#[cfg(not(stage0))] // NOTE(stage0) remove cfg after a snapshot #[lang="index"] -pub trait Index for Sized? { +pub trait Index for Sized? { + type Sized? Output; + /// The method for the indexing (`Foo[Bar]`) operation - fn index<'a>(&'a self, index: &Index) -> &'a Result; + fn index<'a>(&'a self, index: &Index) -> &'a Self::Output; +} + +// NOTE(stage0) remove trait after a snapshot +#[cfg(stage0)] +#[allow(missing_docs)] +#[lang="index_mut"] +pub trait IndexMut for Sized? { + /// The method for the indexing (`Foo[Bar]`) operation + fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result; } /// The `IndexMut` trait is used to specify the functionality of indexing @@ -651,12 +782,16 @@ pub trait Index for Sized? { /// calling `index_mut`, and therefore, `main` prints `Indexing!`. /// /// ``` +/// #![feature(associated_types)] +/// /// use std::ops::IndexMut; /// /// #[deriving(Copy)] /// struct Foo; /// -/// impl IndexMut for Foo { +/// impl IndexMut for Foo { +/// type Output = Foo; +/// /// fn index_mut<'a>(&'a mut self, _index: &Foo) -> &'a mut Foo { /// println!("Indexing!"); /// self @@ -667,10 +802,13 @@ pub trait Index for Sized? { /// &mut Foo[Foo]; /// } /// ``` +#[cfg(not(stage0))] // NOTE(stage0) remove cfg after a snapshot #[lang="index_mut"] -pub trait IndexMut for Sized? { +pub trait IndexMut for Sized? { + type Sized? Output; + /// The method for the indexing (`Foo[Bar]`) operation - fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result; + fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Self::Output; } /// The `Slice` trait is used to specify the functionality of slicing operations @@ -789,7 +927,9 @@ pub struct Range { // FIXME(#19391) needs a snapshot //impl> Iterator for Range { -impl Iterator for Range { +impl Iterator for Range { + type Item = Idx; + #[inline] fn next(&mut self) -> Option { if self.start < self.end { @@ -811,7 +951,7 @@ impl Iterator for Range { } } -impl DoubleEndedIterator for Range { +impl DoubleEndedIterator for Range { #[inline] fn next_back(&mut self) -> Option { if self.start < self.end { @@ -823,7 +963,7 @@ impl DoubleEndedIterator for Range { } } -impl ExactSizeIterator for Range {} +impl ExactSizeIterator for Range {} /// A range which is only bounded below. #[deriving(Copy)] @@ -833,7 +973,9 @@ pub struct RangeFrom { pub start: Idx, } -impl Iterator for RangeFrom { +impl Iterator for RangeFrom { + type Item = Idx; + #[inline] fn next(&mut self) -> Option { // Deliberately overflow so we loop forever. diff --git a/src/libcore/option.rs b/src/libcore/option.rs index b9749f57d5832..92209b937d927 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -777,7 +777,9 @@ struct Item { opt: Option } -impl Iterator for Item { +impl Iterator for Item { + type Item = A; + #[inline] fn next(&mut self) -> Option { self.opt.take() @@ -792,32 +794,34 @@ impl Iterator for Item { } } -impl DoubleEndedIterator for Item { +impl DoubleEndedIterator for Item { #[inline] fn next_back(&mut self) -> Option { self.opt.take() } } -impl ExactSizeIterator for Item {} +impl ExactSizeIterator for Item {} /// An iterator over a reference of the contained item in an Option. #[stable] pub struct Iter<'a, A: 'a> { inner: Item<&'a A> } -impl<'a, A> Iterator<&'a A> for Iter<'a, A> { +impl<'a, A> Iterator for Iter<'a, A> { + type Item = &'a A; + #[inline] fn next(&mut self) -> Option<&'a A> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a, A> DoubleEndedIterator<&'a A> for Iter<'a, A> { +impl<'a, A> DoubleEndedIterator for Iter<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a A> { self.inner.next_back() } } -impl<'a, A> ExactSizeIterator<&'a A> for Iter<'a, A> {} +impl<'a, A> ExactSizeIterator for Iter<'a, A> {} #[stable] impl<'a, A> Clone for Iter<'a, A> { @@ -830,37 +834,41 @@ impl<'a, A> Clone for Iter<'a, A> { #[stable] pub struct IterMut<'a, A: 'a> { inner: Item<&'a mut A> } -impl<'a, A> Iterator<&'a mut A> for IterMut<'a, A> { +impl<'a, A> Iterator for IterMut<'a, A> { + type Item = &'a mut A; + #[inline] fn next(&mut self) -> Option<&'a mut A> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> { +impl<'a, A> DoubleEndedIterator for IterMut<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a mut A> { self.inner.next_back() } } -impl<'a, A> ExactSizeIterator<&'a mut A> for IterMut<'a, A> {} +impl<'a, A> ExactSizeIterator for IterMut<'a, A> {} /// An iterator over the item contained inside an Option. #[stable] pub struct IntoIter { inner: Item } -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = A; + #[inline] fn next(&mut self) -> Option { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.inner.next_back() } } -impl ExactSizeIterator for IntoIter {} +impl ExactSizeIterator for IntoIter {} ///////////////////////////////////////////////////////////////////////////// // FromIterator @@ -887,7 +895,7 @@ impl> FromIterator> for Option { /// ``` #[inline] #[stable] - fn from_iter>>(iter: I) -> Option { + fn from_iter>>(iter: I) -> Option { // FIXME(#11084): This could be replaced with Iterator::scan when this // performance bug is closed. @@ -896,7 +904,9 @@ impl> FromIterator> for Option { found_none: bool, } - impl>> Iterator for Adapter { + impl>> Iterator for Adapter { + type Item = T; + #[inline] fn next(&mut self) -> Option { match self.iter.next() { diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 8cb631380095f..1355825e56dfd 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -42,9 +42,9 @@ pub use char::Char; pub use clone::Clone; pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; pub use iter::{Extend, IteratorExt}; -pub use iter::{Iterator, DoubleEndedIterator, DoubleEndedIteratorExt}; +pub use iter::{Iterator, DoubleEndedIterator}; pub use iter::{IteratorCloneExt, CloneIteratorExt}; -pub use iter::{IteratorOrdExt, ExactSizeIterator, IteratorPairExt}; +pub use iter::{IteratorOrdExt, ExactSizeIterator}; pub use option::Option::{mod, Some, None}; pub use ptr::{PtrExt, MutPtrExt}; pub use result::Result::{mod, Ok, Err}; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index bd1c6dbcf1e9a..b0ee5672e060d 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -807,7 +807,9 @@ impl AsSlice for Result { #[stable] pub struct Iter<'a, T: 'a> { inner: Option<&'a T> } -impl<'a, T> Iterator<&'a T> for Iter<'a, T> { +impl<'a, T> Iterator for Iter<'a, T> { + type Item = &'a T; + #[inline] fn next(&mut self) -> Option<&'a T> { self.inner.take() } #[inline] @@ -817,12 +819,12 @@ impl<'a, T> Iterator<&'a T> for Iter<'a, T> { } } -impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { +impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { self.inner.take() } } -impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} +impl<'a, T> ExactSizeIterator for Iter<'a, T> {} impl<'a, T> Clone for Iter<'a, T> { fn clone(&self) -> Iter<'a, T> { Iter { inner: self.inner } } @@ -832,7 +834,9 @@ impl<'a, T> Clone for Iter<'a, T> { #[stable] pub struct IterMut<'a, T: 'a> { inner: Option<&'a mut T> } -impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> { +impl<'a, T> Iterator for IterMut<'a, T> { + type Item = &'a mut T; + #[inline] fn next(&mut self) -> Option<&'a mut T> { self.inner.take() } #[inline] @@ -842,18 +846,20 @@ impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> { } } -impl<'a, T> DoubleEndedIterator<&'a mut T> for IterMut<'a, T> { +impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut T> { self.inner.take() } } -impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {} +impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} /// An iterator over the value in a `Ok` variant of a `Result`. #[stable] pub struct IntoIter { inner: Option } -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = T; + #[inline] fn next(&mut self) -> Option { self.inner.take() } #[inline] @@ -863,12 +869,12 @@ impl Iterator for IntoIter { } } -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.inner.take() } } -impl ExactSizeIterator for IntoIter {} +impl ExactSizeIterator for IntoIter {} ///////////////////////////////////////////////////////////////////////////// // FromIterator @@ -894,7 +900,7 @@ impl> FromIterator> for Result { /// assert!(res == Ok(vec!(2u, 3u))); /// ``` #[inline] - fn from_iter>>(iter: I) -> Result { + fn from_iter>>(iter: I) -> Result { // FIXME(#11084): This could be replaced with Iterator::scan when this // performance bug is closed. @@ -903,7 +909,9 @@ impl> FromIterator> for Result { err: Option, } - impl>> Iterator for Adapter { + impl>> Iterator for Adapter { + type Item = T; + #[inline] fn next(&mut self) -> Option { match self.iter.next() { @@ -941,7 +949,7 @@ pub fn fold V, - Iter: Iterator>>( + Iter: Iterator>>( mut iterator: Iter, mut init: V, mut f: F) diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 07addf7a56969..d5810a382968b 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -531,6 +531,8 @@ impl SliceExt for [T] { } } +// NOTE(stage0) remove impl after a snapshot +#[cfg(stage0)] impl ops::Index for [T] { fn index(&self, &index: &uint) -> &T { assert!(index < self.len()); @@ -539,6 +541,19 @@ impl ops::Index for [T] { } } +#[cfg(not(stage0))] // NOTE(stage0) remove cfg after a snapshot +impl ops::Index for [T] { + type Output = T; + + fn index(&self, &index: &uint) -> &T { + assert!(index < self.len()); + + unsafe { mem::transmute(self.repr().data.offset(index as int)) } + } +} + +// NOTE(stage0) remove impl after a snapshot +#[cfg(stage0)] impl ops::IndexMut for [T] { fn index_mut(&mut self, &index: &uint) -> &mut T { assert!(index < self.len()); @@ -547,6 +562,17 @@ impl ops::IndexMut for [T] { } } +#[cfg(not(stage0))] // NOTE(stage0) remove cfg after a snapshot +impl ops::IndexMut for [T] { + type Output = T; + + fn index_mut(&mut self, &index: &uint) -> &mut T { + assert!(index < self.len()); + + unsafe { mem::transmute(self.repr().data.offset(index as int)) } + } +} + impl ops::Slice for [T] { #[inline] fn as_slice_<'a>(&'a self) -> &'a [T] { @@ -647,7 +673,9 @@ impl<'a, T> Default for &'a [T] { macro_rules! iterator { (struct $name:ident -> $ptr:ty, $elem:ty) => { #[experimental = "needs review"] - impl<'a, T> Iterator<$elem> for $name<'a, T> { + impl<'a, T> Iterator for $name<'a, T> { + type Item = $elem; + #[inline] fn next(&mut self) -> Option<$elem> { // could be implemented with slices, but this avoids bounds checks @@ -683,7 +711,7 @@ macro_rules! iterator { } #[experimental = "needs review"] - impl<'a, T> DoubleEndedIterator<$elem> for $name<'a, T> { + impl<'a, T> DoubleEndedIterator for $name<'a, T> { #[inline] fn next_back(&mut self) -> Option<$elem> { // could be implemented with slices, but this avoids bounds checks @@ -766,7 +794,7 @@ impl<'a,T> Copy for Iter<'a,T> {} iterator!{struct Iter -> *const T, &'a T} #[experimental = "needs review"] -impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} +impl<'a, T> ExactSizeIterator for Iter<'a, T> {} #[stable] impl<'a, T> Clone for Iter<'a, T> { @@ -774,7 +802,7 @@ impl<'a, T> Clone for Iter<'a, T> { } #[experimental = "needs review"] -impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> { +impl<'a, T> RandomAccessIterator for Iter<'a, T> { #[inline] fn indexable(&self) -> uint { let (exact, _) = self.size_hint(); @@ -860,14 +888,14 @@ impl<'a, T> IterMut<'a, T> { iterator!{struct IterMut -> *mut T, &'a mut T} #[experimental = "needs review"] -impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {} +impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} /// An internal abstraction over the splitting iterators, so that /// splitn, splitn_mut etc can be implemented once. -trait SplitIter: DoubleEndedIterator { +trait SplitIter: DoubleEndedIterator { /// Mark the underlying iterator as complete, extracting the remaining /// portion of the slice. - fn finish(&mut self) -> Option; + fn finish(&mut self) -> Option< ::Item>; } /// An iterator over subslices separated by elements that match a predicate @@ -892,7 +920,9 @@ impl<'a, T, P> Clone for Split<'a, T, P> where P: Clone + FnMut(&T) -> bool { } #[experimental = "needs review"] -impl<'a, T, P> Iterator<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool { + type Item = &'a [T]; + #[inline] fn next(&mut self) -> Option<&'a [T]> { if self.finished { return None; } @@ -918,7 +948,7 @@ impl<'a, T, P> Iterator<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool } #[experimental = "needs review"] -impl<'a, T, P> DoubleEndedIterator<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> DoubleEndedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { if self.finished { return None; } @@ -934,7 +964,7 @@ impl<'a, T, P> DoubleEndedIterator<&'a [T]> for Split<'a, T, P> where P: FnMut(& } } -impl<'a, T, P> SplitIter<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> SplitIter for Split<'a, T, P> where P: FnMut(&T) -> bool { #[inline] fn finish(&mut self) -> Option<&'a [T]> { if self.finished { None } else { self.finished = true; Some(self.v) } @@ -950,7 +980,7 @@ pub struct SplitMut<'a, T:'a, P> where P: FnMut(&T) -> bool { finished: bool } -impl<'a, T, P> SplitIter<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> SplitIter for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { #[inline] fn finish(&mut self) -> Option<&'a mut [T]> { if self.finished { @@ -963,7 +993,9 @@ impl<'a, T, P> SplitIter<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) } #[experimental = "needs review"] -impl<'a, T, P> Iterator<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { + type Item = &'a mut [T]; + #[inline] fn next(&mut self) -> Option<&'a mut [T]> { if self.finished { return None; } @@ -996,7 +1028,7 @@ impl<'a, T, P> Iterator<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) - } #[experimental = "needs review"] -impl<'a, T, P> DoubleEndedIterator<&'a mut [T]> for SplitMut<'a, T, P> where +impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool, { #[inline] @@ -1029,9 +1061,11 @@ struct GenericSplitN { } #[experimental = "needs review"] -impl> Iterator for GenericSplitN { +impl> Iterator for GenericSplitN { + type Item = T; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.count == 0 { self.iter.finish() } else { @@ -1075,9 +1109,11 @@ pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { macro_rules! forward_iterator { ($name:ident: $elem:ident, $iter_of:ty) => { - impl<'a, $elem, P> Iterator<$iter_of> for $name<'a, $elem, P> where + impl<'a, $elem, P> Iterator for $name<'a, $elem, P> where P: FnMut(&T) -> bool { + type Item = $iter_of; + #[inline] fn next(&mut self) -> Option<$iter_of> { self.inner.next() @@ -1104,7 +1140,9 @@ pub struct Windows<'a, T:'a> { size: uint } -impl<'a, T> Iterator<&'a [T]> for Windows<'a, T> { +impl<'a, T> Iterator for Windows<'a, T> { + type Item = &'a [T]; + #[inline] fn next(&mut self) -> Option<&'a [T]> { if self.size > self.v.len() { @@ -1140,7 +1178,9 @@ pub struct Chunks<'a, T:'a> { } #[experimental = "needs review"] -impl<'a, T> Iterator<&'a [T]> for Chunks<'a, T> { +impl<'a, T> Iterator for Chunks<'a, T> { + type Item = &'a [T]; + #[inline] fn next(&mut self) -> Option<&'a [T]> { if self.v.len() == 0 { @@ -1167,7 +1207,7 @@ impl<'a, T> Iterator<&'a [T]> for Chunks<'a, T> { } #[experimental = "needs review"] -impl<'a, T> DoubleEndedIterator<&'a [T]> for Chunks<'a, T> { +impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { if self.v.len() == 0 { @@ -1183,7 +1223,7 @@ impl<'a, T> DoubleEndedIterator<&'a [T]> for Chunks<'a, T> { } #[experimental = "needs review"] -impl<'a, T> RandomAccessIterator<&'a [T]> for Chunks<'a, T> { +impl<'a, T> RandomAccessIterator for Chunks<'a, T> { #[inline] fn indexable(&self) -> uint { self.v.len()/self.size + if self.v.len() % self.size != 0 { 1 } else { 0 } @@ -1213,7 +1253,9 @@ pub struct ChunksMut<'a, T:'a> { } #[experimental = "needs review"] -impl<'a, T> Iterator<&'a mut [T]> for ChunksMut<'a, T> { +impl<'a, T> Iterator for ChunksMut<'a, T> { + type Item = &'a mut [T]; + #[inline] fn next(&mut self) -> Option<&'a mut [T]> { if self.v.len() == 0 { @@ -1241,7 +1283,7 @@ impl<'a, T> Iterator<&'a mut [T]> for ChunksMut<'a, T> { } #[experimental = "needs review"] -impl<'a, T> DoubleEndedIterator<&'a mut [T]> for ChunksMut<'a, T> { +impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut [T]> { if self.v.len() == 0 { diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index f4fe86a0d7ec0..7e99e4236083e 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -21,7 +21,7 @@ use self::Searcher::{Naive, TwoWay, TwoWayLong}; use cmp::{mod, Eq}; use default::Default; use iter::range; -use iter::{DoubleEndedIteratorExt, ExactSizeIterator}; +use iter::ExactSizeIterator; use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator}; use kinds::Sized; use mem; @@ -37,7 +37,7 @@ use uint; macro_rules! delegate_iter { (exact $te:ty in $ti:ty) => { delegate_iter!{$te in $ti} - impl<'a> ExactSizeIterator<$te> for $ti { + impl<'a> ExactSizeIterator for $ti { #[inline] fn rposition

(&mut self, predicate: P) -> Option where P: FnMut($te) -> bool{ self.0.rposition(predicate) @@ -49,7 +49,9 @@ macro_rules! delegate_iter { } }; ($te:ty in $ti:ty) => { - impl<'a> Iterator<$te> for $ti { + impl<'a> Iterator for $ti { + type Item = $te; + #[inline] fn next(&mut self) -> Option<$te> { self.0.next() @@ -59,7 +61,7 @@ macro_rules! delegate_iter { self.0.size_hint() } } - impl<'a> DoubleEndedIterator<$te> for $ti { + impl<'a> DoubleEndedIterator for $ti { #[inline] fn next_back(&mut self) -> Option<$te> { self.0.next_back() @@ -67,7 +69,9 @@ macro_rules! delegate_iter { } }; (pattern $te:ty in $ti:ty) => { - impl<'a, P: CharEq> Iterator<$te> for $ti { + impl<'a, P: CharEq> Iterator for $ti { + type Item = $te; + #[inline] fn next(&mut self) -> Option<$te> { self.0.next() @@ -77,7 +81,7 @@ macro_rules! delegate_iter { self.0.size_hint() } } - impl<'a, P: CharEq> DoubleEndedIterator<$te> for $ti { + impl<'a, P: CharEq> DoubleEndedIterator for $ti { #[inline] fn next_back(&mut self) -> Option<$te> { self.0.next_back() @@ -85,7 +89,9 @@ macro_rules! delegate_iter { } }; (pattern forward $te:ty in $ti:ty) => { - impl<'a, P: CharEq> Iterator<$te> for $ti { + impl<'a, P: CharEq> Iterator for $ti { + type Item = $te; + #[inline] fn next(&mut self) -> Option<$te> { self.0.next() @@ -275,7 +281,9 @@ fn unwrap_or_0(opt: Option<&u8>) -> u8 { } } -impl<'a> Iterator for Chars<'a> { +impl<'a> Iterator for Chars<'a> { + type Item = char; + #[inline] fn next(&mut self) -> Option { // Decode UTF-8, using the valid UTF-8 invariant @@ -318,7 +326,7 @@ impl<'a> Iterator for Chars<'a> { } } -impl<'a> DoubleEndedIterator for Chars<'a> { +impl<'a> DoubleEndedIterator for Chars<'a> { #[inline] fn next_back(&mut self) -> Option { let w = match self.iter.next_back() { @@ -359,7 +367,9 @@ pub struct CharIndices<'a> { iter: Chars<'a>, } -impl<'a> Iterator<(uint, char)> for CharIndices<'a> { +impl<'a> Iterator for CharIndices<'a> { + type Item = (uint, char); + #[inline] fn next(&mut self) -> Option<(uint, char)> { let (pre_len, _) = self.iter.iter.size_hint(); @@ -380,7 +390,7 @@ impl<'a> Iterator<(uint, char)> for CharIndices<'a> { } } -impl<'a> DoubleEndedIterator<(uint, char)> for CharIndices<'a> { +impl<'a> DoubleEndedIterator for CharIndices<'a> { #[inline] fn next_back(&mut self) -> Option<(uint, char)> { match self.iter.next_back() { @@ -463,7 +473,9 @@ impl<'a, Sep> CharSplits<'a, Sep> { } } -impl<'a, Sep: CharEq> Iterator<&'a str> for CharSplits<'a, Sep> { +impl<'a, Sep: CharEq> Iterator for CharSplits<'a, Sep> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { if self.finished { return None } @@ -495,8 +507,7 @@ impl<'a, Sep: CharEq> Iterator<&'a str> for CharSplits<'a, Sep> { } } -impl<'a, Sep: CharEq> DoubleEndedIterator<&'a str> -for CharSplits<'a, Sep> { +impl<'a, Sep: CharEq> DoubleEndedIterator for CharSplits<'a, Sep> { #[inline] fn next_back(&mut self) -> Option<&'a str> { if self.finished { return None } @@ -537,7 +548,9 @@ for CharSplits<'a, Sep> { } } -impl<'a, Sep: CharEq> Iterator<&'a str> for CharSplitsN<'a, Sep> { +impl<'a, Sep: CharEq> Iterator for CharSplitsN<'a, Sep> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { if self.count != 0 { @@ -864,7 +877,9 @@ pub struct SplitStr<'a> { #[deprecated = "Type is now named `SplitStr`"] pub type StrSplits<'a> = SplitStr<'a>; -impl<'a> Iterator<(uint, uint)> for MatchIndices<'a> { +impl<'a> Iterator for MatchIndices<'a> { + type Item = (uint, uint); + #[inline] fn next(&mut self) -> Option<(uint, uint)> { match self.searcher { @@ -878,7 +893,9 @@ impl<'a> Iterator<(uint, uint)> for MatchIndices<'a> { } } -impl<'a> Iterator<&'a str> for SplitStr<'a> { +impl<'a> Iterator for SplitStr<'a> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { if self.finished { return None; } @@ -1672,23 +1689,27 @@ impl<'a> Default for &'a str { fn default() -> &'a str { "" } } -impl<'a> Iterator<&'a str> for Lines<'a> { +impl<'a> Iterator for Lines<'a> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a> DoubleEndedIterator<&'a str> for Lines<'a> { +impl<'a> DoubleEndedIterator for Lines<'a> { #[inline] fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() } } -impl<'a> Iterator<&'a str> for LinesAny<'a> { +impl<'a> Iterator for LinesAny<'a> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a> DoubleEndedIterator<&'a str> for LinesAny<'a> { +impl<'a> DoubleEndedIterator for LinesAny<'a> { #[inline] fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() } } diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 7952c96a117cf..b53791f694480 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -561,7 +561,9 @@ fn test_rposition_panic() { #[cfg(test)] -fn check_randacc_iter>(a: T, len: uint) +fn check_randacc_iter(a: T, len: uint) where + A: PartialEq, + T: Clone + RandomAccessIterator + Iterator, { let mut b = a.clone(); assert_eq!(len, b.indexable()); diff --git a/src/libcoretest/num/mod.rs b/src/libcoretest/num/mod.rs index 82e91c5b7120a..274b4cee3ba12 100644 --- a/src/libcoretest/num/mod.rs +++ b/src/libcoretest/num/mod.rs @@ -31,9 +31,9 @@ mod uint; /// Helper function for testing numeric operations pub fn test_num(ten: T, two: T) where T: PartialEq + NumCast - + Add + Sub - + Mul + Div - + Rem + Show + + Add + Sub + + Mul + Div + + Rem + Show + Copy { assert_eq!(ten.add(two), cast(12i).unwrap()); diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index c284fb7c9e338..ecb657b5a2ba5 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -24,6 +24,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![feature(macro_rules, globs, slicing_syntax)] +#![feature(associated_types)] pub use self::Piece::*; pub use self::Position::*; @@ -142,7 +143,9 @@ pub struct Parser<'a> { pub errors: Vec, } -impl<'a> Iterator> for Parser<'a> { +impl<'a> Iterator for Parser<'a> { + type Item = Piece<'a>; + fn next(&mut self) -> Option> { match self.cur.clone().next() { Some((pos, '{')) => { diff --git a/src/libgraphviz/maybe_owned_vec.rs b/src/libgraphviz/maybe_owned_vec.rs index d0396ddc7adcc..901dffc04c5e9 100644 --- a/src/libgraphviz/maybe_owned_vec.rs +++ b/src/libgraphviz/maybe_owned_vec.rs @@ -124,7 +124,7 @@ impl<'b,T> AsSlice for MaybeOwnedVector<'b,T> { impl<'a,T> FromIterator for MaybeOwnedVector<'a,T> { #[allow(deprecated)] - fn from_iter>(iterator: I) -> MaybeOwnedVector<'a,T> { + fn from_iter>(iterator: I) -> MaybeOwnedVector<'a,T> { // If we are building from scratch, might as well build the // most flexible variant. Growable(iterator.collect()) diff --git a/src/librand/lib.rs b/src/librand/lib.rs index e96bf80feef6b..0f8dbc78cde32 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -25,6 +25,7 @@ #![feature(macro_rules, phase, globs)] #![feature(unboxed_closures)] +#![feature(associated_types)] #![no_std] #![experimental] @@ -314,7 +315,9 @@ pub struct Generator<'a, T, R:'a> { rng: &'a mut R, } -impl<'a, T: Rand, R: Rng> Iterator for Generator<'a, T, R> { +impl<'a, T: Rand, R: Rng> Iterator for Generator<'a, T, R> { + type Item = T; + fn next(&mut self) -> Option { Some(self.rng.gen()) } @@ -327,7 +330,9 @@ pub struct AsciiGenerator<'a, R:'a> { rng: &'a mut R, } -impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> { +impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> { + type Item = char; + fn next(&mut self) -> Option { static GEN_ASCII_STR_CHARSET: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\ diff --git a/src/libregex/lib.rs b/src/libregex/lib.rs index 9ad02afee9934..c546477ee0152 100644 --- a/src/libregex/lib.rs +++ b/src/libregex/lib.rs @@ -373,6 +373,7 @@ #![allow(unknown_features)] #![feature(macro_rules, phase, slicing_syntax, globs)] #![feature(unboxed_closures)] +#![feature(associated_types)] #![deny(missing_docs)] #[cfg(test)] diff --git a/src/libregex/re.rs b/src/libregex/re.rs index 3171966a596db..69c58eebd56d0 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -546,7 +546,9 @@ pub enum NamesIter<'a> { NamesIterDynamic(::std::slice::Iter<'a, Option>) } -impl<'a> Iterator> for NamesIter<'a> { +impl<'a> Iterator for NamesIter<'a> { + type Item = Option; + fn next(&mut self) -> Option> { match *self { NamesIterNative(ref mut i) => i.next().map(|x| x.map(|s| s.to_string())), @@ -603,7 +605,9 @@ pub struct RegexSplits<'r, 't> { last: uint, } -impl<'r, 't> Iterator<&'t str> for RegexSplits<'r, 't> { +impl<'r, 't> Iterator for RegexSplits<'r, 't> { + type Item = &'t str; + fn next(&mut self) -> Option<&'t str> { let text = self.finder.search; match self.finder.next() { @@ -638,7 +642,9 @@ pub struct RegexSplitsN<'r, 't> { limit: uint, } -impl<'r, 't> Iterator<&'t str> for RegexSplitsN<'r, 't> { +impl<'r, 't> Iterator for RegexSplitsN<'r, 't> { + type Item = &'t str; + fn next(&mut self) -> Option<&'t str> { let text = self.splits.finder.search; if self.cur >= self.limit { @@ -801,7 +807,9 @@ pub struct SubCaptures<'t> { caps: &'t Captures<'t>, } -impl<'t> Iterator<&'t str> for SubCaptures<'t> { +impl<'t> Iterator for SubCaptures<'t> { + type Item = &'t str; + fn next(&mut self) -> Option<&'t str> { if self.idx < self.caps.len() { self.idx += 1; @@ -824,7 +832,9 @@ pub struct SubCapturesPos<'t> { caps: &'t Captures<'t>, } -impl<'t> Iterator> for SubCapturesPos<'t> { +impl<'t> Iterator for SubCapturesPos<'t> { + type Item = Option<(uint, uint)>; + fn next(&mut self) -> Option> { if self.idx < self.caps.len() { self.idx += 1; @@ -850,7 +860,9 @@ pub struct FindCaptures<'r, 't> { last_end: uint, } -impl<'r, 't> Iterator> for FindCaptures<'r, 't> { +impl<'r, 't> Iterator for FindCaptures<'r, 't> { + type Item = Captures<'t>; + fn next(&mut self) -> Option> { if self.last_end > self.search.len() { return None @@ -893,7 +905,9 @@ pub struct FindMatches<'r, 't> { last_end: uint, } -impl<'r, 't> Iterator<(uint, uint)> for FindMatches<'r, 't> { +impl<'r, 't> Iterator for FindMatches<'r, 't> { + type Item = (uint, uint); + fn next(&mut self) -> Option<(uint, uint)> { if self.last_end > self.search.len() { return None diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs index 0baa5e6c24f22..ebd1cc7e166d7 100644 --- a/src/libregex_macros/lib.rs +++ b/src/libregex_macros/lib.rs @@ -603,7 +603,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str, // Converts `xs` to a `[x1, x2, .., xN]` expression by calling `to_expr` // on each element in `xs`. fn vec_expr(&self, xs: It, mut to_expr: F) -> P where - It: Iterator, + It: Iterator, F: FnMut(&ExtCtxt, T) -> P, { let exprs = xs.map(|x| to_expr(self.cx, x)).collect(); diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index cdc27244dde6e..122171e469108 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -28,6 +28,7 @@ #![feature(rustc_diagnostic_macros)] #![feature(unboxed_closures)] #![feature(old_orphan_check)] +#![feature(associated_types)] extern crate arena; extern crate flate; diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 10383b901f38a..17663a127a881 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -364,7 +364,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext, } } -fn encode_path>(rbml_w: &mut Encoder, path: PI) { +fn encode_path>(rbml_w: &mut Encoder, path: PI) { let path = path.collect::>(); rbml_w.start_tag(tag_path); rbml_w.wr_tagged_u32(tag_path_len, path.len() as u32); diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 92aa70548c82b..a7b28a6323eaf 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -150,7 +150,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } - fn pats_all<'b, I: Iterator<&'b P>>(&mut self, + fn pats_all<'b, I: Iterator>>(&mut self, pats: I, pred: CFGIndex) -> CFGIndex { //! Handles case where all of the patterns must match. @@ -501,7 +501,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } - fn call<'b, I: Iterator<&'b ast::Expr>>(&mut self, + fn call<'b, I: Iterator>(&mut self, call_expr: &ast::Expr, pred: CFGIndex, func_or_rcvr: &ast::Expr, @@ -521,7 +521,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } - fn exprs<'b, I: Iterator<&'b ast::Expr>>(&mut self, + fn exprs<'b, I: Iterator>(&mut self, exprs: I, pred: CFGIndex) -> CFGIndex { //! Constructs graph for `exprs` evaluated in order @@ -535,7 +535,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { opt_expr.iter().fold(pred, |p, e| self.expr(&**e, p)) } - fn straightline<'b, I: Iterator<&'b ast::Expr>>(&mut self, + fn straightline<'b, I: Iterator>(&mut self, expr: &ast::Expr, pred: CFGIndex, subexprs: I) -> CFGIndex { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 9cb8674c3e1b7..74f25332ecf31 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -92,7 +92,7 @@ impl<'a> fmt::Show for Matrix<'a> { } impl<'a> FromIterator> for Matrix<'a> { - fn from_iter>>(iterator: T) -> Matrix<'a> { + fn from_iter>>(iterator: T) -> Matrix<'a> { Matrix(iterator.collect()) } } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 9fc5cb0335313..96b2a62326b17 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -81,7 +81,7 @@ pub fn join(a: constness, b: constness) -> constness { } } -pub fn join_all>(cs: It) -> constness { +pub fn join_all>(cs: It) -> constness { cs.fold(integral_const, |a, b| join(a, b)) } diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index da00d737b473e..e8efdda3888a7 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -305,7 +305,9 @@ pub struct DepthFirstTraversal<'g, N:'g, E:'g> { visited: BitvSet } -impl<'g, N, E> Iterator<&'g N> for DepthFirstTraversal<'g, N, E> { +impl<'g, N, E> Iterator for DepthFirstTraversal<'g, N, E> { + type Item = &'g N; + fn next(&mut self) -> Option<&'g N> { while let Some(idx) = self.stack.pop() { if !self.visited.insert(idx.node_id()) { diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 97e74b9f6bbb9..e7971a82119ec 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -494,7 +494,9 @@ impl<'a,T> EnumeratedItems<'a,T> { } } -impl<'a,T> Iterator<(ParamSpace, uint, &'a T)> for EnumeratedItems<'a,T> { +impl<'a,T> Iterator for EnumeratedItems<'a,T> { + type Item = (ParamSpace, uint, &'a T); + fn next(&mut self) -> Option<(ParamSpace, uint, &'a T)> { let spaces = ParamSpace::all(); if self.space_index < spaces.len() { diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 7da33babaeb60..c6fccab95a4ca 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -292,7 +292,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { stack: Option<&TraitObligationStack<'o, 'tcx>>, mut predicates: I) -> EvaluationResult<'tcx> - where I : Iterator<&'a PredicateObligation<'tcx>>, 'tcx:'a + where I : Iterator>, 'tcx:'a { let mut result = EvaluatedToOk; for obligation in predicates { @@ -2310,9 +2310,9 @@ impl<'o, 'tcx> TraitObligationStack<'o, 'tcx> { } } -impl<'o, 'tcx> Iterator<&'o TraitObligationStack<'o,'tcx>> - for Option<&'o TraitObligationStack<'o, 'tcx>> -{ +impl<'o, 'tcx> Iterator for Option<&'o TraitObligationStack<'o, 'tcx>> { + type Item = &'o TraitObligationStack<'o,'tcx>; + fn next(&mut self) -> Option<&'o TraitObligationStack<'o, 'tcx>> { match *self { Some(o) => { diff --git a/src/librustc/middle/traits/util.rs b/src/librustc/middle/traits/util.rs index 41a59d6a5d846..e4578f7476329 100644 --- a/src/librustc/middle/traits/util.rs +++ b/src/librustc/middle/traits/util.rs @@ -133,7 +133,9 @@ impl<'cx, 'tcx> Elaborator<'cx, 'tcx> { } } -impl<'cx, 'tcx> Iterator> for Elaborator<'cx, 'tcx> { +impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> { + type Item = ty::Predicate<'tcx>; + fn next(&mut self) -> Option> { loop { // Extract next item from top-most stack frame, if any. @@ -197,7 +199,9 @@ pub fn transitive_bounds<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>, elaborate_trait_refs(tcx, bounds).filter_to_traits() } -impl<'cx, 'tcx> Iterator> for Supertraits<'cx, 'tcx> { +impl<'cx, 'tcx> Iterator for Supertraits<'cx, 'tcx> { + type Item = ty::PolyTraitRef<'tcx>; + fn next(&mut self) -> Option> { loop { match self.elaborator.next() { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index c720032bef264..20ded8ad0e0c1 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3259,19 +3259,25 @@ impl TypeContents { } } -impl ops::BitOr for TypeContents { +impl ops::BitOr for TypeContents { + type Output = TypeContents; + fn bitor(self, other: TypeContents) -> TypeContents { TypeContents {bits: self.bits | other.bits} } } -impl ops::BitAnd for TypeContents { +impl ops::BitAnd for TypeContents { + type Output = TypeContents; + fn bitand(self, other: TypeContents) -> TypeContents { TypeContents {bits: self.bits & other.bits} } } -impl ops::Sub for TypeContents { +impl ops::Sub for TypeContents { + type Output = TypeContents; + fn sub(self, other: TypeContents) -> TypeContents { TypeContents {bits: self.bits & !other.bits} } @@ -3740,10 +3746,10 @@ pub fn is_type_representable<'tcx>(cx: &ctxt<'tcx>, sp: Span, ty: Ty<'tcx>) -> Representability { // Iterate until something non-representable is found - fn find_nonrepresentable<'tcx, It: Iterator>>(cx: &ctxt<'tcx>, sp: Span, - seen: &mut Vec>, - iter: It) - -> Representability { + fn find_nonrepresentable<'tcx, It: Iterator>>(cx: &ctxt<'tcx>, sp: Span, + seen: &mut Vec>, + iter: It) + -> Representability { iter.fold(Representable, |r, ty| cmp::max(r, is_type_structurally_recursive(cx, sp, seen, ty))) } diff --git a/src/librustc/middle/ty_walk.rs b/src/librustc/middle/ty_walk.rs index 406ebf4bc38a4..12df36c10fc09 100644 --- a/src/librustc/middle/ty_walk.rs +++ b/src/librustc/middle/ty_walk.rs @@ -94,7 +94,9 @@ impl<'tcx> TypeWalker<'tcx> { } } -impl<'tcx> Iterator> for TypeWalker<'tcx> { +impl<'tcx> Iterator for TypeWalker<'tcx> { + type Item = Ty<'tcx>; + fn next(&mut self) -> Option> { debug!("next(): stack={}", self.stack); match self.stack.pop() { diff --git a/src/librustc/session/search_paths.rs b/src/librustc/session/search_paths.rs index 56b4cae2e43cf..14ea2d3d33a26 100644 --- a/src/librustc/session/search_paths.rs +++ b/src/librustc/session/search_paths.rs @@ -53,7 +53,9 @@ impl SearchPaths { } } -impl<'a> Iterator<&'a Path> for Iter<'a> { +impl<'a> Iterator for Iter<'a> { + type Item = &'a Path; + fn next(&mut self) -> Option<&'a Path> { loop { match self.iter.next() { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index be55da8c59da2..9a993de098ea4 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -26,6 +26,7 @@ #![feature(slicing_syntax, unsafe_destructor)] #![feature(rustc_diagnostic_macros)] #![feature(unboxed_closures)] +#![feature(associated_types)] extern crate arena; extern crate flate; diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index a046d9d5d39c5..561099550cee3 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -345,7 +345,9 @@ enum NodesMatchingUII<'a, 'ast: 'a> { NodesMatchingSuffix(ast_map::NodesMatchingSuffix<'a, 'ast>), } -impl<'a, 'ast> Iterator for NodesMatchingUII<'a, 'ast> { +impl<'a, 'ast> Iterator for NodesMatchingUII<'a, 'ast> { + type Item = ast::NodeId; + fn next(&mut self) -> Option { match self { &NodesMatchingDirect(ref mut iter) => iter.next(), diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 93ff9f53ec12d..c3c97616ea838 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -266,7 +266,7 @@ pub fn sanitize(s: &str) -> String { return result; } -pub fn mangle>(mut path: PI, +pub fn mangle>(mut path: PI, hash: Option<&str>) -> String { // Follow C++ namespace-mangling style, see // http://en.wikipedia.org/wiki/Name_mangling for more info. diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 5ffe9b2d6471a..9dbff66aba286 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -28,6 +28,7 @@ #![feature(rustc_diagnostic_macros)] #![feature(unboxed_closures)] #![feature(old_orphan_check)] +#![feature(associated_types)] extern crate arena; extern crate flate; diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 4c29467d93a44..225f6f116dae3 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -3072,7 +3072,9 @@ fn internalize_symbols(cx: &SharedCrateContext, reachable: &HashSet) { step: unsafe extern "C" fn(ValueRef) -> ValueRef, } - impl Iterator for ValueIter { + impl Iterator for ValueIter { + type Item = ValueRef; + fn next(&mut self) -> Option { let old = self.cur; if !old.is_null() { diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index 9ceb0c6399093..67aecde661891 100644 --- a/src/librustc_trans/trans/context.rs +++ b/src/librustc_trans/trans/context.rs @@ -168,7 +168,9 @@ pub struct CrateContextIterator<'a, 'tcx: 'a> { index: uint, } -impl<'a, 'tcx> Iterator> for CrateContextIterator<'a,'tcx> { +impl<'a, 'tcx> Iterator for CrateContextIterator<'a,'tcx> { + type Item = CrateContext<'a, 'tcx>; + fn next(&mut self) -> Option> { if self.index >= self.shared.local_ccxs.len() { return None; @@ -193,7 +195,9 @@ pub struct CrateContextMaybeIterator<'a, 'tcx: 'a> { origin: uint, } -impl<'a, 'tcx> Iterator<(CrateContext<'a, 'tcx>, bool)> for CrateContextMaybeIterator<'a, 'tcx> { +impl<'a, 'tcx> Iterator for CrateContextMaybeIterator<'a, 'tcx> { + type Item = (CrateContext<'a, 'tcx>, bool); + fn next(&mut self) -> Option<(CrateContext<'a, 'tcx>, bool)> { if self.index >= self.shared.local_ccxs.len() { return None; diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index 99624f1b1e7d8..f0588b3082ab6 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -727,7 +727,7 @@ pub fn get_vtable<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } /// Helper function to declare and initialize the vtable. -pub fn make_vtable>(ccx: &CrateContext, +pub fn make_vtable>(ccx: &CrateContext, drop_glue: ValueRef, size: ValueRef, align: ValueRef, diff --git a/src/librustc_trans/trans/value.rs b/src/librustc_trans/trans/value.rs index 9e959ce4221e7..028e2154303e2 100644 --- a/src/librustc_trans/trans/value.rs +++ b/src/librustc_trans/trans/value.rs @@ -155,7 +155,9 @@ pub struct Users { next: Option } -impl Iterator for Users { +impl Iterator for Users { + type Item = Value; + fn next(&mut self) -> Option { let current = self.next; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 82525b71052d2..7f1feb9365a8f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2543,7 +2543,6 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, } let input_ty = fcx.infcx().next_ty_var(); - let return_ty = fcx.infcx().next_ty_var(); // Try `IndexMut` first, if preferred. let method = match (lvalue_pref, fcx.tcx().lang_items.index_mut_trait()) { @@ -2555,7 +2554,7 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, trait_did, adjustment.clone(), adjusted_ty, - Some(vec![input_ty, return_ty])) + Some(vec![input_ty])) } _ => None, }; @@ -2570,7 +2569,7 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, trait_did, adjustment, adjusted_ty, - Some(vec![input_ty, return_ty])) + Some(vec![input_ty])) } (method, _) => method, }; @@ -2578,9 +2577,9 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, // If some lookup succeeds, write callee into table and extract index/element // type from the method signature. // If some lookup succeeded, install method in table - method.map(|method| { - make_overloaded_lvalue_return_type(fcx, Some(method_call), Some(method)); - (input_ty, return_ty) + method.and_then(|method| { + make_overloaded_lvalue_return_type(fcx, Some(method_call), Some(method)). + map(|ret| (input_ty, ret.ty)) }) } diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index e97a29ec458c7..6b5f08e22ddab 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -922,11 +922,11 @@ fn constrain_callee(rcx: &mut Rcx, } } -fn constrain_call<'a, I: Iterator<&'a ast::Expr>>(rcx: &mut Rcx, - call_expr: &ast::Expr, - receiver: Option<&ast::Expr>, - mut arg_exprs: I, - implicitly_ref_args: bool) { +fn constrain_call<'a, I: Iterator>(rcx: &mut Rcx, + call_expr: &ast::Expr, + receiver: Option<&ast::Expr>, + mut arg_exprs: I, + implicitly_ref_args: bool) { //! Invoked on every call site (i.e., normal calls, method calls, //! and overloaded operators). Constrains the regions which appear //! in the type of the function. Also constrains the regions that diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index fe61b3de2cf6f..8c2cb557c1c9d 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -428,7 +428,7 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>, untransformed_rcvr_ty: Ty<'tcx>, rcvr_ty_generics: &ty::Generics<'tcx>, rcvr_visibility: ast::Visibility) - where I: Iterator<&'i ast::Method> { + where I: Iterator { debug!("convert_methods(untransformed_rcvr_ty={}, rcvr_ty_generics={})", untransformed_rcvr_ty.repr(ccx.tcx), rcvr_ty_generics.repr(ccx.tcx)); diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 353db82eb027d..cc5b1f635e370 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -104,9 +104,6 @@ use syntax::print::pprust::*; use syntax::{ast, ast_map, abi}; use syntax::ast_util::local_def; -#[cfg(stage0)] -mod diagnostics; - mod check; mod rscope; mod astconv; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 1beeeaf629dbf..f0feb8de1cefa 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -21,6 +21,7 @@ #![feature(globs, macro_rules, phase, slicing_syntax)] #![feature(unboxed_closures)] #![feature(old_orphan_check)] +#![feature(associated_types)] extern crate arena; extern crate getopts; diff --git a/src/librustdoc/stability_summary.rs b/src/librustdoc/stability_summary.rs index 058a7acd4550b..0d6d7a47c8579 100644 --- a/src/librustdoc/stability_summary.rs +++ b/src/librustdoc/stability_summary.rs @@ -41,7 +41,9 @@ pub struct Counts { pub unmarked: uint, } -impl Add for Counts { +impl Add for Counts { + type Output = Counts; + fn add(self, other: Counts) -> Counts { Counts { deprecated: self.deprecated + other.deprecated, diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index a87044bb3b3ba..71117c7fe128f 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1123,12 +1123,25 @@ impl Json { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a> ops::Index<&'a str, Json> for Json { fn index(&self, idx: & &str) -> &Json { self.find(*idx).unwrap() } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a> ops::Index<&'a str> for Json { + type Output = Json; + + fn index(&self, idx: & &str) -> &Json { + self.find(*idx).unwrap() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl ops::Index for Json { fn index<'a>(&'a self, idx: &uint) -> &'a Json { match self { @@ -1138,6 +1151,18 @@ impl ops::Index for Json { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl ops::Index for Json { + type Output = Json; + + fn index<'a>(&'a self, idx: &uint) -> &'a Json { + match self { + &Json::Array(ref v) => v.index(idx), + _ => panic!("can only index Json with uint if it is an array") + } + } +} + /// The output of the streaming parser. #[deriving(PartialEq, Clone, Show)] pub enum JsonEvent { @@ -1324,7 +1349,9 @@ pub struct Parser { state: ParserState, } -impl> Iterator for Parser { +impl> Iterator for Parser { + type Item = JsonEvent; + fn next(&mut self) -> Option { if self.state == ParseFinished { return None; @@ -1345,7 +1372,7 @@ impl> Iterator for Parser { } } -impl> Parser { +impl> Parser { /// Creates the JSON parser. pub fn new(rdr: T) -> Parser { let mut p = Parser { @@ -1867,7 +1894,7 @@ pub struct Builder { token: Option, } -impl> Builder { +impl> Builder { /// Create a JSON Builder. pub fn new(src: T) -> Builder { Builder { parser: Parser::new(src), token: None, } diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 4a2bbbeec03a4..1ec6a2af309a7 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -25,6 +25,7 @@ Core encoding and decoding interfaces. #![allow(unknown_features)] #![feature(macro_rules, default_type_params, phase, slicing_syntax, globs)] #![feature(unboxed_closures)] +#![feature(associated_types)] // test harness access #[cfg(test)] diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index c07531d3f32d6..16bc6b16598e0 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -209,7 +209,9 @@ macro_rules! bitflags { } } - impl ::std::ops::BitOr<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::BitOr for $BitFlags { + type Output = $BitFlags; + /// Returns the union of the two sets of flags. #[inline] fn bitor(self, other: $BitFlags) -> $BitFlags { @@ -217,7 +219,9 @@ macro_rules! bitflags { } } - impl ::std::ops::BitXor<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::BitXor for $BitFlags { + type Output = $BitFlags; + /// Returns the left flags, but with all the right flags toggled. #[inline] fn bitxor(self, other: $BitFlags) -> $BitFlags { @@ -225,7 +229,9 @@ macro_rules! bitflags { } } - impl ::std::ops::BitAnd<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::BitAnd for $BitFlags { + type Output = $BitFlags; + /// Returns the intersection between the two sets of flags. #[inline] fn bitand(self, other: $BitFlags) -> $BitFlags { @@ -233,7 +239,9 @@ macro_rules! bitflags { } } - impl ::std::ops::Sub<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::Sub for $BitFlags { + type Output = $BitFlags; + /// Returns the set difference of the two sets of flags. #[inline] fn sub(self, other: $BitFlags) -> $BitFlags { @@ -241,7 +249,9 @@ macro_rules! bitflags { } } - impl ::std::ops::Not<$BitFlags> for $BitFlags { + impl ::std::ops::Not for $BitFlags { + type Output = $BitFlags; + /// Returns the complement of this set of flags. #[inline] fn not(self) -> $BitFlags { diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index b1433ad7fdc62..834a9f082d03a 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -504,7 +504,9 @@ pub struct CChars<'a> { marker: marker::ContravariantLifetime<'a>, } -impl<'a> Iterator for CChars<'a> { +impl<'a> Iterator for CChars<'a> { + type Item = libc::c_char; + fn next(&mut self) -> Option { let ch = unsafe { *self.ptr }; if ch == 0 { diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index d4fc4150fae91..f246e9df3b987 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1300,6 +1300,8 @@ impl, V, S, H: Hasher + Default> Default for HashMap } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl + Eq, Sized? Q, V, S, H: Hasher> Index for HashMap where Q: BorrowFrom + Hash + Eq @@ -1310,6 +1312,21 @@ impl + Eq, Sized? Q, V, S, H: Hasher> Index for HashMap + Eq, Sized? Q, V, S, H: Hasher> Index for HashMap + where Q: BorrowFrom + Hash + Eq +{ + type Output = V; + + #[inline] + fn index<'a>(&'a self, index: &Q) -> &'a V { + self.get(index).expect("no entry found for key") + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl + Eq, Sized? Q, V, S, H: Hasher> IndexMut for HashMap where Q: BorrowFrom + Hash + Eq @@ -1320,6 +1337,19 @@ impl + Eq, Sized? Q, V, S, H: Hasher> IndexMut for HashMap + Eq, Sized? Q, V, S, H: Hasher> IndexMut for HashMap + where Q: BorrowFrom + Hash + Eq +{ + type Output = V; + + #[inline] + fn index_mut<'a>(&'a mut self, index: &Q) -> &'a mut V { + self.get_mut(index).expect("no entry found for key") + } +} + /// HashMap iterator #[stable] pub struct Iter<'a, K: 'a, V: 'a> { @@ -1423,37 +1453,49 @@ enum VacantEntryState { } #[stable] -impl<'a, K, V> Iterator<(&'a K, &'a V)> for Iter<'a, K, V> { +impl<'a, K, V> Iterator for Iter<'a, K, V> { + type Item = (&'a K, &'a V); + #[inline] fn next(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { +impl<'a, K, V> Iterator for IterMut<'a, K, V> { + type Item = (&'a K, &'a mut V); + #[inline] fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl Iterator<(K, V)> for IntoIter { +impl Iterator for IntoIter { + type Item = (K, V); + #[inline] fn next(&mut self) -> Option<(K, V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl<'a, K, V> Iterator<&'a K> for Keys<'a, K, V> { +impl<'a, K, V> Iterator for Keys<'a, K, V> { + type Item = &'a K; + #[inline] fn next(&mut self) -> Option<(&'a K)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl<'a, K, V> Iterator<&'a V> for Values<'a, K, V> { +impl<'a, K, V> Iterator for Values<'a, K, V> { + type Item = &'a V; + #[inline] fn next(&mut self) -> Option<(&'a V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } #[stable] -impl<'a, K: 'a, V: 'a> Iterator<(K, V)> for Drain<'a, K, V> { +impl<'a, K: 'a, V: 'a> Iterator for Drain<'a, K, V> { + type Item = (K, V); + #[inline] fn next(&mut self) -> Option<(K, V)> { self.inner.next() @@ -1511,7 +1553,7 @@ impl<'a, K, V> VacantEntry<'a, K, V> { #[stable] impl, V, S, H: Hasher + Default> FromIterator<(K, V)> for HashMap { - fn from_iter>(iter: T) -> HashMap { + fn from_iter>(iter: T) -> HashMap { let lower = iter.size_hint().0; let mut map = HashMap::with_capacity_and_hasher(lower, Default::default()); map.extend(iter); @@ -1521,7 +1563,7 @@ impl, V, S, H: Hasher + Default> FromIterator<(K, V)> for Has #[stable] impl, V, S, H: Hasher + Default> Extend<(K, V)> for HashMap { - fn extend>(&mut self, mut iter: T) { + fn extend>(&mut self, mut iter: T) { for (k, v) in iter { self.insert(k, v); } diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 6132d288da279..4c6a74a78d510 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -603,7 +603,7 @@ impl + fmt::Show, S, H: Hasher> fmt::Show for HashSet { #[stable] impl, S, H: Hasher + Default> FromIterator for HashSet { - fn from_iter>(iter: I) -> HashSet { + fn from_iter>(iter: I) -> HashSet { let lower = iter.size_hint().0; let mut set = HashSet::with_capacity_and_hasher(lower, Default::default()); set.extend(iter); @@ -613,7 +613,7 @@ impl, S, H: Hasher + Default> FromIterator for HashSet, S, H: Hasher + Default> Extend for HashSet { - fn extend>(&mut self, mut iter: I) { + fn extend>(&mut self, mut iter: I) { for k in iter { self.insert(k); } @@ -630,7 +630,9 @@ impl, S, H: Hasher + Default> Default for HashSet { #[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> -BitOr<&'b HashSet, HashSet> for &'a HashSet { +BitOr<&'b HashSet> for &'a HashSet { + type Output = HashSet; + /// Returns the union of `self` and `rhs` as a new `HashSet`. /// /// # Examples @@ -658,7 +660,9 @@ BitOr<&'b HashSet, HashSet> for &'a HashSet { #[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> -BitAnd<&'b HashSet, HashSet> for &'a HashSet { +BitAnd<&'b HashSet> for &'a HashSet { + type Output = HashSet; + /// Returns the intersection of `self` and `rhs` as a new `HashSet`. /// /// # Examples @@ -686,7 +690,9 @@ BitAnd<&'b HashSet, HashSet> for &'a HashSet { #[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> -BitXor<&'b HashSet, HashSet> for &'a HashSet { +BitXor<&'b HashSet> for &'a HashSet { + type Output = HashSet; + /// Returns the symmetric difference of `self` and `rhs` as a new `HashSet`. /// /// # Examples @@ -714,7 +720,9 @@ BitXor<&'b HashSet, HashSet> for &'a HashSet { #[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> -Sub<&'b HashSet, HashSet> for &'a HashSet { +Sub<&'b HashSet> for &'a HashSet { + type Output = HashSet; + /// Returns the difference of `self` and `rhs` as a new `HashSet`. /// /// # Examples @@ -789,27 +797,35 @@ pub struct Union<'a, T: 'a, H: 'a> { } #[stable] -impl<'a, K> Iterator<&'a K> for Iter<'a, K> { +impl<'a, K> Iterator for Iter<'a, K> { + type Item = &'a K; + fn next(&mut self) -> Option<&'a K> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[stable] -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = K; + fn next(&mut self) -> Option { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[stable] -impl<'a, K: 'a> Iterator for Drain<'a, K> { +impl<'a, K: 'a> Iterator for Drain<'a, K> { + type Item = K; + fn next(&mut self) -> Option { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[stable] -impl<'a, T, S, H> Iterator<&'a T> for Intersection<'a, T, H> +impl<'a, T, S, H> Iterator for Intersection<'a, T, H> where T: Eq + Hash, H: Hasher { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { loop { match self.iter.next() { @@ -828,9 +844,11 @@ impl<'a, T, S, H> Iterator<&'a T> for Intersection<'a, T, H> } #[stable] -impl<'a, T, S, H> Iterator<&'a T> for Difference<'a, T, H> +impl<'a, T, S, H> Iterator for Difference<'a, T, H> where T: Eq + Hash, H: Hasher { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { loop { match self.iter.next() { @@ -849,17 +867,21 @@ impl<'a, T, S, H> Iterator<&'a T> for Difference<'a, T, H> } #[stable] -impl<'a, T, S, H> Iterator<&'a T> for SymmetricDifference<'a, T, H> +impl<'a, T, S, H> Iterator for SymmetricDifference<'a, T, H> where T: Eq + Hash, H: Hasher { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[stable] -impl<'a, T, S, H> Iterator<&'a T> for Union<'a, T, H> +impl<'a, T, S, H> Iterator for Union<'a, T, H> where T: Eq + Hash, H: Hasher { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index a687ba3da8d7f..2b999d83a98c2 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -730,7 +730,9 @@ impl<'a, K, V> Clone for RawBuckets<'a, K, V> { } -impl<'a, K, V> Iterator> for RawBuckets<'a, K, V> { +impl<'a, K, V> Iterator for RawBuckets<'a, K, V> { + type Item = RawBucket; + fn next(&mut self) -> Option> { while self.raw.hash != self.hashes_end { unsafe { @@ -757,7 +759,9 @@ struct RevMoveBuckets<'a, K, V> { marker: marker::ContravariantLifetime<'a>, } -impl<'a, K, V> Iterator<(K, V)> for RevMoveBuckets<'a, K, V> { +impl<'a, K, V> Iterator for RevMoveBuckets<'a, K, V> { + type Item = (K, V); + fn next(&mut self) -> Option<(K, V)> { if self.elems_left == 0 { return None; @@ -816,7 +820,9 @@ pub struct Drain<'a, K: 'a, V: 'a> { iter: RawBuckets<'static, K, V>, } -impl<'a, K, V> Iterator<(&'a K, &'a V)> for Iter<'a, K, V> { +impl<'a, K, V> Iterator for Iter<'a, K, V> { + type Item = (&'a K, &'a V); + fn next(&mut self) -> Option<(&'a K, &'a V)> { self.iter.next().map(|bucket| { self.elems_left -= 1; @@ -832,7 +838,9 @@ impl<'a, K, V> Iterator<(&'a K, &'a V)> for Iter<'a, K, V> { } } -impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { +impl<'a, K, V> Iterator for IterMut<'a, K, V> { + type Item = (&'a K, &'a mut V); + fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.iter.next().map(|bucket| { self.elems_left -= 1; @@ -848,7 +856,9 @@ impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { } } -impl Iterator<(SafeHash, K, V)> for IntoIter { +impl Iterator for IntoIter { + type Item = (SafeHash, K, V); + fn next(&mut self) -> Option<(SafeHash, K, V)> { self.iter.next().map(|bucket| { self.table.size -= 1; @@ -870,7 +880,9 @@ impl Iterator<(SafeHash, K, V)> for IntoIter { } } -impl<'a, K: 'a, V: 'a> Iterator<(SafeHash, K, V)> for Drain<'a, K, V> { +impl<'a, K: 'a, V: 'a> Iterator for Drain<'a, K, V> { + type Item = (SafeHash, K, V); + #[inline] fn next(&mut self) -> Option<(SafeHash, K, V)> { self.iter.next().map(|bucket| { diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index 94dba1f7cc70a..8c097a65db7bd 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -52,7 +52,9 @@ impl<'r, R: Reader> Bytes<'r, R> { } } -impl<'r, R: Reader> Iterator> for Bytes<'r, R> { +impl<'r, R: Reader> Iterator for Bytes<'r, R> { + type Item = IoResult; + #[inline] fn next(&mut self) -> Option> { match self.reader.read_byte() { diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 7fa5b3cfac7e2..1ff54fcb48432 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -563,7 +563,9 @@ pub struct Directories { stack: Vec, } -impl Iterator for Directories { +impl Iterator for Directories { + type Item = Path; + fn next(&mut self) -> Option { match self.stack.pop() { Some(path) => { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 0a7815aeb5367..917ffa4ff76da 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1036,7 +1036,6 @@ pub trait Writer { error: IoResult<()>, } - #[cfg(not(stage0))] impl<'a, Sized? T: Writer> fmt::Writer for Adaptor<'a, T> { fn write_str(&mut self, s: &str) -> fmt::Result { match self.inner.write(s.as_bytes()) { @@ -1049,19 +1048,6 @@ pub trait Writer { } } - #[cfg(stage0)] - impl<'a, T: Writer> fmt::Writer for Adaptor<'a, T> { - fn write_str(&mut self, s: &str) -> fmt::Result { - match self.inner.write(s.as_bytes()) { - Ok(()) => Ok(()), - Err(e) => { - self.error = Err(e); - Err(fmt::Error) - } - } - } - } - let mut output = Adaptor { inner: self, error: Ok(()) }; match fmt::write(&mut output, fmt) { Ok(()) => Ok(()), @@ -1371,7 +1357,9 @@ pub struct Lines<'r, T:'r> { buffer: &'r mut T, } -impl<'r, T: Buffer> Iterator> for Lines<'r, T> { +impl<'r, T: Buffer> Iterator for Lines<'r, T> { + type Item = IoResult; + fn next(&mut self) -> Option> { match self.buffer.read_line() { Ok(x) => Some(Ok(x)), @@ -1398,7 +1386,9 @@ pub struct Chars<'r, T:'r> { buffer: &'r mut T } -impl<'r, T: Buffer> Iterator> for Chars<'r, T> { +impl<'r, T: Buffer> Iterator for Chars<'r, T> { + type Item = IoResult; + fn next(&mut self) -> Option> { match self.buffer.read_char() { Ok(x) => Some(Ok(x)), @@ -1648,15 +1638,9 @@ pub struct IncomingConnections<'a, Sized? A:'a> { inc: &'a mut A, } -#[cfg(stage0)] -impl<'a, T, A: Acceptor> Iterator> for IncomingConnections<'a, A> { - fn next(&mut self) -> Option> { - Some(self.inc.accept()) - } -} +impl<'a, T, Sized? A: Acceptor> Iterator for IncomingConnections<'a, A> { + type Item = IoResult; -#[cfg(not(stage0))] -impl<'a, T, Sized? A: Acceptor> Iterator> for IncomingConnections<'a, A> { fn next(&mut self) -> Option> { Some(self.inc.accept()) } diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 38ab71c172c59..51d1bacf63b9f 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -169,7 +169,7 @@ pub struct ChainedReader { cur_reader: Option, } -impl> ChainedReader { +impl> ChainedReader { /// Creates a new `ChainedReader` pub fn new(mut readers: I) -> ChainedReader { let r = readers.next(); @@ -177,7 +177,7 @@ impl> ChainedReader { } } -impl> Reader for ChainedReader { +impl> Reader for ChainedReader { fn read(&mut self, buf: &mut [u8]) -> io::IoResult { loop { let err = match self.cur_reader { @@ -252,7 +252,7 @@ pub struct IterReader { iter: T, } -impl> IterReader { +impl> IterReader { /// Creates a new `IterReader` which will read from the specified /// `Iterator`. pub fn new(iter: T) -> IterReader { @@ -260,7 +260,7 @@ impl> IterReader { } } -impl> Reader for IterReader { +impl> Reader for IterReader { #[inline] fn read(&mut self, buf: &mut [u8]) -> io::IoResult { let mut len = 0; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 01aa21c692bf5..007d89a942dcc 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -127,9 +127,9 @@ pub fn abs_sub(x: T, y: T) -> T { #[cfg(test)] pub fn test_num(ten: T, two: T) where T: PartialEq + NumCast - + Add + Sub - + Mul + Div - + Rem + Show + + Add + Sub + + Mul + Div + + Rem + Show + Copy { assert_eq!(ten.add(two), cast(12i).unwrap()); diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 6075010f3b5ff..39b96ef6aeea0 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -15,7 +15,7 @@ use clone::Clone; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use hash; use io::Writer; -use iter::{DoubleEndedIteratorExt, AdditiveIterator, Extend}; +use iter::{AdditiveIterator, Extend}; use iter::{Iterator, IteratorExt, Map}; use option::Option; use option::Option::{None, Some}; @@ -449,7 +449,7 @@ mod tests { use super::*; use clone::Clone; - use iter::{IteratorExt, DoubleEndedIteratorExt}; + use iter::IteratorExt; use option::Option::{mod, Some, None}; use path::GenericPath; use slice::{AsSlice, SliceExt}; diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 55086ad3a23f9..f6fb149e82cf6 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -20,7 +20,7 @@ use clone::Clone; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use hash; use io::Writer; -use iter::{AdditiveIterator, DoubleEndedIteratorExt, Extend}; +use iter::{AdditiveIterator, Extend}; use iter::{Iterator, IteratorExt, Map, repeat}; use mem; use option::Option; @@ -1124,7 +1124,7 @@ mod tests { use super::*; use clone::Clone; - use iter::{IteratorExt, DoubleEndedIteratorExt}; + use iter::IteratorExt; use option::Option::{mod, Some, None}; use path::GenericPath; use slice::{AsSlice, SliceExt}; diff --git a/src/libstd/prelude/mod.rs b/src/libstd/prelude/mod.rs index da945b4c9fa08..1fbd17ede08f2 100644 --- a/src/libstd/prelude/mod.rs +++ b/src/libstd/prelude/mod.rs @@ -35,8 +35,5 @@ //! pervasive that it would be obnoxious to import for every use, particularly //! those that define methods on primitive types. -#[cfg(stage0)] -pub use self::v1::*; - #[stable] pub mod v1; diff --git a/src/libstd/prelude/v1.rs b/src/libstd/prelude/v1.rs index cb5dfafb4a123..2d2f3f895d0c1 100644 --- a/src/libstd/prelude/v1.rs +++ b/src/libstd/prelude/v1.rs @@ -27,11 +27,9 @@ #[stable] #[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; #[stable] #[doc(no_inline)] pub use iter::CloneIteratorExt; #[stable] #[doc(no_inline)] pub use iter::DoubleEndedIterator; -#[stable] #[doc(no_inline)] pub use iter::DoubleEndedIteratorExt; #[stable] #[doc(no_inline)] pub use iter::ExactSizeIterator; #[stable] #[doc(no_inline)] pub use iter::{Iterator, IteratorExt, Extend}; #[stable] #[doc(no_inline)] pub use iter::{IteratorCloneExt, IteratorOrdExt}; -#[stable] #[doc(no_inline)] pub use iter::IteratorPairExt; #[stable] #[doc(no_inline)] pub use option::Option::{mod, Some, None}; #[stable] #[doc(no_inline)] pub use ptr::{PtrExt, MutPtrExt}; #[stable] #[doc(no_inline)] pub use result::Result::{mod, Ok, Err}; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 86b8bfc73709d..208e4f9e566f4 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -404,7 +404,7 @@ pub fn random() -> T { /// let sample = sample(&mut rng, range(1i, 100), 5); /// println!("{}", sample); /// ``` -pub fn sample, R: Rng>(rng: &mut R, +pub fn sample, R: Rng>(rng: &mut R, mut iter: I, amount: uint) -> Vec { let mut reservoir: Vec = iter.by_ref().take(amount).collect(); diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 413675f26d59c..e9dc3d986ba11 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -936,7 +936,9 @@ impl select::Packet for Receiver { } #[unstable] -impl<'a, T: Send> Iterator for Iter<'a, T> { +impl<'a, T: Send> Iterator for Iter<'a, T> { + type Item = T; + fn next(&mut self) -> Option { self.rx.recv().ok() } } diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index 43554d7c335a4..3d9dca7e21cb3 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -319,7 +319,9 @@ impl<'rx, T: Send> Drop for Handle<'rx, T> { } } -impl Iterator<*mut Handle<'static, ()>> for Packets { +impl Iterator for Packets { + type Item = *mut Handle<'static, ()>; + fn next(&mut self) -> Option<*mut Handle<'static, ()>> { if self.cur.is_null() { None diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 51564b539768d..41a130492c047 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -262,7 +262,9 @@ impl Duration { } } -impl Neg for Duration { +impl Neg for Duration { + type Output = Duration; + #[inline] fn neg(self) -> Duration { if self.nanos == 0 { @@ -273,7 +275,9 @@ impl Neg for Duration { } } -impl Add for Duration { +impl Add for Duration { + type Output = Duration; + fn add(self, rhs: Duration) -> Duration { let mut secs = self.secs + rhs.secs; let mut nanos = self.nanos + rhs.nanos; @@ -285,7 +289,9 @@ impl Add for Duration { } } -impl Sub for Duration { +impl Sub for Duration { + type Output = Duration; + fn sub(self, rhs: Duration) -> Duration { let mut secs = self.secs - rhs.secs; let mut nanos = self.nanos - rhs.nanos; @@ -297,7 +303,9 @@ impl Sub for Duration { } } -impl Mul for Duration { +impl Mul for Duration { + type Output = Duration; + fn mul(self, rhs: i32) -> Duration { // Multiply nanoseconds as i64, because it cannot overflow that way. let total_nanos = self.nanos as i64 * rhs as i64; @@ -307,7 +315,9 @@ impl Mul for Duration { } } -impl Div for Duration { +impl Div for Duration { + type Output = Duration; + fn div(self, rhs: i32) -> Duration { let mut secs = self.secs / rhs as i64; let carry = self.secs - secs * rhs as i64; diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index b5395d09ca7d4..b1799fc2718ff 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -61,7 +61,9 @@ struct LinkedPathNode<'a> { type LinkedPath<'a> = Option<&'a LinkedPathNode<'a>>; -impl<'a> Iterator for LinkedPath<'a> { +impl<'a> Iterator for LinkedPath<'a> { + type Item = PathElem; + fn next(&mut self) -> Option { match *self { Some(node) => { @@ -77,7 +79,9 @@ impl<'a> Iterator for LinkedPath<'a> { #[deriving(Clone)] pub struct Values<'a, T:'a>(pub slice::Iter<'a, T>); -impl<'a, T: Copy> Iterator for Values<'a, T> { +impl<'a, T: Copy> Iterator for Values<'a, T> { + type Item = T; + fn next(&mut self) -> Option { let &Values(ref mut items) = self; items.next().map(|&x| x) @@ -87,7 +91,7 @@ impl<'a, T: Copy> Iterator for Values<'a, T> { /// The type of the iterator used by with_path. pub type PathElems<'a, 'b> = iter::Chain, LinkedPath<'b>>; -pub fn path_to_string>(path: PI) -> String { +pub fn path_to_string>(path: PI) -> String { let itr = token::get_ident_interner(); path.fold(String::new(), |mut s, e| { @@ -629,7 +633,9 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> { } } -impl<'a, 'ast> Iterator for NodesMatchingSuffix<'a, 'ast> { +impl<'a, 'ast> Iterator for NodesMatchingSuffix<'a, 'ast> { + type Item = NodeId; + fn next(&mut self) -> Option { loop { let idx = self.idx; diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index df820b40cb6de..92818f0634160 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -359,7 +359,7 @@ pub enum StabilityLevel { pub fn find_stability_generic<'a, AM: AttrMetaMethods, - I: Iterator<&'a AM>> + I: Iterator> (mut attrs: I) -> Option<(Stability, &'a AM)> { for attr in attrs { diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 5eac6546c6b82..eb011faa55dc8 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -53,13 +53,17 @@ impl Pos for BytePos { fn to_uint(&self) -> uint { let BytePos(n) = *self; n as uint } } -impl Add for BytePos { +impl Add for BytePos { + type Output = BytePos; + fn add(self, rhs: BytePos) -> BytePos { BytePos((self.to_uint() + rhs.to_uint()) as u32) } } -impl Sub for BytePos { +impl Sub for BytePos { + type Output = BytePos; + fn sub(self, rhs: BytePos) -> BytePos { BytePos((self.to_uint() - rhs.to_uint()) as u32) } @@ -70,13 +74,17 @@ impl Pos for CharPos { fn to_uint(&self) -> uint { let CharPos(n) = *self; n } } -impl Add for CharPos { +impl Add for CharPos { + type Output = CharPos; + fn add(self, rhs: CharPos) -> CharPos { CharPos(self.to_uint() + rhs.to_uint()) } } -impl Sub for CharPos { +impl Sub for CharPos { + type Output = CharPos; + fn sub(self, rhs: CharPos) -> CharPos { CharPos(self.to_uint() - rhs.to_uint()) } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index efb4867a016be..e56194c95cd5b 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -220,7 +220,7 @@ pub struct MacItems { } impl MacItems { - pub fn new>>(it: I) -> Box { + pub fn new>>(it: I) -> Box { box MacItems { items: it.collect() } as Box } } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index deed0b78e87e4..8af5e952e9a11 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -106,7 +106,9 @@ enum LockstepIterSize { LisContradiction(String), } -impl Add for LockstepIterSize { +impl Add for LockstepIterSize { + type Output = LockstepIterSize; + fn add(self, other: LockstepIterSize) -> LockstepIterSize { match self { LisUnconstrained => other, diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index bc2e09231159a..38c26e8967140 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -77,7 +77,7 @@ impl Clone for OwnedSlice { } impl FromIterator for OwnedSlice { - fn from_iter>(iter: I) -> OwnedSlice { + fn from_iter>(iter: I) -> OwnedSlice { OwnedSlice::from_vec(iter.collect()) } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 88c485a07acdf..8598571e5c37a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -598,7 +598,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<(uint, u8)>>(it: &mut iter::Peekable<(uint, u8), I>) { + fn eat<'a, I: Iterator>(it: &mut iter::Peekable<(uint, u8), I>) { loop { match it.peek().map(|x| x.1) { Some(b' ') | Some(b'\n') | Some(b'\r') | Some(b'\t') => { diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index 953a7ae960e8c..b68c9926391d7 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -30,7 +30,7 @@ enum SmallVectorRepr { } impl FromIterator for SmallVector { - fn from_iter>(iter: I) -> SmallVector { + fn from_iter>(iter: I) -> SmallVector { let mut v = SmallVector::zero(); v.extend(iter); v @@ -38,7 +38,7 @@ impl FromIterator for SmallVector { } impl Extend for SmallVector { - fn extend>(&mut self, mut iter: I) { + fn extend>(&mut self, mut iter: I) { for val in iter { self.push(val); } @@ -147,7 +147,9 @@ enum IntoIterRepr { ManyIterator(vec::IntoIter), } -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = T; + fn next(&mut self) -> Option { match self.repr { ZeroIterator => None, diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index ed6a00a8e9115..e8ab1b548433b 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -438,7 +438,7 @@ pub fn write_boxplot( /// Returns a HashMap with the number of occurrences of every element in the /// sequence that the iterator exposes. -pub fn freq_count, U: Eq+Hash>(mut iter: T) -> hash_map::HashMap { +pub fn freq_count, U: Eq+Hash>(mut iter: T) -> hash_map::HashMap { let mut map: hash_map::HashMap = hash_map::HashMap::new(); for elem in iter { match map.entry(elem) { diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index b2aca68431432..7603d84848c9f 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -24,6 +24,8 @@ #![allow(unknown_features)] #![feature(phase, globs)] #![feature(old_orphan_check)] +#![feature(associated_types)] +#![feature(default_type_params)] #[cfg(test)] #[phase(plugin, link)] extern crate log; @@ -100,7 +102,9 @@ impl Timespec { } } -impl Add for Timespec { +impl Add for Timespec { + type Output = Timespec; + fn add(self, other: Duration) -> Timespec { let d_sec = other.num_seconds(); // It is safe to unwrap the nanoseconds, because there cannot be @@ -120,7 +124,9 @@ impl Add for Timespec { } } -impl Sub for Timespec { +impl Sub for Timespec { + type Output = Duration; + fn sub(self, other: Timespec) -> Duration { let sec = self.sec - other.sec; let nsec = self.nsec - other.nsec; diff --git a/src/libunicode/lib.rs b/src/libunicode/lib.rs index d33362ec23295..eabe044ce3b71 100644 --- a/src/libunicode/lib.rs +++ b/src/libunicode/lib.rs @@ -29,6 +29,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![no_std] #![feature(globs, macro_rules, slicing_syntax, unboxed_closures)] +#![feature(associated_types)] extern crate core; diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index e17bf025cba7c..8ec90acb711f0 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -105,7 +105,9 @@ pub struct GraphemeIndices<'a> { iter: Graphemes<'a>, } -impl<'a> Iterator<(uint, &'a str)> for GraphemeIndices<'a> { +impl<'a> Iterator for GraphemeIndices<'a> { + type Item = (uint, &'a str); + #[inline] fn next(&mut self) -> Option<(uint, &'a str)> { self.iter.next().map(|s| (s.as_ptr() as uint - self.start_offset, s)) @@ -117,7 +119,7 @@ impl<'a> Iterator<(uint, &'a str)> for GraphemeIndices<'a> { } } -impl<'a> DoubleEndedIterator<(uint, &'a str)> for GraphemeIndices<'a> { +impl<'a> DoubleEndedIterator for GraphemeIndices<'a> { #[inline] fn next_back(&mut self) -> Option<(uint, &'a str)> { self.iter.next_back().map(|s| (s.as_ptr() as uint - self.start_offset, s)) @@ -145,7 +147,9 @@ enum GraphemeState { Regional, } -impl<'a> Iterator<&'a str> for Graphemes<'a> { +impl<'a> Iterator for Graphemes<'a> { + type Item = &'a str; + #[inline] fn size_hint(&self) -> (uint, Option) { let slen = self.string.len(); @@ -251,7 +255,7 @@ impl<'a> Iterator<&'a str> for Graphemes<'a> { } } -impl<'a> DoubleEndedIterator<&'a str> for Graphemes<'a> { +impl<'a> DoubleEndedIterator for Graphemes<'a> { #[inline] fn next_back(&mut self) -> Option<&'a str> { use tables::grapheme as gr; @@ -428,7 +432,9 @@ impl Utf16Item { } } -impl<'a> Iterator for Utf16Items<'a> { +impl<'a> Iterator for Utf16Items<'a> { + type Item = Utf16Item; + fn next(&mut self) -> Option { let u = match self.iter.next() { Some(u) => *u, @@ -505,12 +511,14 @@ pub struct Utf16Encoder { impl Utf16Encoder { /// Create an UTF-16 encoder from any `char` iterator. - pub fn new(chars: I) -> Utf16Encoder where I: Iterator { + pub fn new(chars: I) -> Utf16Encoder where I: Iterator { Utf16Encoder { chars: chars, extra: 0 } } } -impl Iterator for Utf16Encoder where I: Iterator { +impl Iterator for Utf16Encoder where I: Iterator { + type Item = u16; + #[inline] fn next(&mut self) -> Option { if self.extra != 0 { @@ -537,9 +545,11 @@ impl Iterator for Utf16Encoder where I: Iterator { } } -impl<'a> Iterator<&'a str> for Words<'a> { +impl<'a> Iterator for Words<'a> { + type Item = &'a str; + fn next(&mut self) -> Option<&'a str> { self.inner.next() } } -impl<'a> DoubleEndedIterator<&'a str> for Words<'a> { +impl<'a> DoubleEndedIterator for Words<'a> { fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() } } diff --git a/src/snapshots.txt b/src/snapshots.txt index 34beb53bd07cc..c72fd7978f885 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -1,3 +1,12 @@ +S 2015-01-02 c894171 + freebsd-x86_64 ea8bcf75eada3539f5cbab51708eecf40d436b77 + linux-i386 646ae265721e3cbe19404aae4fea4ffa1f1d90cf + linux-x86_64 85183ce0724af3dfb7616b9e81a4e5510415f351 + macos-i386 b3eced7fc5e78f767edb4595dfcde02dad206f3f + macos-x86_64 36418bce8c18f1b49ec6b5aec2bf35ff1cd833a3 + winnt-i386 6c7ddf23b389be723d34ab91a9baa4a06c5f9571 + winnt-x86_64 d086d4019d603db09166d0609a21da8ee8fe306a + S 2015-01-01 7d4f487 freebsd-x86_64 5dc87adb17bc33abc08f1bf4c092e0b5b92a6ca4 linux-i386 63bf82a5b540d8acbbf1e445ce48be0fa0f003fc diff --git a/src/test/auxiliary/issue-16643.rs b/src/test/auxiliary/issue-16643.rs index b30ccb4dded0d..41572998b58a4 100644 --- a/src/test/auxiliary/issue-16643.rs +++ b/src/test/auxiliary/issue-16643.rs @@ -9,6 +9,7 @@ // except according to those terms. #![crate_type = "lib"] +#![feature(associated_types)] pub struct TreeBuilder; @@ -20,7 +21,9 @@ impl TreeBuilder { } } -impl Iterator for TreeBuilder { +impl Iterator for TreeBuilder { + type Item = H; + fn next(&mut self) -> Option { None } diff --git a/src/test/auxiliary/nested_item.rs b/src/test/auxiliary/nested_item.rs index d97a2e3cda129..1a2f429c9ebc1 100644 --- a/src/test/auxiliary/nested_item.rs +++ b/src/test/auxiliary/nested_item.rs @@ -26,7 +26,7 @@ impl Foo { // issue 8134 pub struct Parser; -impl> Parser { +impl> Parser { fn in_doctype(&mut self) { static DOCTYPEPattern: [char; 6] = ['O', 'C', 'T', 'Y', 'P', 'E']; } diff --git a/src/test/auxiliary/trait_inheritance_overloading_xc.rs b/src/test/auxiliary/trait_inheritance_overloading_xc.rs index 7ddf2c43489c1..7394373e9229b 100644 --- a/src/test/auxiliary/trait_inheritance_overloading_xc.rs +++ b/src/test/auxiliary/trait_inheritance_overloading_xc.rs @@ -8,10 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::cmp::PartialEq; use std::ops::{Add, Sub, Mul}; -pub trait MyNum : Add + Sub + Mul + PartialEq + Clone { +pub trait MyNum : Add + Sub + Mul + PartialEq + Clone { } #[derive(Clone, Show)] @@ -19,15 +21,21 @@ pub struct MyInt { pub val: int } -impl Add for MyInt { +impl Add for MyInt { + type Output = MyInt; + fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) } } -impl Sub for MyInt { +impl Sub for MyInt { + type Output = MyInt; + fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) } } -impl Mul for MyInt { +impl Mul for MyInt { + type Output = MyInt; + fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) } } diff --git a/src/test/auxiliary/unboxed-closures-cross-crate.rs b/src/test/auxiliary/unboxed-closures-cross-crate.rs index 0b65fa913cb77..4bc45caa170e4 100644 --- a/src/test/auxiliary/unboxed-closures-cross-crate.rs +++ b/src/test/auxiliary/unboxed-closures-cross-crate.rs @@ -21,7 +21,7 @@ pub fn has_closures() -> uint { f() + g() } -pub fn has_generic_closures + Copy>(x: T, y: T) -> T { +pub fn has_generic_closures + Copy>(x: T, y: T) -> T { let mut f = move |&mut:| x; let g = |:| y; f() + g() diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 7009dd4c1a76f..eee42af4dbc76 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -38,7 +38,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. -#![feature(slicing_syntax)] +#![feature(associated_types, slicing_syntax)] use std::cmp::min; use std::io::{BufferedWriter, File}; @@ -75,7 +75,9 @@ impl<'a> AAGen<'a> { AAGen { rng: rng, data: data } } } -impl<'a> Iterator for AAGen<'a> { +impl<'a> Iterator for AAGen<'a> { + type Item = u8; + fn next(&mut self) -> Option { let r = self.rng.gen(); self.data.iter() @@ -85,7 +87,7 @@ impl<'a> Iterator for AAGen<'a> { } } -fn make_fasta>( +fn make_fasta>( wr: &mut W, header: &str, mut it: I, mut n: uint) -> std::io::IoResult<()> { diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 26ef696b616ce..df5baac7dbe4e 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -40,7 +40,7 @@ // ignore-android see #10393 #13206 -#![feature(slicing_syntax)] +#![feature(associated_types, slicing_syntax)] use std::ascii::OwnedAsciiExt; use std::slice; @@ -194,7 +194,9 @@ impl Table { } } -impl<'a> Iterator<&'a Entry> for Items<'a> { +impl<'a> Iterator for Items<'a> { + type Item = &'a Entry; + fn next(&mut self) -> Option<&'a Entry> { let ret = match self.cur { None => { diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 0c3152d4780f2..94d99b9f118f7 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -40,6 +40,8 @@ // no-pretty-expanded FIXME #15189 +#![feature(associated_types)] + use std::sync::mpsc::channel; use std::sync::Arc; use std::thread::Thread; @@ -57,7 +59,9 @@ struct Iterate<'a, T> { f: |&T|: 'a -> T, next: T } -impl<'a, T> Iterator for Iterate<'a, T> { +impl<'a, T> Iterator for Iterate<'a, T> { + type Item = T; + fn next(&mut self) -> Option { let mut res = (self.f)(&self.next); std::mem::swap(&mut res, &mut self.next); @@ -78,7 +82,9 @@ impl<'a, T> List<'a, T> { ListIterator{cur: self} } } -impl<'a, T> Iterator<&'a T> for ListIterator<'a, T> { +impl<'a, T> Iterator for ListIterator<'a, T> { + type Item = &'a T; + fn next(&mut self) -> Option<&'a T> { match *self.cur { List::Nil => None, diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index a138684330365..4e60c2bee4446 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -40,7 +40,7 @@ // ignore-android see #10393 #13206 -#![feature(slicing_syntax, unboxed_closures)] +#![feature(associated_types, slicing_syntax, unboxed_closures)] extern crate libc; @@ -150,7 +150,9 @@ struct MutDnaSeqs<'a> { s: &'a mut [u8] } fn mut_dna_seqs<'a>(s: &'a mut [u8]) -> MutDnaSeqs<'a> { MutDnaSeqs { s: s } } -impl<'a> Iterator<&'a mut [u8]> for MutDnaSeqs<'a> { +impl<'a> Iterator for MutDnaSeqs<'a> { + type Item = &'a mut [u8]; + fn next(&mut self) -> Option<&'a mut [u8]> { let tmp = std::mem::replace(&mut self.s, &mut []); let tmp = match memchr(tmp, b'\n') { @@ -229,7 +231,7 @@ unsafe impl Send for Racy {} /// The closure `f` is run in parallel with an element of `iter`. fn parallel<'a, I, T, F>(mut iter: I, f: F) where T: 'a+Send + Sync, - I: Iterator<&'a mut [T]>, + I: Iterator, F: Fn(&mut [T]) + Sync { use std::mem; use std::raw::Repr; diff --git a/src/test/compile-fail/binop-consume-args.rs b/src/test/compile-fail/binop-consume-args.rs index afa255be699e7..930000e5f0c37 100644 --- a/src/test/compile-fail/binop-consume-args.rs +++ b/src/test/compile-fail/binop-consume-args.rs @@ -10,63 +10,65 @@ // Test that binary operators consume their arguments +#![feature(associated_types, default_type_params)] + use std::ops::{Add, Sub, Mul, Div, Rem, BitAnd, BitXor, BitOr, Shl, Shr}; -fn add, B>(lhs: A, rhs: B) { +fn add, B>(lhs: A, rhs: B) { lhs + rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` } -fn sub, B>(lhs: A, rhs: B) { +fn sub, B>(lhs: A, rhs: B) { lhs - rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` } -fn mul, B>(lhs: A, rhs: B) { +fn mul, B>(lhs: A, rhs: B) { lhs * rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` } -fn div, B>(lhs: A, rhs: B) { +fn div, B>(lhs: A, rhs: B) { lhs / rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` } -fn rem, B>(lhs: A, rhs: B) { +fn rem, B>(lhs: A, rhs: B) { lhs % rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` } -fn bitand, B>(lhs: A, rhs: B) { +fn bitand, B>(lhs: A, rhs: B) { lhs & rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` } -fn bitor, B>(lhs: A, rhs: B) { +fn bitor, B>(lhs: A, rhs: B) { lhs | rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` } -fn bitxor, B>(lhs: A, rhs: B) { +fn bitxor, B>(lhs: A, rhs: B) { lhs ^ rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` } -fn shl, B>(lhs: A, rhs: B) { +fn shl, B>(lhs: A, rhs: B) { lhs << rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` } -fn shr, B>(lhs: A, rhs: B) { +fn shr, B>(lhs: A, rhs: B) { lhs >> rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` diff --git a/src/test/compile-fail/binop-move-semantics.rs b/src/test/compile-fail/binop-move-semantics.rs index e48c88a49f0bf..e51ca6a70f28b 100644 --- a/src/test/compile-fail/binop-move-semantics.rs +++ b/src/test/compile-fail/binop-move-semantics.rs @@ -10,21 +10,23 @@ // Test that move restrictions are enforced on overloaded binary operations +#![feature(associated_types, default_type_params)] + use std::ops::Add; -fn double_move>(x: T) { +fn double_move>(x: T) { x + x; //~ ERROR: use of moved value } -fn move_then_borrow + Clone>(x: T) { +fn move_then_borrow + Clone>(x: T) { x + x.clone(); //~ ERROR: use of moved value } -fn move_borrowed>(x: T, mut y: T) { +fn move_borrowed>(x: T, mut y: T) { let m = &x; let n = &mut y; @@ -33,7 +35,7 @@ fn move_borrowed>(x: T, mut y: T) { y; //~ ERROR: cannot move out of `y` because it is borrowed } -fn illegal_dereference>(mut x: T, y: T) { +fn illegal_dereference>(mut x: T, y: T) { let m = &mut x; let n = &y; @@ -44,11 +46,15 @@ fn illegal_dereference>(mut x: T, y: T) { struct Foo; -impl<'a, 'b> Add<&'b Foo, ()> for &'a mut Foo { +impl<'a, 'b> Add<&'b Foo> for &'a mut Foo { + type Output = (); + fn add(self, _: &Foo) {} } -impl<'a, 'b> Add<&'b mut Foo, ()> for &'a Foo { +impl<'a, 'b> Add<&'b mut Foo> for &'a Foo { + type Output = (); + fn add(self, _: &mut Foo) {} } diff --git a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs index bcbb1f08b8979..141dd8905bece 100644 --- a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs @@ -8,12 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::ops::Add; #[derive(Clone)] struct foo(Box); -impl Add for foo { +impl Add for foo { + type Output = foo; + fn add(self, f: foo) -> foo { let foo(box i) = self; let foo(box j) = f; diff --git a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs index a0edd07818477..e0a961e5cc5fc 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types, default_type_params)] + use std::ops::Add; #[derive(Copy)] @@ -16,7 +18,9 @@ struct Point { y: int, } -impl Add for Point { +impl Add for Point { + type Output = int; + fn add(self, z: int) -> int { self.x + self.y + z } diff --git a/src/test/compile-fail/borrowck-overloaded-index-2.rs b/src/test/compile-fail/borrowck-overloaded-index-2.rs index 01afe405d5e12..87e647d16ddf8 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-2.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-2.rs @@ -8,13 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::ops::Index; struct MyVec { data: Vec, } -impl Index for MyVec { +impl Index for MyVec { + type Output = T; + fn index(&self, &i: &uint) -> &T { &self.data[i] } diff --git a/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs b/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs index e8949d4b30bef..e7bd7cdf0b79d 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs @@ -11,6 +11,8 @@ // Test that we still see borrowck errors of various kinds when using // indexing and autoderef in combination. +#![feature(associated_types)] + use std::ops::{Index, IndexMut}; struct Foo { @@ -18,7 +20,9 @@ struct Foo { y: int, } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index<'a>(&'a self, z: &String) -> &'a int { if z.as_slice() == "x" { &self.x @@ -28,7 +32,9 @@ impl Index for Foo { } } -impl IndexMut for Foo { +impl IndexMut for Foo { + type Output = int; + fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int { if z.as_slice() == "x" { &mut self.x diff --git a/src/test/compile-fail/borrowck-overloaded-index.rs b/src/test/compile-fail/borrowck-overloaded-index.rs index 933d0f15e4e70..532f32ce770a6 100644 --- a/src/test/compile-fail/borrowck-overloaded-index.rs +++ b/src/test/compile-fail/borrowck-overloaded-index.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::ops::{Index, IndexMut}; struct Foo { @@ -15,7 +17,9 @@ struct Foo { y: int, } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index<'a>(&'a self, z: &String) -> &'a int { if z.as_slice() == "x" { &self.x @@ -25,7 +29,9 @@ impl Index for Foo { } } -impl IndexMut for Foo { +impl IndexMut for Foo { + type Output = int; + fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int { if z.as_slice() == "x" { &mut self.x @@ -39,7 +45,9 @@ struct Bar { x: int, } -impl Index for Bar { +impl Index for Bar { + type Output = int; + fn index<'a>(&'a self, z: &int) -> &'a int { &self.x } diff --git a/src/test/compile-fail/dst-index.rs b/src/test/compile-fail/dst-index.rs index af97c864dc81a..06d20c3361bc9 100644 --- a/src/test/compile-fail/dst-index.rs +++ b/src/test/compile-fail/dst-index.rs @@ -11,6 +11,8 @@ // Test that overloaded index expressions with DST result types // can't be used as rvalues +#![feature(associated_types)] + use std::ops::Index; use std::fmt::Show; @@ -18,7 +20,9 @@ struct S; impl Copy for S {} -impl Index for S { +impl Index for S { + type Output = str; + fn index<'a>(&'a self, _: &uint) -> &'a str { "hello" } @@ -28,7 +32,9 @@ struct T; impl Copy for T {} -impl Index for T { +impl Index for T { + type Output = Show + 'static; + fn index<'a>(&'a self, idx: &uint) -> &'a (Show + 'static) { static x: uint = 42; &x diff --git a/src/test/compile-fail/issue-13058.rs b/src/test/compile-fail/issue-13058.rs index 5203c91237be8..8dda54efc06af 100644 --- a/src/test/compile-fail/issue-13058.rs +++ b/src/test/compile-fail/issue-13058.rs @@ -10,7 +10,7 @@ use std::iter::{Range,range}; -trait Itble<'r, T, I: Iterator> { fn iter(&'r self) -> I; } +trait Itble<'r, T, I: Iterator> { fn iter(&'r self) -> I; } impl<'r> Itble<'r, uint, Range> for (uint, uint) { fn iter(&'r self) -> Range { @@ -19,8 +19,8 @@ impl<'r> Itble<'r, uint, Range> for (uint, uint) { } } -fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &T) -> bool -//~^ HELP as shown: fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &'r T) -> bool +fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &T) -> bool +//~^ HELP as shown: fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &'r T) { let cont_iter = cont.iter(); //~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements diff --git a/src/test/compile-fail/issue-13853.rs b/src/test/compile-fail/issue-13853.rs index 868836a4bbd0a..509ca9b80f81f 100644 --- a/src/test/compile-fail/issue-13853.rs +++ b/src/test/compile-fail/issue-13853.rs @@ -13,11 +13,11 @@ trait Node { } trait Graph { - fn nodes<'a, I: Iterator<&'a N>>(&'a self) -> I; + fn nodes<'a, I: Iterator>(&'a self) -> I; } impl Graph for Vec { - fn nodes<'a, I: Iterator<&'a N>>(&self) -> I { + fn nodes<'a, I: Iterator>(&self) -> I { self.iter() //~ ERROR mismatched types } } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 3343e92252f8e..b688cafb67459 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - trait vec_monad { fn bind(&self, f: |A| -> Vec ); } diff --git a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs index 7c514b4e16f07..7d91b1998bf24 100644 --- a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs +++ b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs @@ -12,7 +12,7 @@ use std::iter::{Range,range}; -trait Itble<'r, T, I: Iterator> { fn iter(&'r self) -> I; } +trait Itble<'r, T, I: Iterator> { fn iter(&'r self) -> I; } impl<'r> Itble<'r, uint, Range> for (uint, uint) { fn iter(&'r self) -> Range { @@ -21,8 +21,8 @@ impl<'r> Itble<'r, uint, Range> for (uint, uint) { } } -fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &T) -> bool { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &'r T) -> bool +fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &T) -> bool { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &'r T) let cont_iter = cont.iter(); //~ ERROR: cannot infer let result = cont_iter.fold(Some(0u16), |state, val| { state.map_or(None, |mask| { diff --git a/src/test/compile-fail/static-reference-to-fn-2.rs b/src/test/compile-fail/static-reference-to-fn-2.rs index d7255c3ba0694..2bdbdb4fde295 100644 --- a/src/test/compile-fail/static-reference-to-fn-2.rs +++ b/src/test/compile-fail/static-reference-to-fn-2.rs @@ -8,13 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + struct StateMachineIter<'a> { statefn: &'a StateMachineFunc<'a> } type StateMachineFunc<'a> = fn(&mut StateMachineIter<'a>) -> Option<&'static str>; -impl<'a> Iterator<&'static str> for StateMachineIter<'a> { +impl<'a> Iterator for StateMachineIter<'a> { + type Item = &'static str; + fn next(&mut self) -> Option<&'static str> { return (*self.statefn)(self); } diff --git a/src/test/compile-fail/unop-move-semantics.rs b/src/test/compile-fail/unop-move-semantics.rs index c458c539c0766..f8cbdb4e160bf 100644 --- a/src/test/compile-fail/unop-move-semantics.rs +++ b/src/test/compile-fail/unop-move-semantics.rs @@ -12,13 +12,13 @@ use std::ops::Not; -fn move_then_borrow + Clone>(x: T) { +fn move_then_borrow + Clone>(x: T) { !x; x.clone(); //~ ERROR: use of moved value } -fn move_borrowed>(x: T, mut y: T) { +fn move_borrowed>(x: T, mut y: T) { let m = &x; let n = &mut y; @@ -27,7 +27,7 @@ fn move_borrowed>(x: T, mut y: T) { !y; //~ ERROR: cannot move out of `y` because it is borrowed } -fn illegal_dereference>(mut x: T, y: T) { +fn illegal_dereference>(mut x: T, y: T) { let m = &mut x; let n = &y; diff --git a/src/test/compile-fail/wrong-mul-method-signature.rs b/src/test/compile-fail/wrong-mul-method-signature.rs index bde5b853078f2..7aa6ead89d7e0 100644 --- a/src/test/compile-fail/wrong-mul-method-signature.rs +++ b/src/test/compile-fail/wrong-mul-method-signature.rs @@ -13,6 +13,8 @@ // (In this case the mul method should take &f64 and not f64) // See: #11450 +#![feature(associated_types, default_type_params)] + use std::ops::Mul; struct Vec1 { @@ -20,7 +22,9 @@ struct Vec1 { } // Expecting value in input signature -impl Mul for Vec1 { +impl Mul for Vec1 { + type Output = Vec1; + fn mul(self, s: &f64) -> Vec1 { //~^ ERROR: method `mul` has an incompatible type for trait: expected f64, found &-ptr Vec1 { @@ -35,7 +39,9 @@ struct Vec2 { } // Wrong type parameter ordering -impl Mul for Vec2 { +impl Mul for Vec2 { + type Output = f64; + fn mul(self, s: f64) -> Vec2 { //~^ ERROR: method `mul` has an incompatible type for trait: expected struct Vec2, found f64 Vec2 { @@ -52,7 +58,9 @@ struct Vec3 { } // Unexpected return type -impl Mul for Vec3 { +impl Mul for Vec3 { + type Output = i32; + fn mul(self, s: f64) -> f64 { //~^ ERROR: method `mul` has an incompatible type for trait: expected i32, found f64 s diff --git a/src/test/run-pass/deriving-zero.rs b/src/test/run-pass/deriving-zero.rs index a6c0a592c77be..442c330b27786 100644 --- a/src/test/run-pass/deriving-zero.rs +++ b/src/test/run-pass/deriving-zero.rs @@ -8,13 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::ops::Add; +#![feature(associated_types)] + use std::num::Zero; +use std::ops::Add; #[derive(Zero)] struct Vector2(T, T); -impl> Add, Vector2> for Vector2 { +impl> Add for Vector2 { + type Output = Vector2; + fn add(self, other: Vector2) -> Vector2 { match (self, other) { (Vector2(x0, y0), Vector2(x1, y1)) => { @@ -29,7 +33,9 @@ struct Vector3 { x: T, y: T, z: T, } -impl> Add, Vector3> for Vector3 { +impl> Add for Vector3 { + type Output = Vector3; + fn add(self, other: Vector3) -> Vector3 { Vector3 { x: self.x + other.x, @@ -46,7 +52,9 @@ struct Matrix3x2 { z: Vector2, } -impl> Add, Matrix3x2> for Matrix3x2 { +impl> Add for Matrix3x2 { + type Output = Matrix3x2; + fn add(self, other: Matrix3x2) -> Matrix3x2 { Matrix3x2 { x: self.x + other.x, diff --git a/src/test/run-pass/dst-index.rs b/src/test/run-pass/dst-index.rs index eaf7131e1d878..6a69bfc248f16 100644 --- a/src/test/run-pass/dst-index.rs +++ b/src/test/run-pass/dst-index.rs @@ -11,12 +11,16 @@ // Test that overloaded index expressions with DST result types // work and don't ICE. +#![feature(associated_types)] + use std::ops::Index; use std::fmt::Show; struct S; -impl Index for S { +impl Index for S { + type Output = str; + fn index<'a>(&'a self, _: &uint) -> &'a str { "hello" } @@ -24,7 +28,9 @@ impl Index for S { struct T; -impl Index for T { +impl Index for T { + type Output = Show + 'static; + fn index<'a>(&'a self, idx: &uint) -> &'a (Show + 'static) { static x: uint = 42; &x diff --git a/src/test/run-pass/issue-13167.rs b/src/test/run-pass/issue-13167.rs index 1282077028ffb..ee556ce2c8459 100644 --- a/src/test/run-pass/issue-13167.rs +++ b/src/test/run-pass/issue-13167.rs @@ -8,13 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::slice; pub struct PhfMapEntries<'a, T: 'a> { iter: slice::Iter<'a, (&'static str, T)>, } -impl<'a, T> Iterator<(&'static str, &'a T)> for PhfMapEntries<'a, T> { +impl<'a, T> Iterator for PhfMapEntries<'a, T> { + type Item = (&'static str, &'a T); + fn next(&mut self) -> Option<(&'static str, &'a T)> { self.iter.by_ref().map(|&(key, ref value)| (key, value)).next() } diff --git a/src/test/run-pass/issue-13204.rs b/src/test/run-pass/issue-13204.rs index f9b542dea56f0..c29dc4319dc0c 100644 --- a/src/test/run-pass/issue-13204.rs +++ b/src/test/run-pass/issue-13204.rs @@ -12,7 +12,7 @@ // lifetime parameters defined on the method bound correctly. pub trait Foo { - fn bar<'a, I: Iterator<&'a ()>>(&self, it: I) -> uint { + fn bar<'a, I: Iterator>(&self, it: I) -> uint { let mut xs = it.filter(|_| true); xs.count() } diff --git a/src/test/run-pass/issue-14919.rs b/src/test/run-pass/issue-14919.rs index db29eb314bd70..d66bbe9187a28 100644 --- a/src/test/run-pass/issue-14919.rs +++ b/src/test/run-pass/issue-14919.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + trait Matcher { fn next_match(&mut self) -> Option<(uint, uint)>; } @@ -40,7 +42,9 @@ struct MatchIndices { matcher: M } -impl Iterator<(uint, uint)> for MatchIndices { +impl Iterator for MatchIndices { + type Item = (uint, uint); + fn next(&mut self) -> Option<(uint, uint)> { self.matcher.next_match() } diff --git a/src/test/run-pass/issue-15734.rs b/src/test/run-pass/issue-15734.rs index e99b1dc5befb0..f261098f53811 100644 --- a/src/test/run-pass/issue-15734.rs +++ b/src/test/run-pass/issue-15734.rs @@ -10,7 +10,8 @@ // If `Index` used an associated type for its output, this test would // work more smoothly. -#![feature(old_orphan_check)] + +#![feature(associated_types, old_orphan_check)] use std::ops::Index; @@ -25,13 +26,17 @@ impl Mat { } } -impl Index<(uint, uint), T> for Mat { +impl Index<(uint, uint)> for Mat { + type Output = T; + fn index<'a>(&'a self, &(row, col): &(uint, uint)) -> &'a T { &self.data[row * self.cols + col] } } -impl<'a, T> Index<(uint, uint), T> for &'a Mat { +impl<'a, T> Index<(uint, uint)> for &'a Mat { + type Output = T; + fn index<'b>(&'b self, index: &(uint, uint)) -> &'b T { (*self).index(index) } @@ -39,7 +44,9 @@ impl<'a, T> Index<(uint, uint), T> for &'a Mat { struct Row { mat: M, row: uint, } -impl> Index for Row { +impl> Index for Row { + type Output = T; + fn index<'a>(&'a self, col: &uint) -> &'a T { &self.mat[(self.row, *col)] } diff --git a/src/test/run-pass/issue-16596.rs b/src/test/run-pass/issue-16596.rs index df959fa0bda93..7bc6d989fa75c 100644 --- a/src/test/run-pass/issue-16596.rs +++ b/src/test/run-pass/issue-16596.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + trait MatrixRow {} struct Mat; @@ -18,7 +20,9 @@ struct Rows { mat: M, } -impl<'a> Iterator<()> for Rows<&'a Mat> { +impl<'a> Iterator for Rows<&'a Mat> { + type Item = (); + fn next(&mut self) -> Option<()> { unimplemented!() } diff --git a/src/test/run-pass/issue-3743.rs b/src/test/run-pass/issue-3743.rs index cb4f1b7d20f14..741f168482da2 100644 --- a/src/test/run-pass/issue-3743.rs +++ b/src/test/run-pass/issue-3743.rs @@ -10,7 +10,7 @@ // If `Mul` used an associated type for its output, this test would // work more smoothly. -#![feature(old_orphan_check)] +#![feature(associated_types, default_type_params, old_orphan_check)] use std::ops::Mul; @@ -33,7 +33,9 @@ impl Vec2 { trait RhsOfVec2Mul { fn mul_vec2_by(&self, lhs: &Vec2) -> Result; } // Vec2's implementation of Mul "from the other side" using the above trait -impl> Mul for Vec2 { +impl> Mul for Vec2 { + type Output = Res; + fn mul(self, rhs: Rhs) -> Res { rhs.mul_vec2_by(&self) } } diff --git a/src/test/run-pass/issue-3979-generics.rs b/src/test/run-pass/issue-3979-generics.rs index 93c72e2e35091..180bd292f8433 100644 --- a/src/test/run-pass/issue-3979-generics.rs +++ b/src/test/run-pass/issue-3979-generics.rs @@ -15,7 +15,7 @@ trait Positioned { fn X(&self) -> S; } -trait Movable>: Positioned { +trait Movable>: Positioned { fn translate(&mut self, dx: S) { let x = self.X() + dx; self.SetX(x); diff --git a/src/test/run-pass/issue-7784.rs b/src/test/run-pass/issue-7784.rs index 43785edc2eb03..882ca00f1dfa6 100644 --- a/src/test/run-pass/issue-7784.rs +++ b/src/test/run-pass/issue-7784.rs @@ -12,7 +12,7 @@ use std::ops::Add; -fn foo + Clone>([x, y, z]: [T; 3]) -> (T, T, T) { +fn foo + Clone>([x, y, z]: [T; 3]) -> (T, T, T) { (x.clone(), x.clone() + y.clone(), x + y + z) } fn bar(a: &'static str, b: &'static str) -> [&'static str; 4] { diff --git a/src/test/run-pass/operator-multidispatch.rs b/src/test/run-pass/operator-multidispatch.rs index 2394822d9baea..5999840091967 100644 --- a/src/test/run-pass/operator-multidispatch.rs +++ b/src/test/run-pass/operator-multidispatch.rs @@ -11,6 +11,8 @@ // Test that we can overload the `+` operator for points so that two // points can be added, and a point can be added to an integer. +#![feature(associated_types, default_type_params)] + use std::ops; #[derive(Show,PartialEq,Eq)] @@ -19,13 +21,17 @@ struct Point { y: int } -impl ops::Add for Point { +impl ops::Add for Point { + type Output = Point; + fn add(self, other: Point) -> Point { Point {x: self.x + other.x, y: self.y + other.y} } } -impl ops::Add for Point { +impl ops::Add for Point { + type Output = Point; + fn add(self, other: int) -> Point { Point {x: self.x + other, y: self.y + other} diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs index 101b93c1896f1..41e7586f1e3db 100644 --- a/src/test/run-pass/operator-overloading.rs +++ b/src/test/run-pass/operator-overloading.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] use std::cmp; use std::ops; @@ -18,31 +19,41 @@ struct Point { y: int } -impl ops::Add for Point { +impl ops::Add for Point { + type Output = Point; + fn add(self, other: Point) -> Point { Point {x: self.x + other.x, y: self.y + other.y} } } -impl ops::Sub for Point { +impl ops::Sub for Point { + type Output = Point; + fn sub(self, other: Point) -> Point { Point {x: self.x - other.x, y: self.y - other.y} } } -impl ops::Neg for Point { +impl ops::Neg for Point { + type Output = Point; + fn neg(self) -> Point { Point {x: -self.x, y: -self.y} } } -impl ops::Not for Point { +impl ops::Not for Point { + type Output = Point; + fn not(self) -> Point { Point {x: !self.x, y: !self.y } } } -impl ops::Index for Point { +impl ops::Index for Point { + type Output = int; + fn index(&self, x: &bool) -> &int { if *x { &self.x diff --git a/src/test/run-pass/overloaded-calls-param-vtables.rs b/src/test/run-pass/overloaded-calls-param-vtables.rs index bdaccee65d7f5..b3c9ec3dc934e 100644 --- a/src/test/run-pass/overloaded-calls-param-vtables.rs +++ b/src/test/run-pass/overloaded-calls-param-vtables.rs @@ -10,14 +10,14 @@ // Tests that nested vtables work with overloaded calls. -#![feature(unboxed_closures)] +#![feature(default_type_params, unboxed_closures)] use std::ops::Fn; use std::ops::Add; struct G; -impl<'a, A: Add> Fn<(A,), int> for G { +impl<'a, A: Add> Fn<(A,), int> for G { extern "rust-call" fn call(&self, (arg,): (A,)) -> int { arg.add(1) } diff --git a/src/test/run-pass/overloaded-index-assoc-list.rs b/src/test/run-pass/overloaded-index-assoc-list.rs index 0347f8a29df28..77bb981cfd9b9 100644 --- a/src/test/run-pass/overloaded-index-assoc-list.rs +++ b/src/test/run-pass/overloaded-index-assoc-list.rs @@ -11,6 +11,8 @@ // Test overloading of the `[]` operator. In particular test that it // takes its argument *by reference*. +#![feature(associated_types)] + use std::ops::Index; struct AssociationList { @@ -28,7 +30,9 @@ impl AssociationList { } } -impl Index for AssociationList { +impl Index for AssociationList { + type Output = V; + fn index<'a>(&'a self, index: &K) -> &'a V { for pair in self.pairs.iter() { if pair.key == *index { diff --git a/src/test/run-pass/overloaded-index-autoderef.rs b/src/test/run-pass/overloaded-index-autoderef.rs index dcb0c40c6088a..d141234287d13 100644 --- a/src/test/run-pass/overloaded-index-autoderef.rs +++ b/src/test/run-pass/overloaded-index-autoderef.rs @@ -10,6 +10,8 @@ // Test overloaded indexing combined with autoderef. +#![feature(associated_types)] + use std::ops::{Index, IndexMut}; struct Foo { @@ -17,7 +19,9 @@ struct Foo { y: int, } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index(&self, z: &int) -> &int { if *z == 0 { &self.x @@ -27,7 +31,9 @@ impl Index for Foo { } } -impl IndexMut for Foo { +impl IndexMut for Foo { + type Output = int; + fn index_mut(&mut self, z: &int) -> &mut int { if *z == 0 { &mut self.x diff --git a/src/test/run-pass/overloaded-index-in-field.rs b/src/test/run-pass/overloaded-index-in-field.rs index 1c06ed64fc7b8..9c6afc0912d06 100644 --- a/src/test/run-pass/overloaded-index-in-field.rs +++ b/src/test/run-pass/overloaded-index-in-field.rs @@ -11,6 +11,8 @@ // Test using overloaded indexing when the "map" is stored in a // field. This caused problems at some point. +#![feature(associated_types)] + use std::ops::Index; struct Foo { @@ -22,7 +24,9 @@ struct Bar { foo: Foo } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index(&self, z: &int) -> &int { if *z == 0 { &self.x diff --git a/src/test/run-pass/overloaded-index.rs b/src/test/run-pass/overloaded-index.rs index fdf7e7e2cbb13..fe09b47cf0a78 100644 --- a/src/test/run-pass/overloaded-index.rs +++ b/src/test/run-pass/overloaded-index.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::ops::{Index, IndexMut}; struct Foo { @@ -15,7 +17,9 @@ struct Foo { y: int, } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index(&self, z: &int) -> &int { if *z == 0 { &self.x @@ -25,7 +29,9 @@ impl Index for Foo { } } -impl IndexMut for Foo { +impl IndexMut for Foo { + type Output = int; + fn index_mut(&mut self, z: &int) -> &mut int { if *z == 0 { &mut self.x diff --git a/src/test/run-pass/regions-no-bound-in-argument-cleanup.rs b/src/test/run-pass/regions-no-bound-in-argument-cleanup.rs index 27d9895097863..d52c1c0b12c53 100644 --- a/src/test/run-pass/regions-no-bound-in-argument-cleanup.rs +++ b/src/test/run-pass/regions-no-bound-in-argument-cleanup.rs @@ -8,11 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unsafe_destructor)] +#![feature(associated_types, unsafe_destructor)] pub struct Foo; -impl Iterator for Foo { +impl Iterator for Foo { + type Item = T; + fn next(&mut self) -> Option { None } diff --git a/src/test/run-pass/simd-generics.rs b/src/test/run-pass/simd-generics.rs index 42f93a97142d2..ceb6b79042681 100644 --- a/src/test/run-pass/simd-generics.rs +++ b/src/test/run-pass/simd-generics.rs @@ -9,7 +9,7 @@ // except according to those terms. -#![feature(simd)] +#![feature(associated_types, simd)] use std::ops; @@ -17,11 +17,13 @@ use std::ops; impl Copy for f32x4 {} -fn add>(lhs: T, rhs: T) -> T { +fn add>(lhs: T, rhs: T) -> T { lhs + rhs } -impl ops::Add for f32x4 { +impl ops::Add for f32x4 { + type Output = f32x4; + fn add(self, rhs: f32x4) -> f32x4 { self + rhs } diff --git a/src/test/run-pass/supertrait-default-generics.rs b/src/test/run-pass/supertrait-default-generics.rs index 4465561f874eb..f31d9ca186f1e 100644 --- a/src/test/run-pass/supertrait-default-generics.rs +++ b/src/test/run-pass/supertrait-default-generics.rs @@ -17,7 +17,7 @@ trait Positioned { fn X(&self) -> S; } -trait Movable>: Positioned { +trait Movable>: Positioned { fn translate(&mut self, dx: S) { let x = self.X() + dx; self.SetX(x); @@ -35,7 +35,7 @@ impl Positioned for Point { } } -impl> Movable for Point {} +impl> Movable for Point {} pub fn main() { let mut p = Point{ x: 1i, y: 2i}; diff --git a/src/test/run-pass/trait-inheritance-overloading.rs b/src/test/run-pass/trait-inheritance-overloading.rs index 3748a31b30224..3e8db61b94044 100644 --- a/src/test/run-pass/trait-inheritance-overloading.rs +++ b/src/test/run-pass/trait-inheritance-overloading.rs @@ -8,23 +8,31 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::cmp::PartialEq; use std::ops::{Add, Sub, Mul}; -trait MyNum : Add + Sub + Mul + PartialEq + Clone { } +trait MyNum : Add + Sub + Mul + PartialEq + Clone { } #[derive(Clone, Show)] struct MyInt { val: int } -impl Add for MyInt { +impl Add for MyInt { + type Output = MyInt; + fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) } } -impl Sub for MyInt { +impl Sub for MyInt { + type Output = MyInt; + fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) } } -impl Mul for MyInt { +impl Mul for MyInt { + type Output = MyInt; + fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) } } diff --git a/src/test/run-pass/where-clauses-lifetimes.rs b/src/test/run-pass/where-clauses-lifetimes.rs index 4adaf7a11e30f..237c83c8aa23a 100644 --- a/src/test/run-pass/where-clauses-lifetimes.rs +++ b/src/test/run-pass/where-clauses-lifetimes.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo<'a, I>(mut it: I) where I: Iterator<&'a int> {} +fn foo<'a, I>(mut it: I) where I: Iterator {} fn main() { foo([1i, 2].iter());