Allow Clippy lint: derive_hash_xor_eq

The implementation is identical to how #[derive] would do it, and we use the
implementation to add some documentation warning people not to use items with
nanosecond-level precision in hash maps unless they're sure that's what they
want.
This commit is contained in:
Brandon W Maister 2017-07-09 15:21:51 -05:00
parent 4c18d701ca
commit 5643b845a5
3 changed files with 4 additions and 10 deletions

View File

@ -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<H: hash::Hasher>(&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()`.
///

View File

@ -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<H: hash::Hasher>(&self, state: &mut H) {
self.date.hash(state);

View File

@ -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<H: hash::Hasher>(&self, state: &mut H) {
self.secs.hash(state);