Rollup merge of #95017 - zachs18:cmp_ordering_derive_eq, r=Dylan-DPC
Derive Eq for std::cmp::Ordering, instead of using manual impl. This allows consts of type Ordering to be used in patterns, and with feature(adt_const_params) allows using `Ordering` as a const generic parameter. Currently, `std::cmp::Ordering` implements `Eq` using a manually written `impl Eq for Ordering {}`, instead of `derive(Eq)`. This means that it does not implement `StructuralEq`. This commit removes the manually written impl, and adds `derive(Eq)` to `Ordering`, so that it will implement `StructuralEq`.
This commit is contained in:
commit
4ead6d9dc7
@ -333,7 +333,7 @@ pub struct AssertParamIsEq<T: Eq + ?Sized> {
|
|||||||
/// let result = 2.cmp(&1);
|
/// let result = 2.cmp(&1);
|
||||||
/// assert_eq!(Ordering::Greater, result);
|
/// assert_eq!(Ordering::Greater, result);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Copy, PartialEq, Debug, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[repr(i8)]
|
#[repr(i8)]
|
||||||
pub enum Ordering {
|
pub enum Ordering {
|
||||||
@ -861,9 +861,6 @@ pub macro Ord($item:item) {
|
|||||||
/* compiler built-in */
|
/* compiler built-in */
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl Eq for Ordering {}
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl Ord for Ordering {
|
impl Ord for Ordering {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -133,6 +133,19 @@ fn ordering_const() {
|
|||||||
assert_eq!(THEN, Greater);
|
assert_eq!(THEN, Greater);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ordering_structural_eq() {
|
||||||
|
// test that consts of type `Ordering` are usable in patterns
|
||||||
|
|
||||||
|
const ORDERING: Ordering = Greater;
|
||||||
|
|
||||||
|
const REVERSE: Ordering = ORDERING.reverse();
|
||||||
|
match Ordering::Less {
|
||||||
|
REVERSE => {}
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cmp_default() {
|
fn cmp_default() {
|
||||||
// Test default methods in PartialOrd and PartialEq
|
// Test default methods in PartialOrd and PartialEq
|
||||||
|
Loading…
x
Reference in New Issue
Block a user