Skip to content

Commit 526304d

Browse files
Make checked division const
1 parent d4529be commit 526304d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/libcore/num/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,11 @@ assert_eq!((1", stringify!($SelfT), ").checked_div(0), None);",
777777
$EndFeature, "
778778
```"),
779779
#[stable(feature = "rust1", since = "1.0.0")]
780+
#[rustc_const_unstable(feature = "const_int_checked", issue = "53718")]
780781
#[must_use = "this returns the result of the operation, \
781782
without modifying the original"]
782783
#[inline]
783-
pub fn checked_div(self, rhs: Self) -> Option<Self> {
784+
pub const fn checked_div(self, rhs: Self) -> Option<Self> {
784785
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
785786
None
786787
} else {
@@ -835,10 +836,11 @@ assert_eq!(", stringify!($SelfT), "::MIN.checked_rem(-1), None);",
835836
$EndFeature, "
836837
```"),
837838
#[stable(feature = "wrapping", since = "1.7.0")]
839+
#[rustc_const_unstable(feature = "const_int_checked", issue = "53718")]
838840
#[must_use = "this returns the result of the operation, \
839841
without modifying the original"]
840842
#[inline]
841-
pub fn checked_rem(self, rhs: Self) -> Option<Self> {
843+
pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
842844
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
843845
None
844846
} else {
@@ -2937,10 +2939,11 @@ Basic usage:
29372939
assert_eq!(1", stringify!($SelfT), ".checked_div(0), None);", $EndFeature, "
29382940
```"),
29392941
#[stable(feature = "rust1", since = "1.0.0")]
2942+
#[rustc_const_unstable(feature = "const_int_checked", issue = "53718")]
29402943
#[must_use = "this returns the result of the operation, \
29412944
without modifying the original"]
29422945
#[inline]
2943-
pub fn checked_div(self, rhs: Self) -> Option<Self> {
2946+
pub const fn checked_div(self, rhs: Self) -> Option<Self> {
29442947
match rhs {
29452948
0 => None,
29462949
// SAFETY: div by zero has been checked above and unsigned types have no other
@@ -2990,10 +2993,11 @@ Basic usage:
29902993
assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None);", $EndFeature, "
29912994
```"),
29922995
#[stable(feature = "wrapping", since = "1.7.0")]
2996+
#[rustc_const_unstable(feature = "const_int_checked", issue = "53718")]
29932997
#[must_use = "this returns the result of the operation, \
29942998
without modifying the original"]
29952999
#[inline]
2996-
pub fn checked_rem(self, rhs: Self) -> Option<Self> {
3000+
pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
29973001
if rhs == 0 {
29983002
None
29993003
} else {

0 commit comments

Comments
 (0)