@@ -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`
@@ -548,9 +543,7 @@ pub trait IteratorExt: Iterator + Sized {
548543 /// assert!(it.next() == Some(5));
549544 /// ```
550545 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
551- fn by_ref < ' r > ( & ' r mut self ) -> ByRef < ' r , Self > {
552- ByRef { iter : self }
553- }
546+ fn by_ref ( & mut self ) -> & mut Self { self }
554547
555548 /// Loops through the entire iterator, collecting all of the elements into
556549 /// a container implementing `FromIterator`.
@@ -1017,15 +1010,22 @@ impl<I> IteratorExt for I where I: Iterator {}
10171010
10181011/// A range iterator able to yield elements from both ends
10191012///
1020- /// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust
1021- /// elements from the *same* range, and do not work independently of each other.
1013+ /// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and
1014+ /// `next_back()` exhaust elements from the *same* range, and do not work
1015+ /// independently of each other.
10221016#[ stable( feature = "rust1" , since = "1.0.0" ) ]
10231017pub trait DoubleEndedIterator : Iterator {
1024- /// Yield an element from the end of the range, returning `None` if the range is empty.
1018+ /// Yield an element from the end of the range, returning `None` if the
1019+ /// range is empty.
10251020 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
10261021 fn next_back ( & mut self ) -> Option < Self :: Item > ;
10271022}
10281023
1024+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1025+ impl < ' a , I : DoubleEndedIterator + ?Sized > DoubleEndedIterator for & ' a mut I {
1026+ fn next_back ( & mut self ) -> Option < I :: Item > { ( * * self ) . next_back ( ) }
1027+ }
1028+
10291029/// An object implementing random access indexing by `usize`
10301030///
10311031/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
@@ -1065,6 +1065,9 @@ pub trait ExactSizeIterator: Iterator {
10651065 }
10661066}
10671067
1068+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1069+ impl < ' a , I : ExactSizeIterator + ?Sized > ExactSizeIterator for & ' a mut I { }
1070+
10681071// All adaptors that preserve the size of the wrapped iterator are fine
10691072// Adaptors that may overflow in `size_hint` are not, i.e. `Chain`.
10701073#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1117,32 +1120,6 @@ impl<I> RandomAccessIterator for Rev<I> where I: DoubleEndedIterator + RandomAcc
11171120 }
11181121}
11191122
1120- /// A mutable reference to an iterator
1121- #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1122- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1123- pub struct ByRef < ' a , I : ' a > {
1124- iter : & ' a mut I ,
1125- }
1126-
1127- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1128- impl < ' a , I > Iterator for ByRef < ' a , I > where I : ' a + Iterator {
1129- type Item = <I as Iterator >:: Item ;
1130-
1131- #[ inline]
1132- fn next ( & mut self ) -> Option < <I as Iterator >:: Item > { self . iter . next ( ) }
1133- #[ inline]
1134- fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
1135- }
1136-
1137- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1138- impl < ' a , I > DoubleEndedIterator for ByRef < ' a , I > where I : ' a + DoubleEndedIterator {
1139- #[ inline]
1140- fn next_back ( & mut self ) -> Option < <I as Iterator >:: Item > { self . iter . next_back ( ) }
1141- }
1142-
1143- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1144- impl < ' a , I > ExactSizeIterator for ByRef < ' a , I > where I : ' a + ExactSizeIterator { }
1145-
11461123/// A trait for iterators over elements which can be added together
11471124#[ unstable( feature = "core" ,
11481125 reason = "needs to be re-evaluated as part of numerics reform" ) ]
0 commit comments