Skip to content

Commit aaa7631

Browse files
committed
constify the min() and max() functions
1 parent f4fd997 commit aaa7631

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
@@ -1559,7 +1559,8 @@ pub macro PartialOrd($item:item) {
15591559
#[must_use]
15601560
#[stable(feature = "rust1", since = "1.0.0")]
15611561
#[rustc_diagnostic_item = "cmp_min"]
1562-
pub fn min<T: Ord>(v1: T, v2: T) -> T {
1562+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1563+
pub const fn min<T: [const] Ord + [const] Destruct>(v1: T, v2: T) -> T {
15631564
v1.min(v2)
15641565
}
15651566

@@ -1654,7 +1655,8 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
16541655
#[must_use]
16551656
#[stable(feature = "rust1", since = "1.0.0")]
16561657
#[rustc_diagnostic_item = "cmp_max"]
1657-
pub fn max<T: Ord>(v1: T, v2: T) -> T {
1658+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1659+
pub const fn max<T: [const] Ord + [const] Destruct>(v1: T, v2: T) -> T {
16581660
v1.max(v2)
16591661
}
16601662

0 commit comments

Comments
 (0)