Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use smallvec::SmallVec;

use std::borrow::Cow;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::ops::Deref;

pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
Expand Down Expand Up @@ -108,7 +109,7 @@ impl Deref for ObligationCause<'tcx> {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
#[derive(Clone, Debug, PartialEq, Eq, Lift)]
pub struct ObligationCauseData<'tcx> {
pub span: Span,

Expand All @@ -123,6 +124,14 @@ pub struct ObligationCauseData<'tcx> {
pub code: ObligationCauseCode<'tcx>,
}

impl Hash for ObligationCauseData<'_> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For next time: I suggest leaving a brief comment explaining why this custom hash is used, because it's non-obvious and no fun to have to dig through version control history to understand why.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open an issue so it's not forgotten.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to adding comments but

no fun to have to dig through version control history

seems a bit subjective, for me that's 3 clicks which is hardly onerous. So that didn't quite meet my threshold of adding a comment.

fn hash<H: Hasher>(&self, state: &mut H) {
self.body_id.hash(state);
self.span.hash(state);
std::mem::discriminant(&self.code).hash(state);
}
}

impl<'tcx> ObligationCause<'tcx> {
#[inline]
pub fn new(
Expand Down