Skip to content

Commit b71b640

Browse files
authored
Rollup merge of rust-lang#101810 - raldone01:feat/const_partial_eq_ordering, r=fee1-dead
Constify `PartialEq` for `Ordering` Adds `impl const PartialEq for Ordering {}` to rust-lang#92391.
2 parents a88b96b + f4ff686 commit b71b640

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

library/core/src/cmp.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![stable(feature = "rust1", since = "1.0.0")]
2424

2525
use crate::marker::Destruct;
26+
use crate::marker::StructuralPartialEq;
2627

2728
use self::Ordering::*;
2829

@@ -338,7 +339,7 @@ pub struct AssertParamIsEq<T: Eq + ?Sized> {
338339
/// let result = 2.cmp(&1);
339340
/// assert_eq!(Ordering::Greater, result);
340341
/// ```
341-
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
342+
#[derive(Clone, Copy, Eq, Debug, Hash)]
342343
#[stable(feature = "rust1", since = "1.0.0")]
343344
#[repr(i8)]
344345
pub enum Ordering {
@@ -884,6 +885,18 @@ pub macro Ord($item:item) {
884885
/* compiler built-in */
885886
}
886887

888+
#[stable(feature = "rust1", since = "1.0.0")]
889+
impl StructuralPartialEq for Ordering {}
890+
891+
#[stable(feature = "rust1", since = "1.0.0")]
892+
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
893+
impl const PartialEq for Ordering {
894+
#[inline]
895+
fn eq(&self, other: &Self) -> bool {
896+
(*self as i32).eq(&(*other as i32))
897+
}
898+
}
899+
887900
#[stable(feature = "rust1", since = "1.0.0")]
888901
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
889902
impl const Ord for Ordering {

0 commit comments

Comments
 (0)