mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Implement SpecOptionPartialEq
for cmp::Ordering
This commit is contained in:
parent
e08b379d5d
commit
3122db7d03
@ -551,7 +551,7 @@ use crate::marker::Destruct;
|
||||
use crate::panicking::{panic, panic_str};
|
||||
use crate::pin::Pin;
|
||||
use crate::{
|
||||
convert, hint, mem,
|
||||
cmp, convert, hint, mem,
|
||||
ops::{self, ControlFlow, Deref, DerefMut},
|
||||
};
|
||||
|
||||
@ -2146,6 +2146,14 @@ impl<T> SpecOptionPartialEq for crate::ptr::NonNull<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl SpecOptionPartialEq for cmp::Ordering {
|
||||
#[inline]
|
||||
fn eq(l: &Option<Self>, r: &Option<Self>) -> bool {
|
||||
l.map_or(2, |x| x as i8) == r.map_or(2, |x| x as i8)
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// The Option Iterators
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -3,6 +3,7 @@
|
||||
#![crate_type = "lib"]
|
||||
|
||||
extern crate core;
|
||||
use core::cmp::Ordering;
|
||||
use core::num::{NonZeroU32, NonZeroI64};
|
||||
use core::ptr::NonNull;
|
||||
|
||||
@ -32,3 +33,12 @@ pub fn non_null_eq(l: Option<NonNull<u8>>, r: Option<NonNull<u8>>) -> bool {
|
||||
// CHECK-NEXT: ret i1
|
||||
l == r
|
||||
}
|
||||
|
||||
// CHECK-lABEL: @ordering_eq
|
||||
#[no_mangle]
|
||||
pub fn ordering_eq(l: Option<Ordering>, r: Option<Ordering>) -> bool {
|
||||
// CHECK: start:
|
||||
// CHECK-NEXT: icmp eq i8
|
||||
// CHECK-NEXT: ret i1
|
||||
l == r
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user