about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2020-10-19 13:46:30 -0700
committerJosh Stone <jistone@redhat.com>2020-10-19 13:46:30 -0700
commit9fd79a39044be777a39604856d0a276484d6480f (patch)
treef5f9cc77fd70b999a7772b21da1f84377d8cf871
parentb62b352f4779072c07c110a63fd83afa9508b9e9 (diff)
downloadrust-9fd79a39044be777a39604856d0a276484d6480f.tar.gz
rust-9fd79a39044be777a39604856d0a276484d6480f.zip
make exhausted RangeInclusive::end_bound return Excluded(end)
-rw-r--r--library/core/src/ops/range.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs
index 1da186d9fbb..084ddffab0b 100644
--- a/library/core/src/ops/range.rs
+++ b/library/core/src/ops/range.rs
@@ -495,7 +495,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
         Idx: PartialOrd<U>,
         U: ?Sized + PartialOrd<Idx>,
     {
-        !self.exhausted && <Self as RangeBounds<Idx>>::contains(self, item)
+        <Self as RangeBounds<Idx>>::contains(self, item)
     }
 
     /// Returns `true` if the range contains no items.
@@ -891,7 +891,13 @@ impl<T> RangeBounds<T> for RangeInclusive<T> {
         Included(&self.start)
     }
     fn end_bound(&self) -> Bound<&T> {
-        Included(&self.end)
+        if self.exhausted {
+            // When the iterator is exhausted, we usually have start == end,
+            // but we want the range to appear empty, containing nothing.
+            Excluded(&self.end)
+        } else {
+            Included(&self.end)
+        }
     }
 }