diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2018-02-09 17:54:27 -0800 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2018-02-09 17:54:27 -0800 |
| commit | b5cb393cf5b4a65fb99d8b1e43450fb87567788b (patch) | |
| tree | abee324c966322f576a7dd646cf865fdc7d39881 /src/libcore/ops | |
| parent | 7fe182fdfe01e01dd899962cc8dbaea63f422c9c (diff) | |
Use is_empty in range iteration exhaustion tests
Diffstat (limited to 'src/libcore/ops')
| -rw-r--r-- | src/libcore/ops/range.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 102e08362cb..cce593ee208 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -262,6 +262,13 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> { /// The `RangeInclusive` `start..=end` contains all values with `x >= start` /// and `x <= end`. /// +/// This iterator is [fused], but the specific values of `start` and `end` after +/// iteration has finished are **unspecified** other than that [`.is_empty()`] +/// will return `true` once no more values will be produced. +/// +/// [fused]: ../iter/trait.FusedIterator.html +/// [`.is_empty()`]: #method.is_empty +/// /// # Examples /// /// ``` @@ -329,6 +336,17 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> { /// assert!(!(3..=3).is_empty()); /// assert!( (3..=2).is_empty()); /// ``` + /// + /// This method returns `true` after iteration has finished: + /// + /// ``` + /// #![feature(range_is_empty,inclusive_range_syntax)] + /// + /// let mut r = 3..=5; + /// for _ in r.by_ref() {} + /// // Precise field values are unspecified here + /// assert!(r.is_empty()); + /// ``` #[unstable(feature = "range_is_empty", reason = "recently added", issue = "123456789")] pub fn is_empty(&self) -> bool { !(self.start <= self.end) |
