Skip to content

Commit 734f69d

Browse files
committed
Auto merge of rust-lang#109817 - oli-obk:revert_102245, r=pnkfelix
Revert 102245 reverts rust-lang#102245, but only on beta, as that caused rust-lang#109543 which has since been fixed on nightly. This needed an additional partial revert of rust-lang@5b08c9f for changes that happened due to later cleanups. I also added a test from the issue to make sure this actually fixes it 😆 r? `@wesleywiser` `@pnkfelix`
2 parents 6664087 + 7d89116 commit 734f69d

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

library/core/src/cmp.rs

+14-30
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
3+
type I32Cmp = fn(&i32, &i32) -> core::cmp::Ordering;
4+
pub const fn min_by_i32() -> fn(i32, i32, I32Cmp) -> i32 {
5+
core::cmp::min_by
6+
}
7+
8+
fn main() {}

0 commit comments

Comments
 (0)