From f4ff6860dcefbe59fac837f7208a83b5f83b2820 Mon Sep 17 00:00:00 2001 From: raldone01 Date: Wed, 14 Sep 2022 18:31:53 +0200 Subject: [PATCH] Constify `PartialEq` for Ordering. --- library/core/src/cmp.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index 8a30bb6745060..d9f2d3d64d667 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -23,6 +23,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::marker::Destruct; +use crate::marker::StructuralPartialEq; use self::Ordering::*; @@ -338,7 +339,7 @@ pub struct AssertParamIsEq { /// let result = 2.cmp(&1); /// assert_eq!(Ordering::Greater, result); /// ``` -#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, Copy, Eq, Debug, Hash)] #[stable(feature = "rust1", since = "1.0.0")] #[repr(i8)] pub enum Ordering { @@ -884,6 +885,18 @@ pub macro Ord($item:item) { /* compiler built-in */ } +#[stable(feature = "rust1", since = "1.0.0")] +impl StructuralPartialEq for Ordering {} + +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_cmp", issue = "92391")] +impl const PartialEq for Ordering { + #[inline] + fn eq(&self, other: &Self) -> bool { + (*self as i32).eq(&(*other as i32)) + } +} + #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] impl const Ord for Ordering {