@@ -341,16 +341,15 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
341341
342342 #[ inline]
343343 fn next ( & mut self ) -> Option < A > {
344- self . compute_is_empty ( ) ;
345- if self . is_empty . unwrap_or_default ( ) {
344+ if self . is_empty ( ) {
346345 return None ;
347346 }
348347 let is_iterating = self . start < self . end ;
349- self . is_empty = Some ( !is_iterating) ;
350348 Some ( if is_iterating {
351349 let n = self . start . add_one ( ) ;
352350 mem:: replace ( & mut self . start , n)
353351 } else {
352+ self . exhausted = true ;
354353 self . start . clone ( )
355354 } )
356355 }
@@ -369,8 +368,7 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
369368
370369 #[ inline]
371370 fn nth ( & mut self , n : usize ) -> Option < A > {
372- self . compute_is_empty ( ) ;
373- if self . is_empty . unwrap_or_default ( ) {
371+ if self . is_empty ( ) {
374372 return None ;
375373 }
376374
@@ -379,21 +377,20 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
379377
380378 match plus_n. partial_cmp ( & self . end ) {
381379 Some ( Less ) => {
382- self . is_empty = Some ( false ) ;
383380 self . start = plus_n. add_one ( ) ;
384381 return Some ( plus_n) ;
385382 }
386383 Some ( Equal ) => {
387- self . is_empty = Some ( true ) ;
388384 self . start = plus_n. clone ( ) ;
385+ self . exhausted = true ;
389386 return Some ( plus_n) ;
390387 }
391388 _ => { }
392389 }
393390 }
394391
395392 self . start = self . end . clone ( ) ;
396- self . is_empty = Some ( true ) ;
393+ self . exhausted = true ;
397394 None
398395 }
399396
@@ -404,8 +401,6 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
404401 F : FnMut ( B , Self :: Item ) -> R ,
405402 R : Try < Ok = B > ,
406403 {
407- self . compute_is_empty ( ) ;
408-
409404 if self . is_empty ( ) {
410405 return Try :: from_ok ( init) ;
411406 }
@@ -418,7 +413,7 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
418413 accum = f ( accum, n) ?;
419414 }
420415
421- self . is_empty = Some ( true ) ;
416+ self . exhausted = true ;
422417
423418 if self . start == self . end {
424419 accum = f ( accum, self . start . clone ( ) ) ?;
@@ -447,24 +442,22 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
447442impl < A : Step > DoubleEndedIterator for ops:: RangeInclusive < A > {
448443 #[ inline]
449444 fn next_back ( & mut self ) -> Option < A > {
450- self . compute_is_empty ( ) ;
451- if self . is_empty . unwrap_or_default ( ) {
445+ if self . is_empty ( ) {
452446 return None ;
453447 }
454448 let is_iterating = self . start < self . end ;
455- self . is_empty = Some ( !is_iterating) ;
456449 Some ( if is_iterating {
457450 let n = self . end . sub_one ( ) ;
458451 mem:: replace ( & mut self . end , n)
459452 } else {
453+ self . exhausted = true ;
460454 self . end . clone ( )
461455 } )
462456 }
463457
464458 #[ inline]
465459 fn nth_back ( & mut self , n : usize ) -> Option < A > {
466- self . compute_is_empty ( ) ;
467- if self . is_empty . unwrap_or_default ( ) {
460+ if self . is_empty ( ) {
468461 return None ;
469462 }
470463
@@ -473,21 +466,20 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
473466
474467 match minus_n. partial_cmp ( & self . start ) {
475468 Some ( Greater ) => {
476- self . is_empty = Some ( false ) ;
477469 self . end = minus_n. sub_one ( ) ;
478470 return Some ( minus_n) ;
479471 }
480472 Some ( Equal ) => {
481- self . is_empty = Some ( true ) ;
482473 self . end = minus_n. clone ( ) ;
474+ self . exhausted = true ;
483475 return Some ( minus_n) ;
484476 }
485477 _ => { }
486478 }
487479 }
488480
489481 self . end = self . start . clone ( ) ;
490- self . is_empty = Some ( true ) ;
482+ self . exhausted = true ;
491483 None
492484 }
493485
@@ -498,8 +490,6 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
498490 F : FnMut ( B , Self :: Item ) -> R ,
499491 R : Try < Ok = B > ,
500492 {
501- self . compute_is_empty ( ) ;
502-
503493 if self . is_empty ( ) {
504494 return Try :: from_ok ( init) ;
505495 }
@@ -512,7 +502,7 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
512502 accum = f ( accum, n) ?;
513503 }
514504
515- self . is_empty = Some ( true ) ;
505+ self . exhausted = true ;
516506
517507 if self . start == self . end {
518508 accum = f ( accum, self . start . clone ( ) ) ?;
0 commit comments