Skip to content

Fix parameter order for _by() variants of min / max/ minmax in std::cmp #139357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
#[must_use]
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
if compare(&v2, &v1).is_lt() { v2 } else { v1 }
if compare(&v1, &v2).is_le() { v1 } else { v2 }
}

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

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

/// Returns minimum and maximum values with respect to the specified key function.
Expand Down
Loading