Skip to content

Commit 3c267f8

Browse files
committed
constify the min() and max() functions
1 parent 34e5239 commit 3c267f8

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
@@ -1548,7 +1548,8 @@ pub macro PartialOrd($item:item) {
15481548
#[must_use]
15491549
#[stable(feature = "rust1", since = "1.0.0")]
15501550
#[rustc_diagnostic_item = "cmp_min"]
1551-
pub fn min<T: Ord>(v1: T, v2: T) -> T {
1551+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1552+
pub const fn min<T: [const] Ord + [const] Destruct>(v1: T, v2: T) -> T {
15521553
v1.min(v2)
15531554
}
15541555

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

0 commit comments

Comments
 (0)