Skip to content

Commit 16555ac

Browse files
authored
Rollup merge of #68809 - ecstatic-morse:const-int-functions, r=oli-obk
Make more arithmetic functions unstably const This is a smaller version of #66884 (thanks @9999years) that constifies many of the arithmetic functions on integer primitives from #53718 that were blocked on #49146. This makes the following things unstably const. - `feature = const_int_unchecked_arith` - `intrinsics::unchecked_add` - `intrinsics::unchecked_sub` - `intrinsics::unchecked_mul` - `intrinsics::unchecked_div` - `intrinsics::unchecked_rem` - `feature = const_checked_int_methods` - `checked_add` - `checked_sub` - `checked_mul` - `checked_div` (Uses `intrinsics::unchecked_div` internally) - `checked_rem` (Uses `intrinsics::unchecked_rem` internally) - `checked_neg` - `checked_shl` - `checked_shr` - `checked_abs` - `feature = const_saturating_int_methods` - `saturating_mul` - `saturating_neg` (Uses `intrinsics::unchecked_sub` internally) - `saturating_abs` (Uses `intrinsics::unchecked_sub` internally) - `feature = const_wrapping_int_methods` - `wrapping_div` - `wrapping_rem` - `feature = const_overflowing_int_methods` - `overflowing_div` - `overflowing_rem` - `feature = const_euclidean_int_methods` - `checked_div_euclid` - `checked_rem_euclid` - `wrapping_div_euclid` - `wrapping_rem_euclid` - `overflowing_div_euclid` - `overflowing_rem_euclid` Exponentiation and operations on the `NonZero` types are left to a later PR. r? @oli-obk cc @rust-lang/wg-const-eval @rust-lang/libs
2 parents c177941 + 78f8ad3 commit 16555ac

File tree

6 files changed

+260
-51
lines changed

6 files changed

+260
-51
lines changed

src/libcore/intrinsics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,9 +1305,11 @@ extern "rust-intrinsic" {
13051305

13061306
/// Performs an unchecked division, resulting in undefined behavior
13071307
/// where y = 0 or x = `T::min_value()` and y = -1
1308+
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
13081309
pub fn unchecked_div<T>(x: T, y: T) -> T;
13091310
/// Returns the remainder of an unchecked division, resulting in
13101311
/// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
1312+
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
13111313
pub fn unchecked_rem<T>(x: T, y: T) -> T;
13121314

13131315
/// Performs an unchecked left shift, resulting in undefined behavior when
@@ -1321,14 +1323,17 @@ extern "rust-intrinsic" {
13211323

13221324
/// Returns the result of an unchecked addition, resulting in
13231325
/// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
1326+
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
13241327
pub fn unchecked_add<T>(x: T, y: T) -> T;
13251328

13261329
/// Returns the result of an unchecked subtraction, resulting in
13271330
/// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
1331+
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
13281332
pub fn unchecked_sub<T>(x: T, y: T) -> T;
13291333

13301334
/// Returns the result of an unchecked multiplication, resulting in
13311335
/// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
1336+
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
13321337
pub fn unchecked_mul<T>(x: T, y: T) -> T;
13331338

13341339
/// Performs rotate left.

src/libcore/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
#![feature(concat_idents)]
7373
#![feature(const_alloc_layout)]
7474
#![feature(const_if_match)]
75+
#![feature(const_checked_int_methods)]
76+
#![feature(const_euclidean_int_methods)]
77+
#![feature(const_overflowing_int_methods)]
78+
#![feature(const_saturating_int_methods)]
79+
#![feature(const_int_unchecked_arith)]
7580
#![feature(const_panic)]
7681
#![feature(const_fn_union)]
7782
#![feature(const_generics)]

0 commit comments

Comments
 (0)