Skip to content

Commit 2d2486d

Browse files
committed
Fix parameter order for _by() variants of min / max/ minmax in std::cmp
1 parent 9e14530 commit 2d2486d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/core/src/cmp.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
15721572
#[must_use]
15731573
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
15741574
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
1575-
if compare(&v2, &v1).is_lt() { v2 } else { v1 }
1575+
if compare(&v1, &v2).is_le() { v1 } else { v2 }
15761576
}
15771577

15781578
/// Returns the element that gives the minimum value from the specified function.
@@ -1664,7 +1664,7 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
16641664
#[must_use]
16651665
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
16661666
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
1667-
if compare(&v2, &v1).is_lt() { v1 } else { v2 }
1667+
if compare(&v1, &v2).is_gt() { v1 } else { v2 }
16681668
}
16691669

16701670
/// Returns the element that gives the maximum value from the specified function.
@@ -1767,7 +1767,7 @@ pub fn minmax_by<T, F>(v1: T, v2: T, compare: F) -> [T; 2]
17671767
where
17681768
F: FnOnce(&T, &T) -> Ordering,
17691769
{
1770-
if compare(&v2, &v1).is_lt() { [v2, v1] } else { [v1, v2] }
1770+
if compare(&v1, &v2).is_le() { [v1, v2] } else { [v2, v1] }
17711771
}
17721772

17731773
/// Returns minimum and maximum values with respect to the specified key function.

0 commit comments

Comments
 (0)