File tree 1 file changed +11
-1
lines changed
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -479,13 +479,23 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
479
479
/// assert!(!(0.0..=f32::NAN).contains(&0.0));
480
480
/// assert!(!(f32::NAN..=1.0).contains(&1.0));
481
481
/// ```
482
+ ///
483
+ /// This method always returns `false` after iteration has finished:
484
+ ///
485
+ /// ```
486
+ /// let mut r = 3..=5;
487
+ /// assert!(r.contains(&3) && r.contains(&5));
488
+ /// for _ in r.by_ref() {}
489
+ /// // Precise field values are unspecified here
490
+ /// assert!(!r.contains(&3) && !r.contains(&5));
491
+ /// ```
482
492
#[ stable( feature = "range_contains" , since = "1.35.0" ) ]
483
493
pub fn contains < U > ( & self , item : & U ) -> bool
484
494
where
485
495
Idx : PartialOrd < U > ,
486
496
U : ?Sized + PartialOrd < Idx > ,
487
497
{
488
- <Self as RangeBounds < Idx > >:: contains ( self , item)
498
+ ! self . exhausted && <Self as RangeBounds < Idx > >:: contains ( self , item)
489
499
}
490
500
491
501
/// Returns `true` if the range contains no items.
You can’t perform that action at this time.
0 commit comments