about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-03-31 14:15:35 +0000
committerbors <bors@rust-lang.org>2023-03-31 14:15:35 +0000
commit734f69d95faf740cead75442b2b1f6fbb66597ef (patch)
treeeb5352704ad6b1f000ef074a994247ff0553c396
parent6664087f2d11a7bcb44fcb4dba552bf42d0df3f1 (diff)
parent7d891166f9f3f3bf084209b4e8fd5caedd2c33a3 (diff)
Auto merge of #109817 - oli-obk:revert_102245, r=pnkfelix
Revert 102245

reverts #102245, but only on beta, as that caused #109543 which has since been fixed on nightly.

This needed an additional partial revert of https://github.com/rust-lang/rust/commit/5b08c9f39754039ef9c6cbde157ac9eb8c252a58 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`
-rw-r--r--library/core/src/cmp.rs44
-rw-r--r--tests/ui/rfc-2632-const-trait-impl/function-pointer-does-not-require-const.rs8
2 files changed, 22 insertions, 30 deletions
diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs
index 5b5f55d0e65..068637d1a03 100644
--- a/library/core/src/cmp.rs
+++ b/library/core/src/cmp.rs
@@ -800,7 +800,10 @@ pub trait Ord: Eq + PartialOrd<Self> {
         Self: Sized,
         Self: ~const Destruct,
     {
-        max_by(self, other, Ord::cmp)
+        match self.cmp(&other) {
+            Ordering::Less | Ordering::Equal => other,
+            Ordering::Greater => self,
+        }
     }
 
     /// Compares and returns the minimum of two values.
@@ -821,7 +824,10 @@ pub trait Ord: Eq + PartialOrd<Self> {
         Self: Sized,
         Self: ~const Destruct,
     {
-        min_by(self, other, Ord::cmp)
+        match self.cmp(&other) {
+            Ordering::Less | Ordering::Equal => self,
+            Ordering::Greater => other,
+        }
     }
 
     /// 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 {
 #[inline]
 #[must_use]
 #[stable(feature = "cmp_min_max_by", since = "1.53.0")]
-#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
-pub const fn min_by<T, F: ~const FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T
-where
-    T: ~const Destruct,
-    F: ~const Destruct,
-{
+pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
     match compare(&v1, &v2) {
         Ordering::Less | Ordering::Equal => v1,
         Ordering::Greater => v2,
@@ -1211,14 +1212,8 @@ where
 #[inline]
 #[must_use]
 #[stable(feature = "cmp_min_max_by", since = "1.53.0")]
-#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
-pub const fn min_by_key<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(v1: T, v2: T, mut f: F) -> T
-where
-    T: ~const Destruct,
-    F: ~const Destruct,
-    K: ~const Destruct,
-{
-    min_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
+pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
+    min_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2)))
 }
 
 /// 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 {
 #[inline]
 #[must_use]
 #[stable(feature = "cmp_min_max_by", since = "1.53.0")]
-#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
-pub const fn max_by<T, F: ~const FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T
-where
-    T: ~const Destruct,
-    F: ~const Destruct,
-{
+pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
     match compare(&v1, &v2) {
         Ordering::Less | Ordering::Equal => v2,
         Ordering::Greater => v1,
@@ -1286,14 +1276,8 @@ where
 #[inline]
 #[must_use]
 #[stable(feature = "cmp_min_max_by", since = "1.53.0")]
-#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
-pub const fn max_by_key<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(v1: T, v2: T, mut f: F) -> T
-where
-    T: ~const Destruct,
-    F: ~const Destruct,
-    K: ~const Destruct,
-{
-    max_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
+pub fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
+    max_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2)))
 }
 
 // Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
diff --git a/tests/ui/rfc-2632-const-trait-impl/function-pointer-does-not-require-const.rs b/tests/ui/rfc-2632-const-trait-impl/function-pointer-does-not-require-const.rs
new file mode 100644
index 00000000000..1726cf82e2b
--- /dev/null
+++ b/tests/ui/rfc-2632-const-trait-impl/function-pointer-does-not-require-const.rs
@@ -0,0 +1,8 @@
+// check-pass
+
+type I32Cmp = fn(&i32, &i32) -> core::cmp::Ordering;
+pub const fn min_by_i32() -> fn(i32, i32, I32Cmp) -> i32 {
+    core::cmp::min_by
+}
+
+fn main() {}