]> git.lizzy.rs Git - rust.git/commitdiff
Make checked division `const`
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Mon, 3 Feb 2020 21:19:32 +0000 (13:19 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Tue, 4 Feb 2020 19:04:04 +0000 (11:04 -0800)
src/libcore/num/mod.rs

index 004e91c0eb3a6ab222626ed54fc51255a23aa27b..f590c6bc7c285099e3a202580eba45334e094ba6 100644 (file)
@@ -777,10 +777,11 @@ pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
 $EndFeature, "
 ```"),
             #[stable(feature = "rust1", since = "1.0.0")]
+            #[rustc_const_unstable(feature = "const_int_checked", issue = "53718")]
             #[must_use = "this returns the result of the operation, \
                           without modifying the original"]
             #[inline]
-            pub fn checked_div(self, rhs: Self) -> Option<Self> {
+            pub const fn checked_div(self, rhs: Self) -> Option<Self> {
                 if rhs == 0 || (self == Self::min_value() && rhs == -1) {
                     None
                 } else {
@@ -835,10 +836,11 @@ pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
 $EndFeature, "
 ```"),
             #[stable(feature = "wrapping", since = "1.7.0")]
+            #[rustc_const_unstable(feature = "const_int_checked", issue = "53718")]
             #[must_use = "this returns the result of the operation, \
                           without modifying the original"]
             #[inline]
-            pub fn checked_rem(self, rhs: Self) -> Option<Self> {
+            pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
                 if rhs == 0 || (self == Self::min_value() && rhs == -1) {
                     None
                 } else {
@@ -2937,10 +2939,11 @@ pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
 assert_eq!(1", stringify!($SelfT), ".checked_div(0), None);", $EndFeature, "
 ```"),
             #[stable(feature = "rust1", since = "1.0.0")]
+            #[rustc_const_unstable(feature = "const_int_checked", issue = "53718")]
             #[must_use = "this returns the result of the operation, \
                           without modifying the original"]
             #[inline]
-            pub fn checked_div(self, rhs: Self) -> Option<Self> {
+            pub const fn checked_div(self, rhs: Self) -> Option<Self> {
                 match rhs {
                     0 => None,
                     // SAFETY: div by zero has been checked above and unsigned types have no other
@@ -2990,10 +2993,11 @@ pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
 assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None);", $EndFeature, "
 ```"),
             #[stable(feature = "wrapping", since = "1.7.0")]
+            #[rustc_const_unstable(feature = "const_int_checked", issue = "53718")]
             #[must_use = "this returns the result of the operation, \
                           without modifying the original"]
             #[inline]
-            pub fn checked_rem(self, rhs: Self) -> Option<Self> {
+            pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
                 if rhs == 0 {
                     None
                 } else {