Auto merge of #29862 - ranma42:const_min_max, r=alexcrichton
They can be useful for constructing constant items.
This commit is contained in:
commit
73cfcc60e1
1 changed files with 5 additions and 5 deletions
|
|
@ -124,15 +124,15 @@ macro_rules! int_impl {
|
|||
/// Returns the smallest value that can be represented by this integer type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn min_value() -> Self {
|
||||
pub const fn min_value() -> Self {
|
||||
(-1 as Self) << ($BITS - 1)
|
||||
}
|
||||
|
||||
/// Returns the largest value that can be represented by this integer type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn max_value() -> Self {
|
||||
let min = Self::min_value(); !min
|
||||
pub const fn max_value() -> Self {
|
||||
!Self::min_value()
|
||||
}
|
||||
|
||||
/// Converts a string slice in a given base to an integer.
|
||||
|
|
@ -891,12 +891,12 @@ macro_rules! uint_impl {
|
|||
/// Returns the smallest value that can be represented by this integer type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn min_value() -> Self { 0 }
|
||||
pub const fn min_value() -> Self { 0 }
|
||||
|
||||
/// Returns the largest value that can be represented by this integer type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn max_value() -> Self { !0 }
|
||||
pub const fn max_value() -> Self { !0 }
|
||||
|
||||
/// Converts a string slice in a given base to an integer.
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue