From de52a541d5daab8393d4da8a9508fb7b5c1448e0 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 3 Feb 2020 12:45:51 -0800 Subject: [PATCH] Make overflowing arithmetic `const` Co-Authored-By: 9999years --- src/libcore/lib.rs | 1 + src/libcore/num/mod.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 78b1524f04f8..f8857b9d7337 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -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)] diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 91df649f121e..690a07ce6809 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -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 { @@ -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 { @@ -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) } } @@ -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) } }