Skip to content

Commit

Permalink
Make overflowing arithmetic const
Browse files Browse the repository at this point in the history
Co-Authored-By: 9999years <rbt@sent.as>
  • Loading branch information
ecstatic-morse and 9999years committed Feb 4, 2020
1 parent 37c1418 commit de52a54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Expand Up @@ -74,6 +74,7 @@
#![feature(const_if_match)]
#![feature(const_int_checked)]
#![feature(const_int_euclidean)]
#![feature(const_int_overflowing)]
#![feature(const_panic)]
#![feature(const_fn_union)]
#![feature(const_generics)]
Expand Down
12 changes: 8 additions & 4 deletions src/libcore/num/mod.rs
Expand Up @@ -1646,9 +1646,10 @@ $EndFeature, "
```"),
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing", issue = "53718")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub fn overflowing_div(self, rhs: Self) -> (Self, bool) {
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) {
if self == Self::min_value() && rhs == -1 {
(self, true)
} else {
Expand Down Expand Up @@ -1715,9 +1716,10 @@ $EndFeature, "
```"),
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing", issue = "53718")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
if self == Self::min_value() && rhs == -1 {
(0, true)
} else {
Expand Down Expand Up @@ -3639,9 +3641,10 @@ Basic usage
```"),
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing", issue = "53718")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub fn overflowing_div(self, rhs: Self) -> (Self, bool) {
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) {
(self / rhs, false)
}
}
Expand Down Expand Up @@ -3699,9 +3702,10 @@ Basic usage
```"),
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing", issue = "53718")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
(self % rhs, false)
}
}
Expand Down

0 comments on commit de52a54

Please sign in to comment.