Skip to content

Commit 7107c89

Browse files
authored
Rollup merge of #85096 - clarfonthey:const_unchecked, r=oli-obk
Make unchecked_{add,sub,mul} inherent methods unstably const The intrinsics are marked as being stably const (even though they're not stable by nature of being intrinsics), but the currently-unstable inherent versions are not marked as const. This fixes this inconsistency. Split out of #85017, r? `@oli-obk`
2 parents 37c6038 + e6b12c8 commit 7107c89

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

library/core/src/iter/range.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub unsafe trait Step: Clone + PartialOrd + Sized {
106106
/// For any `a` and `n`, where no overflow occurs:
107107
///
108108
/// * `Step::forward_unchecked(a, n)` is equivalent to `Step::forward(a, n)`
109-
#[unstable(feature = "unchecked_math", reason = "niche optimization path", issue = "none")]
109+
#[unstable(feature = "step_trait_ext", reason = "recently added", issue = "42168")]
110110
unsafe fn forward_unchecked(start: Self, count: usize) -> Self {
111111
Step::forward(start, count)
112112
}
@@ -178,7 +178,7 @@ pub unsafe trait Step: Clone + PartialOrd + Sized {
178178
/// For any `a` and `n`, where no overflow occurs:
179179
///
180180
/// * `Step::backward_unchecked(a, n)` is equivalent to `Step::backward(a, n)`
181-
#[unstable(feature = "unchecked_math", reason = "niche optimization path", issue = "none")]
181+
#[unstable(feature = "step_trait_ext", reason = "recently added", issue = "42168")]
182182
unsafe fn backward_unchecked(start: Self, count: usize) -> Self {
183183
Step::backward(start, count)
184184
}

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) }

src/tools/tidy/src/features.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ pub struct Feature {
5151
pub has_gate_test: bool,
5252
pub tracking_issue: Option<NonZeroU32>,
5353
}
54+
impl Feature {
55+
fn tracking_issue_display(&self) -> impl fmt::Display {
56+
match self.tracking_issue {
57+
None => "none".to_string(),
58+
Some(x) => x.to_string(),
59+
}
60+
}
61+
}
5462

5563
pub type Features = HashMap<String, Feature>;
5664

@@ -361,10 +369,12 @@ fn get_and_check_lib_features(
361369
if f.tracking_issue != s.tracking_issue && f.level != Status::Stable {
362370
tidy_error!(
363371
bad,
364-
"{}:{}: mismatches the `issue` in {}",
372+
"{}:{}: `issue` \"{}\" mismatches the {} `issue` of \"{}\"",
365373
file.display(),
366374
line,
367-
display
375+
f.tracking_issue_display(),
376+
display,
377+
s.tracking_issue_display(),
368378
);
369379
}
370380
}

0 commit comments

Comments
 (0)