about summary refs log tree commit diff
path: root/src/libcore/num
diff options
context:
space:
mode:
authorLinus Färnstrand <faern@faern.net>2020-01-17 22:16:52 +0100
committerLinus Färnstrand <faern@faern.net>2020-01-23 20:55:06 +0100
commitb5ff8064a4fe5b2bc70ee209b19d129b8ffc3ebc (patch)
tree9b96e3635c88151e99bb373a760ad8e1aa7ff965 /src/libcore/num
parente0bbe7915e2b663ac84244918d6d06e0747ed33e (diff)
downloadrust-b5ff8064a4fe5b2bc70ee209b19d129b8ffc3ebc.tar.gz
rust-b5ff8064a4fe5b2bc70ee209b19d129b8ffc3ebc.zip
Add MIN/MAX associated constants to the integer types
Diffstat (limited to 'src/libcore/num')
-rw-r--r--src/libcore/num/mod.rs70
1 files changed, 47 insertions, 23 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index 072966abf2c..e717d0e42bb 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -245,42 +245,54 @@ macro_rules! int_impl {
      $reversed:expr, $le_bytes:expr, $be_bytes:expr,
      $to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr) => {
         doc_comment! {
-            concat!("Returns the smallest value that can be represented by this integer type.
+            concat!("The smallest value that can be represented by this integer type.
 
 # Examples
 
 Basic usage:
 
 ```
-", $Feature, "assert_eq!(", stringify!($SelfT), "::min_value(), ", stringify!($Min), ");",
+", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, ", stringify!($Min), ");",
 $EndFeature, "
 ```"),
-            #[stable(feature = "rust1", since = "1.0.0")]
-            #[inline(always)]
-            #[rustc_promotable]
-            #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")]
-            pub const fn min_value() -> Self {
-                !0 ^ ((!0 as $UnsignedT) >> 1) as Self
-            }
+            #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
+            pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self;
         }
 
         doc_comment! {
-            concat!("Returns the largest value that can be represented by this integer type.
+            concat!("The largest value that can be represented by this integer type.
 
 # Examples
 
 Basic usage:
 
 ```
-", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value(), ", stringify!($Max), ");",
+", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($Max), ");",
 $EndFeature, "
 ```"),
+            #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
+            pub const MAX: Self = !Self::MIN;
+        }
+
+        doc_comment! {
+            "Returns the smallest value that can be represented by this integer type.",
+            #[stable(feature = "rust1", since = "1.0.0")]
+            #[inline(always)]
+            #[rustc_promotable]
+            #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")]
+            pub const fn min_value() -> Self {
+                Self::MIN
+            }
+        }
+
+        doc_comment! {
+            "Returns the largest value that can be represented by this integer type.",
             #[stable(feature = "rust1", since = "1.0.0")]
             #[inline(always)]
             #[rustc_promotable]
             #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
             pub const fn max_value() -> Self {
-                !Self::min_value()
+                Self::MAX
             }
         }
 
@@ -2342,38 +2354,50 @@ macro_rules! uint_impl {
         $reversed:expr, $le_bytes:expr, $be_bytes:expr,
         $to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr) => {
         doc_comment! {
-            concat!("Returns the smallest value that can be represented by this integer type.
+            concat!("The smallest value that can be represented by this integer type.
 
 # Examples
 
 Basic usage:
 
 ```
-", $Feature, "assert_eq!(", stringify!($SelfT), "::min_value(), 0);", $EndFeature, "
+", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, 0);", $EndFeature, "
 ```"),
-            #[stable(feature = "rust1", since = "1.0.0")]
-            #[rustc_promotable]
-            #[inline(always)]
-            #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")]
-            pub const fn min_value() -> Self { 0 }
+            #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
+            pub const MIN: Self = 0;
         }
 
         doc_comment! {
-            concat!("Returns the largest value that can be represented by this integer type.
+            concat!("The largest value that can be represented by this integer type.
 
 # Examples
 
 Basic usage:
 
 ```
-", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value(), ",
-stringify!($MaxV), ");", $EndFeature, "
+", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($MaxV), ");",
+$EndFeature, "
 ```"),
+            #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
+            pub const MAX: Self = !0;
+        }
+
+        doc_comment! {
+            "Returns the smallest value that can be represented by this integer type.",
+            #[stable(feature = "rust1", since = "1.0.0")]
+            #[rustc_promotable]
+            #[inline(always)]
+            #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
+            pub const fn min_value() -> Self { Self::MIN }
+        }
+
+        doc_comment! {
+            "Returns the largest value that can be represented by this integer type.",
             #[stable(feature = "rust1", since = "1.0.0")]
             #[rustc_promotable]
             #[inline(always)]
             #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
-            pub const fn max_value() -> Self { !0 }
+            pub const fn max_value() -> Self { Self::MAX }
         }
 
         doc_comment! {