Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Feb 15, 2022
1 parent a95fb8b commit 80632de
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions compiler/rustc_data_structures/src/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,13 @@ impl<'a, T> PartialEq for Interned<'a, T> {

impl<'a, T> Eq for Interned<'a, T> {}

impl<'a, T: PartialOrd> PartialOrd for Interned<'a, T> {
// In practice you can't intern any `T` that doesn't implement `Eq`, because
// that's needed for hashing. Therefore, we won't be interning any `T` that
// implements `PartialOrd` without also implementing `Ord`. So we can have the
// bound `T: Ord` here and avoid duplication with the `Ord` impl below.
impl<'a, T: Ord> PartialOrd for Interned<'a, T> {
fn partial_cmp(&self, other: &Interned<'a, T>) -> Option<Ordering> {
// Pointer equality implies equality, due to the uniqueness constraint,
// but the contents must be compared otherwise.
if ptr::eq(self.0, other.0) {
Some(Ordering::Equal)
} else {
let res = self.0.partial_cmp(&other.0);
debug_assert!(res != Some(Ordering::Equal));
res
}
Some(self.cmp(other))
}
}

Expand All @@ -84,7 +80,7 @@ impl<'a, T: Ord> Ord for Interned<'a, T> {
Ordering::Equal
} else {
let res = self.0.cmp(&other.0);
debug_assert!(res != Ordering::Equal);
debug_assert_ne!(res, Ordering::Equal);
res
}
}
Expand Down

0 comments on commit 80632de

Please sign in to comment.