@@ -551,7 +551,7 @@ use crate::marker::Destruct;
551
551
use crate :: panicking:: { panic, panic_str} ;
552
552
use crate :: pin:: Pin ;
553
553
use crate :: {
554
- convert, hint, mem,
554
+ cmp , convert, hint, mem,
555
555
ops:: { self , ControlFlow , Deref , DerefMut } ,
556
556
} ;
557
557
@@ -2090,6 +2090,12 @@ impl<T: PartialEq> PartialEq for Option<T> {
2090
2090
}
2091
2091
}
2092
2092
2093
+ /// This specialization trait is a workaround for LLVM not currently (2023-01)
2094
+ /// being able to optimize this itself, even though Alive confirms that it would
2095
+ /// be legal to do so: <https://github.com/llvm/llvm-project/issues/52622>
2096
+ ///
2097
+ /// Once that's fixed, `Option` should go back to deriving `PartialEq`, as
2098
+ /// it used to do before <https://github.com/rust-lang/rust/pull/103556>.
2093
2099
#[ unstable( feature = "spec_option_partial_eq" , issue = "none" , reason = "exposed only for rustc" ) ]
2094
2100
#[ doc( hidden) ]
2095
2101
pub trait SpecOptionPartialEq : Sized {
@@ -2146,6 +2152,14 @@ impl<T> SpecOptionPartialEq for crate::ptr::NonNull<T> {
2146
2152
}
2147
2153
}
2148
2154
2155
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2156
+ impl SpecOptionPartialEq for cmp:: Ordering {
2157
+ #[ inline]
2158
+ fn eq ( l : & Option < Self > , r : & Option < Self > ) -> bool {
2159
+ l. map_or ( 2 , |x| x as i8 ) == r. map_or ( 2 , |x| x as i8 )
2160
+ }
2161
+ }
2162
+
2149
2163
/////////////////////////////////////////////////////////////////////////////
2150
2164
// The Option Iterators
2151
2165
/////////////////////////////////////////////////////////////////////////////
0 commit comments