diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-02-03 12:53:34 -0800 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-02-04 11:04:04 -0800 |
| commit | b46d1d27184bf78cc9181feadd192e887fe7d589 (patch) | |
| tree | 6d6100b6b607343367b8723c7f8cb10171f76979 /src/libcore | |
| parent | b422a19c4323e54f635e6d6aa7fc9900ce9f25a6 (diff) | |
Make wrapping arithmetic `const`
Co-Authored-By: 9999years <rbt@sent.as>
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/num/mod.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 1dccc87dd18..004e91c0eb3 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1280,10 +1280,11 @@ assert_eq!((-128i8).wrapping_div(-1), -128);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_unstable(feature = "const_int_wrapping", issue = "53718")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub fn wrapping_div(self, rhs: Self) -> Self { + pub const fn wrapping_div(self, rhs: Self) -> Self { self.overflowing_div(rhs).0 } } @@ -1340,10 +1341,11 @@ assert_eq!((-128i8).wrapping_rem(-1), 0);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_unstable(feature = "const_int_wrapping", issue = "53718")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub fn wrapping_rem(self, rhs: Self) -> Self { + pub const fn wrapping_rem(self, rhs: Self) -> Self { self.overflowing_rem(rhs).0 } } @@ -3320,10 +3322,11 @@ Basic usage: ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_div(10), 10);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_unstable(feature = "const_int_wrapping", issue = "53718")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub fn wrapping_div(self, rhs: Self) -> Self { + pub const fn wrapping_div(self, rhs: Self) -> Self { self / rhs } } @@ -3371,10 +3374,11 @@ Basic usage: ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_rem(10), 0);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_unstable(feature = "const_int_wrapping", issue = "53718")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub fn wrapping_rem(self, rhs: Self) -> Self { + pub const fn wrapping_rem(self, rhs: Self) -> Self { self % rhs } } |
