Address review comments.

This commit is contained in:
Nicholas Nethercote 2022-02-08 14:12:29 +11:00
parent a95fb8b150
commit 80632de4a1
1 changed files with 7 additions and 11 deletions

View File

@ -62,17 +62,13 @@ impl<'a, T> PartialEq for Interned<'a, T> {
impl<'a, T> Eq 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> { fn partial_cmp(&self, other: &Interned<'a, T>) -> Option<Ordering> {
// Pointer equality implies equality, due to the uniqueness constraint, Some(self.cmp(other))
// 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
}
} }
} }
@ -84,7 +80,7 @@ impl<'a, T: Ord> Ord for Interned<'a, T> {
Ordering::Equal Ordering::Equal
} else { } else {
let res = self.0.cmp(&other.0); let res = self.0.cmp(&other.0);
debug_assert!(res != Ordering::Equal); debug_assert_ne!(res, Ordering::Equal);
res res
} }
} }