Skip to content

Commit 2a1939b

Browse files
committed
constify the min() and max() functions
1 parent 1308d51 commit 2a1939b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

library/core/src/cmp.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,8 @@ pub macro PartialOrd($item:item) {
15491549
#[must_use]
15501550
#[stable(feature = "rust1", since = "1.0.0")]
15511551
#[rustc_diagnostic_item = "cmp_min"]
1552-
pub fn min<T: Ord>(v1: T, v2: T) -> T {
1552+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1553+
pub const fn min<T: [const] Ord + [const] Destruct>(v1: T, v2: T) -> T {
15531554
v1.min(v2)
15541555
}
15551556

@@ -1644,7 +1645,8 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
16441645
#[must_use]
16451646
#[stable(feature = "rust1", since = "1.0.0")]
16461647
#[rustc_diagnostic_item = "cmp_max"]
1647-
pub fn max<T: Ord>(v1: T, v2: T) -> T {
1648+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1649+
pub const fn max<T: [const] Ord + [const] Destruct>(v1: T, v2: T) -> T {
16481650
v1.max(v2)
16491651
}
16501652

0 commit comments

Comments
 (0)