@@ -800,7 +800,10 @@ pub trait Ord: Eq + PartialOrd<Self> {
800
800
Self : Sized ,
801
801
Self : ~const Destruct ,
802
802
{
803
- max_by ( self , other, Ord :: cmp)
803
+ match self . cmp ( & other) {
804
+ Ordering :: Less | Ordering :: Equal => other,
805
+ Ordering :: Greater => self ,
806
+ }
804
807
}
805
808
806
809
/// Compares and returns the minimum of two values.
@@ -821,7 +824,10 @@ pub trait Ord: Eq + PartialOrd<Self> {
821
824
Self : Sized ,
822
825
Self : ~const Destruct ,
823
826
{
824
- min_by ( self , other, Ord :: cmp)
827
+ match self . cmp ( & other) {
828
+ Ordering :: Less | Ordering :: Equal => self ,
829
+ Ordering :: Greater => other,
830
+ }
825
831
}
826
832
827
833
/// Restrict a value to a certain interval.
@@ -1184,12 +1190,7 @@ pub const fn min<T: ~const Ord + ~const Destruct>(v1: T, v2: T) -> T {
1184
1190
#[ inline]
1185
1191
#[ must_use]
1186
1192
#[ stable( feature = "cmp_min_max_by" , since = "1.53.0" ) ]
1187
- #[ rustc_const_unstable( feature = "const_cmp" , issue = "92391" ) ]
1188
- pub const fn min_by < T , F : ~const FnOnce ( & T , & T ) -> Ordering > ( v1 : T , v2 : T , compare : F ) -> T
1189
- where
1190
- T : ~const Destruct ,
1191
- F : ~const Destruct ,
1192
- {
1193
+ pub fn min_by < T , F : FnOnce ( & T , & T ) -> Ordering > ( v1 : T , v2 : T , compare : F ) -> T {
1193
1194
match compare ( & v1, & v2) {
1194
1195
Ordering :: Less | Ordering :: Equal => v1,
1195
1196
Ordering :: Greater => v2,
@@ -1211,14 +1212,8 @@ where
1211
1212
#[ inline]
1212
1213
#[ must_use]
1213
1214
#[ stable( feature = "cmp_min_max_by" , since = "1.53.0" ) ]
1214
- #[ rustc_const_unstable( feature = "const_cmp" , issue = "92391" ) ]
1215
- pub const fn min_by_key < T , F : ~const FnMut ( & T ) -> K , K : ~const Ord > ( v1 : T , v2 : T , mut f : F ) -> T
1216
- where
1217
- T : ~const Destruct ,
1218
- F : ~const Destruct ,
1219
- K : ~const Destruct ,
1220
- {
1221
- min_by ( v1, v2, const |v1, v2| f ( v1) . cmp ( & f ( v2) ) )
1215
+ pub fn min_by_key < T , F : FnMut ( & T ) -> K , K : Ord > ( v1 : T , v2 : T , mut f : F ) -> T {
1216
+ min_by ( v1, v2, |v1, v2| f ( v1) . cmp ( & f ( v2) ) )
1222
1217
}
1223
1218
1224
1219
/// Compares and returns the maximum of two values.
@@ -1259,12 +1254,7 @@ pub const fn max<T: ~const Ord + ~const Destruct>(v1: T, v2: T) -> T {
1259
1254
#[ inline]
1260
1255
#[ must_use]
1261
1256
#[ stable( feature = "cmp_min_max_by" , since = "1.53.0" ) ]
1262
- #[ rustc_const_unstable( feature = "const_cmp" , issue = "92391" ) ]
1263
- pub const fn max_by < T , F : ~const FnOnce ( & T , & T ) -> Ordering > ( v1 : T , v2 : T , compare : F ) -> T
1264
- where
1265
- T : ~const Destruct ,
1266
- F : ~const Destruct ,
1267
- {
1257
+ pub fn max_by < T , F : FnOnce ( & T , & T ) -> Ordering > ( v1 : T , v2 : T , compare : F ) -> T {
1268
1258
match compare ( & v1, & v2) {
1269
1259
Ordering :: Less | Ordering :: Equal => v2,
1270
1260
Ordering :: Greater => v1,
@@ -1286,14 +1276,8 @@ where
1286
1276
#[ inline]
1287
1277
#[ must_use]
1288
1278
#[ stable( feature = "cmp_min_max_by" , since = "1.53.0" ) ]
1289
- #[ rustc_const_unstable( feature = "const_cmp" , issue = "92391" ) ]
1290
- pub const fn max_by_key < T , F : ~const FnMut ( & T ) -> K , K : ~const Ord > ( v1 : T , v2 : T , mut f : F ) -> T
1291
- where
1292
- T : ~const Destruct ,
1293
- F : ~const Destruct ,
1294
- K : ~const Destruct ,
1295
- {
1296
- max_by ( v1, v2, const |v1, v2| f ( v1) . cmp ( & f ( v2) ) )
1279
+ pub fn max_by_key < T , F : FnMut ( & T ) -> K , K : Ord > ( v1 : T , v2 : T , mut f : F ) -> T {
1280
+ max_by ( v1, v2, |v1, v2| f ( v1) . cmp ( & f ( v2) ) )
1297
1281
}
1298
1282
1299
1283
// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
0 commit comments