@@ -2,7 +2,7 @@ use crate::cmp;
2
2
use crate :: fmt:: { self , Debug } ;
3
3
use crate :: iter:: { DoubleEndedIterator , ExactSizeIterator , FusedIterator , Iterator } ;
4
4
use crate :: iter:: { InPlaceIterable , SourceIter , TrustedLen } ;
5
- use crate :: ops:: { ControlFlow , Try } ;
5
+ use crate :: ops:: { ControlFlow , NeverShortCircuit , Try } ;
6
6
7
7
/// An iterator that iterates two other iterators simultaneously.
8
8
///
@@ -43,13 +43,9 @@ impl<A: Iterator, B: Iterator> Zip<A, B> {
43
43
if a_sz != b_sz {
44
44
// Adjust a, b to equal length
45
45
if a_sz > b_sz {
46
- for _ in 0 ..a_sz - b_sz {
47
- self . a . next_back ( ) ;
48
- }
46
+ let _ = self . a . advance_back_by ( a_sz - b_sz) ;
49
47
} else {
50
- for _ in 0 ..b_sz - a_sz {
51
- self . b . next_back ( ) ;
52
- }
48
+ let _ = self . b . advance_back_by ( b_sz - a_sz) ;
53
49
}
54
50
}
55
51
}
@@ -210,11 +206,6 @@ trait ZipImpl<A, B> {
210
206
Self : Iterator + TrustedRandomAccessNoCoerce ;
211
207
}
212
208
213
- #[ inline]
214
- fn ok < B , T > ( mut f : impl FnMut ( B , T ) -> B ) -> impl FnMut ( B , T ) -> Result < B , !> {
215
- move |acc, x| Ok ( f ( acc, x) )
216
- }
217
-
218
209
#[ inline]
219
210
fn check_rfold < AItem , B : DoubleEndedIterator , T , F : FnMut ( T , ( AItem , B :: Item ) ) -> T > (
220
211
mut b : B ,
@@ -227,16 +218,9 @@ fn check_rfold<AItem, B: DoubleEndedIterator, T, F: FnMut(T, (AItem, B::Item)) -
227
218
}
228
219
229
220
#[ inline]
230
- fn check_try_fold <
231
- ' b ,
232
- AItem ,
233
- B : Iterator ,
234
- T ,
235
- R : Try < Output = T > ,
236
- F : ' b + FnMut ( T , ( AItem , B :: Item ) ) -> R ,
237
- > (
238
- b : & ' b mut B ,
239
- mut f : F ,
221
+ fn check_try_fold < ' b , AItem , BItem , T , R : Try < Output = T > > (
222
+ b : & ' b mut impl Iterator < Item = BItem > ,
223
+ mut f : impl ' b + FnMut ( T , ( AItem , BItem ) ) -> R ,
240
224
) -> impl ' b + FnMut ( T , AItem ) -> ControlFlow < R , T > {
241
225
move |acc, x| match b. next ( ) {
242
226
Some ( y) => ControlFlow :: from_try ( f ( acc, ( x, y) ) ) ,
@@ -311,7 +295,7 @@ macro_rules! zip_impl_general_defaults {
311
295
where
312
296
F : FnMut ( T , Self :: Item ) -> T ,
313
297
{
314
- ZipImpl :: try_fold( & mut self , init, ok ( f) ) . unwrap ( )
298
+ ZipImpl :: try_fold( & mut self , init, NeverShortCircuit :: wrap_mut_2 ( f) ) . 0
315
299
}
316
300
317
301
#[ inline]
@@ -407,6 +391,9 @@ where
407
391
}
408
392
}
409
393
394
+ /// Adjusts a, b to equal length. Makes sure that only the first call
395
+ /// of `next_back` does this, otherwise we will break the restriction
396
+ /// on calls to `zipped.next_back()` after calling `get_unchecked()`.
410
397
#[ inline]
411
398
fn adjust_back_trusted_random_access <
412
399
A : TrustedRandomAccess + DoubleEndedIterator + ExactSizeIterator ,
@@ -417,9 +404,6 @@ fn adjust_back_trusted_random_access<
417
404
if A :: MAY_HAVE_SIDE_EFFECT || B :: MAY_HAVE_SIDE_EFFECT {
418
405
let sz_a = zipped. a . size ( ) ;
419
406
let sz_b = zipped. b . size ( ) ;
420
- // Adjust a, b to equal length, make sure that only the first call
421
- // of `next_back` does this, otherwise we will break the restriction
422
- // on calls to `zipped.next_back()` after calling `get_unchecked()`.
423
407
if sz_a != sz_b {
424
408
let sz_a = zipped. a . size ( ) ;
425
409
if A :: MAY_HAVE_SIDE_EFFECT && sz_a > zipped. len {
0 commit comments