Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bd6deaa

Browse files
author
CDirkx
committed
Derive PartialEq, Eq and Hash for RangeInclusive
The manual implementation of PartialEq, Eq and Hash for RangeInclusive was functionally equivalent to a derived implementation. This change removes the manual implementation and adds the respective derives. A side effect of this change is that the derives also add implementations for StructuralPartialEq and StructuralEq, which enables RangeInclusive to be used in const generics.
1 parent f4c675c commit bd6deaa

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

src/libcore/ops/range.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
330330
/// assert_eq!(arr[1..=3], [ 1,2,3 ]); // RangeInclusive
331331
/// ```
332332
#[doc(alias = "..=")]
333-
#[derive(Clone)] // not Copy -- see #27186
333+
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
334334
#[stable(feature = "inclusive_range", since = "1.26.0")]
335335
pub struct RangeInclusive<Idx> {
336336
// Note that the fields here are not public to allow changing the
@@ -350,26 +350,6 @@ pub struct RangeInclusive<Idx> {
350350
pub(crate) exhausted: bool,
351351
}
352352

353-
#[stable(feature = "inclusive_range", since = "1.26.0")]
354-
impl<Idx: PartialEq> PartialEq for RangeInclusive<Idx> {
355-
#[inline]
356-
fn eq(&self, other: &Self) -> bool {
357-
self.start == other.start && self.end == other.end && self.exhausted == other.exhausted
358-
}
359-
}
360-
361-
#[stable(feature = "inclusive_range", since = "1.26.0")]
362-
impl<Idx: Eq> Eq for RangeInclusive<Idx> {}
363-
364-
#[stable(feature = "inclusive_range", since = "1.26.0")]
365-
impl<Idx: Hash> Hash for RangeInclusive<Idx> {
366-
fn hash<H: Hasher>(&self, state: &mut H) {
367-
self.start.hash(state);
368-
self.end.hash(state);
369-
self.exhausted.hash(state);
370-
}
371-
}
372-
373353
impl<Idx> RangeInclusive<Idx> {
374354
/// Creates a new inclusive range. Equivalent to writing `start..=end`.
375355
///

0 commit comments

Comments
 (0)