Skip to content

Commit 9fd79a3

Browse files
committed
make exhausted RangeInclusive::end_bound return Excluded(end)
1 parent b62b352 commit 9fd79a3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

library/core/src/ops/range.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
495495
Idx: PartialOrd<U>,
496496
U: ?Sized + PartialOrd<Idx>,
497497
{
498-
!self.exhausted && <Self as RangeBounds<Idx>>::contains(self, item)
498+
<Self as RangeBounds<Idx>>::contains(self, item)
499499
}
500500

501501
/// Returns `true` if the range contains no items.
@@ -891,7 +891,13 @@ impl<T> RangeBounds<T> for RangeInclusive<T> {
891891
Included(&self.start)
892892
}
893893
fn end_bound(&self) -> Bound<&T> {
894-
Included(&self.end)
894+
if self.exhausted {
895+
// When the iterator is exhausted, we usually have start == end,
896+
// but we want the range to appear empty, containing nothing.
897+
Excluded(&self.end)
898+
} else {
899+
Included(&self.end)
900+
}
895901
}
896902
}
897903

0 commit comments

Comments
 (0)