@@ -557,13 +557,13 @@ use crate::iter::{self, FromIterator, FusedIterator, TrustedLen};
557
557
use crate :: panicking:: { panic, panic_str} ;
558
558
use crate :: pin:: Pin ;
559
559
use crate :: {
560
- convert, hint, mem,
560
+ cmp , convert, hint, mem,
561
561
ops:: { self , ControlFlow , Deref , DerefMut } ,
562
562
slice,
563
563
} ;
564
564
565
565
/// The `Option` type. See [the module level documentation](self) for more.
566
- #[ derive( Copy , PartialOrd , Eq , Ord , Debug , Hash ) ]
566
+ #[ derive( Copy , Eq , Debug , Hash ) ]
567
567
#[ rustc_diagnostic_item = "Option" ]
568
568
#[ lang = "Option" ]
569
569
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -2162,6 +2162,35 @@ impl<T: PartialEq> PartialEq for Option<T> {
2162
2162
}
2163
2163
}
2164
2164
2165
+ // Manually implementing here somewhat improves codegen for
2166
+ // https://github.com/rust-lang/rust/issues/49892, although still
2167
+ // not optimal.
2168
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2169
+ impl < T : PartialOrd > PartialOrd for Option < T > {
2170
+ #[ inline]
2171
+ fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
2172
+ match ( self , other) {
2173
+ ( Some ( l) , Some ( r) ) => l. partial_cmp ( r) ,
2174
+ ( Some ( _) , None ) => Some ( cmp:: Ordering :: Greater ) ,
2175
+ ( None , Some ( _) ) => Some ( cmp:: Ordering :: Less ) ,
2176
+ ( None , None ) => Some ( cmp:: Ordering :: Equal ) ,
2177
+ }
2178
+ }
2179
+ }
2180
+
2181
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2182
+ impl < T : Ord > Ord for Option < T > {
2183
+ #[ inline]
2184
+ fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
2185
+ match ( self , other) {
2186
+ ( Some ( l) , Some ( r) ) => l. cmp ( r) ,
2187
+ ( Some ( _) , None ) => cmp:: Ordering :: Greater ,
2188
+ ( None , Some ( _) ) => cmp:: Ordering :: Less ,
2189
+ ( None , None ) => cmp:: Ordering :: Equal ,
2190
+ }
2191
+ }
2192
+ }
2193
+
2165
2194
/////////////////////////////////////////////////////////////////////////////
2166
2195
// The Option Iterators
2167
2196
/////////////////////////////////////////////////////////////////////////////
0 commit comments