From 9fd79a39044be777a39604856d0a276484d6480f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 19 Oct 2020 13:46:30 -0700 Subject: [PATCH] make exhausted RangeInclusive::end_bound return Excluded(end) --- library/core/src/ops/range.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 1da186d9fbb24..084ddffab0b7a 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -495,7 +495,7 @@ impl> RangeInclusive { Idx: PartialOrd, U: ?Sized + PartialOrd, { - !self.exhausted && >::contains(self, item) + >::contains(self, item) } /// Returns `true` if the range contains no items. @@ -891,7 +891,13 @@ impl RangeBounds for RangeInclusive { 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) + } } }