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`
This commit is contained in:
commit
7107c89970
5 changed files with 33 additions and 16 deletions
|
@ -106,7 +106,7 @@ pub unsafe trait Step: Clone + PartialOrd + Sized {
|
||||||
/// For any `a` and `n`, where no overflow occurs:
|
/// For any `a` and `n`, where no overflow occurs:
|
||||||
///
|
///
|
||||||
/// * `Step::forward_unchecked(a, n)` is equivalent to `Step::forward(a, n)`
|
/// * `Step::forward_unchecked(a, n)` is equivalent to `Step::forward(a, n)`
|
||||||
#[unstable(feature = "unchecked_math", reason = "niche optimization path", issue = "none")]
|
#[unstable(feature = "step_trait_ext", reason = "recently added", issue = "42168")]
|
||||||
unsafe fn forward_unchecked(start: Self, count: usize) -> Self {
|
unsafe fn forward_unchecked(start: Self, count: usize) -> Self {
|
||||||
Step::forward(start, count)
|
Step::forward(start, count)
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ pub unsafe trait Step: Clone + PartialOrd + Sized {
|
||||||
/// For any `a` and `n`, where no overflow occurs:
|
/// For any `a` and `n`, where no overflow occurs:
|
||||||
///
|
///
|
||||||
/// * `Step::backward_unchecked(a, n)` is equivalent to `Step::backward(a, n)`
|
/// * `Step::backward_unchecked(a, n)` is equivalent to `Step::backward(a, n)`
|
||||||
#[unstable(feature = "unchecked_math", reason = "niche optimization path", issue = "none")]
|
#[unstable(feature = "step_trait_ext", reason = "recently added", issue = "42168")]
|
||||||
unsafe fn backward_unchecked(start: Self, count: usize) -> Self {
|
unsafe fn backward_unchecked(start: Self, count: usize) -> Self {
|
||||||
Step::backward(start, count)
|
Step::backward(start, count)
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@
|
||||||
#![feature(const_float_classify)]
|
#![feature(const_float_classify)]
|
||||||
#![feature(const_float_bits_conv)]
|
#![feature(const_float_bits_conv)]
|
||||||
#![feature(const_int_unchecked_arith)]
|
#![feature(const_int_unchecked_arith)]
|
||||||
|
#![feature(const_inherent_unchecked_arith)]
|
||||||
#![feature(const_mut_refs)]
|
#![feature(const_mut_refs)]
|
||||||
#![feature(const_refs_to_cell)]
|
#![feature(const_refs_to_cell)]
|
||||||
#![feature(const_panic)]
|
#![feature(const_panic)]
|
||||||
|
|
|
@ -412,12 +412,13 @@ macro_rules! int_impl {
|
||||||
#[unstable(
|
#[unstable(
|
||||||
feature = "unchecked_math",
|
feature = "unchecked_math",
|
||||||
reason = "niche optimization path",
|
reason = "niche optimization path",
|
||||||
issue = "none",
|
issue = "85122",
|
||||||
)]
|
)]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
|
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn unchecked_add(self, rhs: Self) -> Self {
|
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for
|
// SAFETY: the caller must uphold the safety contract for
|
||||||
// `unchecked_add`.
|
// `unchecked_add`.
|
||||||
unsafe { intrinsics::unchecked_add(self, rhs) }
|
unsafe { intrinsics::unchecked_add(self, rhs) }
|
||||||
|
@ -450,12 +451,13 @@ macro_rules! int_impl {
|
||||||
#[unstable(
|
#[unstable(
|
||||||
feature = "unchecked_math",
|
feature = "unchecked_math",
|
||||||
reason = "niche optimization path",
|
reason = "niche optimization path",
|
||||||
issue = "none",
|
issue = "85122",
|
||||||
)]
|
)]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
|
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn unchecked_sub(self, rhs: Self) -> Self {
|
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for
|
// SAFETY: the caller must uphold the safety contract for
|
||||||
// `unchecked_sub`.
|
// `unchecked_sub`.
|
||||||
unsafe { intrinsics::unchecked_sub(self, rhs) }
|
unsafe { intrinsics::unchecked_sub(self, rhs) }
|
||||||
|
@ -488,12 +490,13 @@ macro_rules! int_impl {
|
||||||
#[unstable(
|
#[unstable(
|
||||||
feature = "unchecked_math",
|
feature = "unchecked_math",
|
||||||
reason = "niche optimization path",
|
reason = "niche optimization path",
|
||||||
issue = "none",
|
issue = "85122",
|
||||||
)]
|
)]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
|
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn unchecked_mul(self, rhs: Self) -> Self {
|
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for
|
// SAFETY: the caller must uphold the safety contract for
|
||||||
// `unchecked_mul`.
|
// `unchecked_mul`.
|
||||||
unsafe { intrinsics::unchecked_mul(self, rhs) }
|
unsafe { intrinsics::unchecked_mul(self, rhs) }
|
||||||
|
|
|
@ -422,12 +422,13 @@ macro_rules! uint_impl {
|
||||||
#[unstable(
|
#[unstable(
|
||||||
feature = "unchecked_math",
|
feature = "unchecked_math",
|
||||||
reason = "niche optimization path",
|
reason = "niche optimization path",
|
||||||
issue = "none",
|
issue = "85122",
|
||||||
)]
|
)]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
|
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn unchecked_add(self, rhs: Self) -> Self {
|
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for
|
// SAFETY: the caller must uphold the safety contract for
|
||||||
// `unchecked_add`.
|
// `unchecked_add`.
|
||||||
unsafe { intrinsics::unchecked_add(self, rhs) }
|
unsafe { intrinsics::unchecked_add(self, rhs) }
|
||||||
|
@ -460,12 +461,13 @@ macro_rules! uint_impl {
|
||||||
#[unstable(
|
#[unstable(
|
||||||
feature = "unchecked_math",
|
feature = "unchecked_math",
|
||||||
reason = "niche optimization path",
|
reason = "niche optimization path",
|
||||||
issue = "none",
|
issue = "85122",
|
||||||
)]
|
)]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
|
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn unchecked_sub(self, rhs: Self) -> Self {
|
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for
|
// SAFETY: the caller must uphold the safety contract for
|
||||||
// `unchecked_sub`.
|
// `unchecked_sub`.
|
||||||
unsafe { intrinsics::unchecked_sub(self, rhs) }
|
unsafe { intrinsics::unchecked_sub(self, rhs) }
|
||||||
|
@ -498,12 +500,13 @@ macro_rules! uint_impl {
|
||||||
#[unstable(
|
#[unstable(
|
||||||
feature = "unchecked_math",
|
feature = "unchecked_math",
|
||||||
reason = "niche optimization path",
|
reason = "niche optimization path",
|
||||||
issue = "none",
|
issue = "85122",
|
||||||
)]
|
)]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
|
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn unchecked_mul(self, rhs: Self) -> Self {
|
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for
|
// SAFETY: the caller must uphold the safety contract for
|
||||||
// `unchecked_mul`.
|
// `unchecked_mul`.
|
||||||
unsafe { intrinsics::unchecked_mul(self, rhs) }
|
unsafe { intrinsics::unchecked_mul(self, rhs) }
|
||||||
|
|
|
@ -51,6 +51,14 @@ pub struct Feature {
|
||||||
pub has_gate_test: bool,
|
pub has_gate_test: bool,
|
||||||
pub tracking_issue: Option<NonZeroU32>,
|
pub tracking_issue: Option<NonZeroU32>,
|
||||||
}
|
}
|
||||||
|
impl Feature {
|
||||||
|
fn tracking_issue_display(&self) -> impl fmt::Display {
|
||||||
|
match self.tracking_issue {
|
||||||
|
None => "none".to_string(),
|
||||||
|
Some(x) => x.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type Features = HashMap<String, Feature>;
|
pub type Features = HashMap<String, Feature>;
|
||||||
|
|
||||||
|
@ -361,10 +369,12 @@ fn get_and_check_lib_features(
|
||||||
if f.tracking_issue != s.tracking_issue && f.level != Status::Stable {
|
if f.tracking_issue != s.tracking_issue && f.level != Status::Stable {
|
||||||
tidy_error!(
|
tidy_error!(
|
||||||
bad,
|
bad,
|
||||||
"{}:{}: mismatches the `issue` in {}",
|
"{}:{}: `issue` \"{}\" mismatches the {} `issue` of \"{}\"",
|
||||||
file.display(),
|
file.display(),
|
||||||
line,
|
line,
|
||||||
display
|
f.tracking_issue_display(),
|
||||||
|
display,
|
||||||
|
s.tracking_issue_display(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue