@@ -800,7 +800,10 @@ pub trait Ord: Eq + PartialOrd<Self> {
800800 Self : Sized ,
801801 Self : ~const Destruct ,
802802 {
803- max_by ( self , other, Ord :: cmp)
803+ match self . cmp ( & other) {
804+ Ordering :: Less | Ordering :: Equal => other,
805+ Ordering :: Greater => self ,
806+ }
804807 }
805808
806809 /// Compares and returns the minimum of two values.
@@ -821,7 +824,10 @@ pub trait Ord: Eq + PartialOrd<Self> {
821824 Self : Sized ,
822825 Self : ~const Destruct ,
823826 {
824- min_by ( self , other, Ord :: cmp)
827+ match self . cmp ( & other) {
828+ Ordering :: Less | Ordering :: Equal => self ,
829+ Ordering :: Greater => other,
830+ }
825831 }
826832
827833 /// 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 {
11841190#[ inline]
11851191#[ must_use]
11861192#[ 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 {
11931194 match compare ( & v1, & v2) {
11941195 Ordering :: Less | Ordering :: Equal => v1,
11951196 Ordering :: Greater => v2,
@@ -1211,14 +1212,8 @@ where
12111212#[ inline]
12121213#[ must_use]
12131214#[ 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) ) )
12221217}
12231218
12241219/// 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 {
12591254#[ inline]
12601255#[ must_use]
12611256#[ 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 {
12681258 match compare ( & v1, & v2) {
12691259 Ordering :: Less | Ordering :: Equal => v2,
12701260 Ordering :: Greater => v1,
@@ -1286,14 +1276,8 @@ where
12861276#[ inline]
12871277#[ must_use]
12881278#[ 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) ) )
12971281}
12981282
12991283// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
0 commit comments