Skip to content

Commit 380bbe8

Browse files
committed
Make unchecked_{add,sub,mul} inherent methods unstably const
1 parent 777bb2f commit 380bbe8

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#![feature(const_float_classify)]
7878
#![feature(const_float_bits_conv)]
7979
#![feature(const_int_unchecked_arith)]
80+
#![feature(const_inherent_unchecked_arith)]
8081
#![feature(const_mut_refs)]
8182
#![feature(const_refs_to_cell)]
8283
#![feature(const_panic)]

library/core/src/num/int_macros.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,13 @@ macro_rules! int_impl {
412412
#[unstable(
413413
feature = "unchecked_math",
414414
reason = "niche optimization path",
415-
issue = "none",
415+
issue = "85122",
416416
)]
417417
#[must_use = "this returns the result of the operation, \
418418
without modifying the original"]
419+
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
419420
#[inline(always)]
420-
pub unsafe fn unchecked_add(self, rhs: Self) -> Self {
421+
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
421422
// SAFETY: the caller must uphold the safety contract for
422423
// `unchecked_add`.
423424
unsafe { intrinsics::unchecked_add(self, rhs) }
@@ -450,12 +451,13 @@ macro_rules! int_impl {
450451
#[unstable(
451452
feature = "unchecked_math",
452453
reason = "niche optimization path",
453-
issue = "none",
454+
issue = "85122",
454455
)]
455456
#[must_use = "this returns the result of the operation, \
456457
without modifying the original"]
458+
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
457459
#[inline(always)]
458-
pub unsafe fn unchecked_sub(self, rhs: Self) -> Self {
460+
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
459461
// SAFETY: the caller must uphold the safety contract for
460462
// `unchecked_sub`.
461463
unsafe { intrinsics::unchecked_sub(self, rhs) }
@@ -488,12 +490,13 @@ macro_rules! int_impl {
488490
#[unstable(
489491
feature = "unchecked_math",
490492
reason = "niche optimization path",
491-
issue = "none",
493+
issue = "85122",
492494
)]
493495
#[must_use = "this returns the result of the operation, \
494496
without modifying the original"]
497+
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
495498
#[inline(always)]
496-
pub unsafe fn unchecked_mul(self, rhs: Self) -> Self {
499+
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
497500
// SAFETY: the caller must uphold the safety contract for
498501
// `unchecked_mul`.
499502
unsafe { intrinsics::unchecked_mul(self, rhs) }

library/core/src/num/uint_macros.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,13 @@ macro_rules! uint_impl {
422422
#[unstable(
423423
feature = "unchecked_math",
424424
reason = "niche optimization path",
425-
issue = "none",
425+
issue = "85122",
426426
)]
427427
#[must_use = "this returns the result of the operation, \
428428
without modifying the original"]
429+
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
429430
#[inline(always)]
430-
pub unsafe fn unchecked_add(self, rhs: Self) -> Self {
431+
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
431432
// SAFETY: the caller must uphold the safety contract for
432433
// `unchecked_add`.
433434
unsafe { intrinsics::unchecked_add(self, rhs) }
@@ -460,12 +461,13 @@ macro_rules! uint_impl {
460461
#[unstable(
461462
feature = "unchecked_math",
462463
reason = "niche optimization path",
463-
issue = "none",
464+
issue = "85122",
464465
)]
465466
#[must_use = "this returns the result of the operation, \
466467
without modifying the original"]
468+
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
467469
#[inline(always)]
468-
pub unsafe fn unchecked_sub(self, rhs: Self) -> Self {
470+
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
469471
// SAFETY: the caller must uphold the safety contract for
470472
// `unchecked_sub`.
471473
unsafe { intrinsics::unchecked_sub(self, rhs) }
@@ -498,12 +500,13 @@ macro_rules! uint_impl {
498500
#[unstable(
499501
feature = "unchecked_math",
500502
reason = "niche optimization path",
501-
issue = "none",
503+
issue = "85122",
502504
)]
503505
#[must_use = "this returns the result of the operation, \
504506
without modifying the original"]
507+
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
505508
#[inline(always)]
506-
pub unsafe fn unchecked_mul(self, rhs: Self) -> Self {
509+
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
507510
// SAFETY: the caller must uphold the safety contract for
508511
// `unchecked_mul`.
509512
unsafe { intrinsics::unchecked_mul(self, rhs) }

0 commit comments

Comments
 (0)