Skip to content

Commit

Permalink
fix(frontend): span: skip rust_span_data while hashing or compare
Browse files Browse the repository at this point in the history
  • Loading branch information
W95Psp committed Apr 18, 2024
1 parent a05c21a commit 02a88b9
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions frontend/exporter/src/types/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,7 @@ pub struct ExpnData {
}

/// Reflects [`rustc_span::Span`]
#[derive(
Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Hash, PartialOrd, Ord,
)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Eq, Ord)]
pub struct Span {
pub lo: Loc,
pub hi: Loc,
Expand All @@ -820,6 +818,36 @@ pub struct Span {
// expn_backtrace: Vec<ExpnData>,
}

const _: () = {
// `rust_span_data` is a metadata that should *not* be taken into
// account while hashing or comparing

impl std::hash::Hash for Span {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.lo.hash(state);
self.hi.hash(state);
self.filename.hash(state);
}
}
impl PartialEq for Span {
fn eq(&self, other: &Self) -> bool {
self.lo == other.lo && self.hi == other.hi && self.filename == other.filename
}
}

impl PartialOrd for Span {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(
self.lo.partial_cmp(&other.lo)?.then(
self.hi
.partial_cmp(&other.hi)?
.then(self.filename.partial_cmp(&other.filename)?),
),
)
}
}
};

impl Into<Loc> for rustc_span::Loc {
fn into(self) -> Loc {
Loc {
Expand Down

0 comments on commit 02a88b9

Please sign in to comment.