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.
This commit is contained in:
parent
f4c675c476
commit
bd6deaa08d
@ -330,7 +330,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
|
||||
/// assert_eq!(arr[1..=3], [ 1,2,3 ]); // RangeInclusive
|
||||
/// ```
|
||||
#[doc(alias = "..=")]
|
||||
#[derive(Clone)] // not Copy -- see #27186
|
||||
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
|
||||
#[stable(feature = "inclusive_range", since = "1.26.0")]
|
||||
pub struct RangeInclusive<Idx> {
|
||||
// Note that the fields here are not public to allow changing the
|
||||
@ -350,26 +350,6 @@ pub struct RangeInclusive<Idx> {
|
||||
pub(crate) exhausted: bool,
|
||||
}
|
||||
|
||||
#[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 && self.exhausted == other.exhausted
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "inclusive_range", since = "1.26.0")]
|
||||
impl<Idx: Eq> Eq for RangeInclusive<Idx> {}
|
||||
|
||||
#[stable(feature = "inclusive_range", since = "1.26.0")]
|
||||
impl<Idx: Hash> Hash for RangeInclusive<Idx> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.start.hash(state);
|
||||
self.end.hash(state);
|
||||
self.exhausted.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<Idx> RangeInclusive<Idx> {
|
||||
/// Creates a new inclusive range. Equivalent to writing `start..=end`.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user