Skip to content

Commit 80632de

Browse files
committed
Address review comments.
1 parent a95fb8b commit 80632de

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

Diff for: compiler/rustc_data_structures/src/intern.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,13 @@ impl<'a, T> PartialEq for Interned<'a, T> {
6262

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

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

@@ -84,7 +80,7 @@ impl<'a, T: Ord> Ord for Interned<'a, T> {
8480
Ordering::Equal
8581
} else {
8682
let res = self.0.cmp(&other.0);
87-
debug_assert!(res != Ordering::Equal);
83+
debug_assert_ne!(res, Ordering::Equal);
8884
res
8985
}
9086
}

0 commit comments

Comments
 (0)