@@ -101,16 +101,11 @@ pub trait Iterator {
101101 fn size_hint ( & self ) -> ( usize , Option < usize > ) { ( 0 , None ) }
102102}
103103
104- impl < ' a , T > Iterator for & ' a mut ( Iterator < Item =T > + ' a ) {
105- type Item = T ;
106-
107- fn next ( & mut self ) -> Option < T > {
108- ( * * self ) . next ( )
109- }
110-
111- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
112- ( * * self ) . size_hint ( )
113- }
104+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
105+ impl < ' a , I : Iterator + ?Sized > Iterator for & ' a mut I {
106+ type Item = I :: Item ;
107+ fn next ( & mut self ) -> Option < I :: Item > { ( * * self ) . next ( ) }
108+ fn size_hint ( & self ) -> ( usize , Option < usize > ) { ( * * self ) . size_hint ( ) }
114109}
115110
116111/// Conversion from an `Iterator`
@@ -549,9 +544,7 @@ pub trait IteratorExt: Iterator + Sized {
549544 /// assert!(it.next() == Some(5));
550545 /// ```
551546 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
552- fn by_ref < ' r > ( & ' r mut self ) -> ByRef < ' r , Self > {
553- ByRef { iter : self }
554- }
547+ fn by_ref ( & mut self ) -> & mut Self { self }
555548
556549 /// Loops through the entire iterator, collecting all of the elements into
557550 /// a container implementing `FromIterator`.
@@ -1019,15 +1012,22 @@ impl<I> IteratorExt for I where I: Iterator {}
10191012
10201013/// A range iterator able to yield elements from both ends
10211014///
1022- /// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust
1023- /// elements from the *same* range, and do not work independently of each other.
1015+ /// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and
1016+ /// `next_back()` exhaust elements from the *same* range, and do not work
1017+ /// independently of each other.
10241018#[ stable( feature = "rust1" , since = "1.0.0" ) ]
10251019pub trait DoubleEndedIterator : Iterator {
1026- /// Yield an element from the end of the range, returning `None` if the range is empty.
1020+ /// Yield an element from the end of the range, returning `None` if the
1021+ /// range is empty.
10271022 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
10281023 fn next_back ( & mut self ) -> Option < Self :: Item > ;
10291024}
10301025
1026+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1027+ impl < ' a , I : DoubleEndedIterator + ?Sized > DoubleEndedIterator for & ' a mut I {
1028+ fn next_back ( & mut self ) -> Option < I :: Item > { ( * * self ) . next_back ( ) }
1029+ }
1030+
10311031/// An object implementing random access indexing by `usize`
10321032///
10331033/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
@@ -1067,6 +1067,9 @@ pub trait ExactSizeIterator: Iterator {
10671067 }
10681068}
10691069
1070+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1071+ impl < ' a , I : ExactSizeIterator + ?Sized > ExactSizeIterator for & ' a mut I { }
1072+
10701073// All adaptors that preserve the size of the wrapped iterator are fine
10711074// Adaptors that may overflow in `size_hint` are not, i.e. `Chain`.
10721075#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1119,32 +1122,6 @@ impl<I> RandomAccessIterator for Rev<I> where I: DoubleEndedIterator + RandomAcc
11191122 }
11201123}
11211124
1122- /// A mutable reference to an iterator
1123- #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1124- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1125- pub struct ByRef < ' a , I : ' a > {
1126- iter : & ' a mut I ,
1127- }
1128-
1129- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1130- impl < ' a , I > Iterator for ByRef < ' a , I > where I : ' a + Iterator {
1131- type Item = <I as Iterator >:: Item ;
1132-
1133- #[ inline]
1134- fn next ( & mut self ) -> Option < <I as Iterator >:: Item > { self . iter . next ( ) }
1135- #[ inline]
1136- fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
1137- }
1138-
1139- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1140- impl < ' a , I > DoubleEndedIterator for ByRef < ' a , I > where I : ' a + DoubleEndedIterator {
1141- #[ inline]
1142- fn next_back ( & mut self ) -> Option < <I as Iterator >:: Item > { self . iter . next_back ( ) }
1143- }
1144-
1145- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1146- impl < ' a , I > ExactSizeIterator for ByRef < ' a , I > where I : ' a + ExactSizeIterator { }
1147-
11481125/// A trait for iterators over elements which can be added together
11491126#[ unstable( feature = "core" ,
11501127 reason = "needs to be re-evaluated as part of numerics reform" ) ]
0 commit comments