Skip to content

Commit 73cfcc6

Browse files
committed
Auto merge of #29862 - ranma42:const_min_max, r=alexcrichton
They can be useful for constructing constant items.
2 parents 99093b7 + c545b33 commit 73cfcc6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/libcore/num/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ macro_rules! int_impl {
124124
/// Returns the smallest value that can be represented by this integer type.
125125
#[stable(feature = "rust1", since = "1.0.0")]
126126
#[inline]
127-
pub fn min_value() -> Self {
127+
pub const fn min_value() -> Self {
128128
(-1 as Self) << ($BITS - 1)
129129
}
130130

131131
/// Returns the largest value that can be represented by this integer type.
132132
#[stable(feature = "rust1", since = "1.0.0")]
133133
#[inline]
134-
pub fn max_value() -> Self {
135-
let min = Self::min_value(); !min
134+
pub const fn max_value() -> Self {
135+
!Self::min_value()
136136
}
137137

138138
/// Converts a string slice in a given base to an integer.
@@ -891,12 +891,12 @@ macro_rules! uint_impl {
891891
/// Returns the smallest value that can be represented by this integer type.
892892
#[stable(feature = "rust1", since = "1.0.0")]
893893
#[inline]
894-
pub fn min_value() -> Self { 0 }
894+
pub const fn min_value() -> Self { 0 }
895895

896896
/// Returns the largest value that can be represented by this integer type.
897897
#[stable(feature = "rust1", since = "1.0.0")]
898898
#[inline]
899-
pub fn max_value() -> Self { !0 }
899+
pub const fn max_value() -> Self { !0 }
900900

901901
/// Converts a string slice in a given base to an integer.
902902
///

0 commit comments

Comments
 (0)