Skip to content

Commit

Permalink
make exhausted RangeInclusive::end_bound return Excluded(end)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Oct 19, 2020
1 parent b62b352 commit 9fd79a3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions library/core/src/ops/range.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 9fd79a3

Please sign in to comment.