diff options
| -rw-r--r-- | src/libcore/ops/range.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 3f9ac8a54bf..0f119789a75 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -341,11 +341,29 @@ pub struct RangeInclusive<Idx> { // accept non-PartialOrd types, also we want the constructor to be const. } +trait RangeInclusiveEquality: Sized { + fn canonicalized_is_empty(range: &RangeInclusive<Self>) -> bool; +} +impl<T> RangeInclusiveEquality for T { + #[inline] + default fn canonicalized_is_empty(range: &RangeInclusive<Self>) -> bool { + !range.is_iterating.unwrap_or(false) + } +} +impl<T: PartialOrd> RangeInclusiveEquality for T { + #[inline] + fn canonicalized_is_empty(range: &RangeInclusive<Self>) -> bool { + range.is_empty() + } +} + #[stable(feature = "inclusive_range", since = "1.26.0")] impl<Idx: PartialEq> PartialEq for RangeInclusive<Idx> { #[inline] fn eq(&self, other: &Self) -> bool { self.start == other.start && self.end == other.end + && RangeInclusiveEquality::canonicalized_is_empty(self) + == RangeInclusiveEquality::canonicalized_is_empty(other) } } @@ -357,6 +375,7 @@ impl<Idx: Hash> Hash for RangeInclusive<Idx> { fn hash<H: Hasher>(&self, state: &mut H) { self.start.hash(state); self.end.hash(state); + RangeInclusiveEquality::canonicalized_is_empty(self).hash(state); } } |
