diff --git a/src/naive/date.rs b/src/naive/date.rs index e178f5e..6fe21e1 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -3,7 +3,7 @@ //! ISO 8601 calendar date without timezone. -use std::{str, fmt, hash}; +use std::{str, fmt}; use std::ops::{Add, Sub, AddAssign, SubAssign}; use num::traits::ToPrimitive; use oldtime::Duration as OldDuration; @@ -93,7 +93,7 @@ const MAX_BITS: usize = 44; /// The year number is same to that of the [calendar date](#calendar-date). /// /// This is currently the internal format of Chrono's date types. -#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone)] +#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] pub struct NaiveDate { ymdf: DateImpl, // (year << 13) | of } @@ -1302,14 +1302,6 @@ impl Datelike for NaiveDate { } } -/// `NaiveDate` can be used as a key to the hash maps. -impl hash::Hash for NaiveDate { - fn hash(&self, state: &mut H) { - // don't need to strip flags, as we can safely assume that it is correct - self.ymdf.hash(state); - } -} - /// An addition of `Duration` to `NaiveDate` discards the fractional days, /// rounding to the closest integral number of days towards `Duration::zero()`. /// diff --git a/src/naive/datetime.rs b/src/naive/datetime.rs index 247ee8a..0a022d4 100644 --- a/src/naive/datetime.rs +++ b/src/naive/datetime.rs @@ -1103,6 +1103,7 @@ impl Timelike for NaiveDateTime { /// /// Practically this also takes account of fractional seconds, so it is not recommended. /// (For the obvious reason this also distinguishes leap seconds from non-leap seconds.) +#[cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))] impl hash::Hash for NaiveDateTime { fn hash(&self, state: &mut H) { self.date.hash(state); diff --git a/src/naive/time.rs b/src/naive/time.rs index 3222c7a..1a337ab 100644 --- a/src/naive/time.rs +++ b/src/naive/time.rs @@ -981,6 +981,7 @@ impl Timelike for NaiveTime { /// /// Practically this also takes account of fractional seconds, so it is not recommended. /// (For the obvious reason this also distinguishes leap seconds from non-leap seconds.) +#[cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))] impl hash::Hash for NaiveTime { fn hash(&self, state: &mut H) { self.secs.hash(state);