From 80632de4a1f9d1c0dfe16170fc079e940f42776a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 8 Feb 2022 14:12:29 +1100 Subject: [PATCH] Address review comments. --- compiler/rustc_data_structures/src/intern.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_data_structures/src/intern.rs b/compiler/rustc_data_structures/src/intern.rs index e5d43db327b..c79a5ebf093 100644 --- a/compiler/rustc_data_structures/src/intern.rs +++ b/compiler/rustc_data_structures/src/intern.rs @@ -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 { - // 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)) } } @@ -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 } }