Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make unchecked_{add,sub,mul} inherent methods unstably const #85096

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/core/src/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub unsafe trait Step: Clone + PartialOrd + Sized {
/// For any `a` and `n`, where no overflow occurs:
///
/// * `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 {
Step::forward(start, count)
}
Expand Down Expand Up @@ -178,7 +178,7 @@ pub unsafe trait Step: Clone + PartialOrd + Sized {
/// For any `a` and `n`, where no overflow occurs:
///
/// * `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 {
Step::backward(start, count)
}
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#![feature(const_float_classify)]
#![feature(const_float_bits_conv)]
#![feature(const_int_unchecked_arith)]
#![feature(const_inherent_unchecked_arith)]
#![feature(const_mut_refs)]
#![feature(const_refs_to_cell)]
#![feature(const_panic)]
Expand Down
15 changes: 9 additions & 6 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,13 @@ macro_rules! int_impl {
#[unstable(
feature = "unchecked_math",
reason = "niche optimization path",
issue = "none",
issue = "85122",
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[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
// `unchecked_add`.
unsafe { intrinsics::unchecked_add(self, rhs) }
Expand Down Expand Up @@ -450,12 +451,13 @@ macro_rules! int_impl {
#[unstable(
feature = "unchecked_math",
reason = "niche optimization path",
issue = "none",
issue = "85122",
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[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
// `unchecked_sub`.
unsafe { intrinsics::unchecked_sub(self, rhs) }
Expand Down Expand Up @@ -488,12 +490,13 @@ macro_rules! int_impl {
#[unstable(
feature = "unchecked_math",
reason = "niche optimization path",
issue = "none",
issue = "85122",
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[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
// `unchecked_mul`.
unsafe { intrinsics::unchecked_mul(self, rhs) }
Expand Down
15 changes: 9 additions & 6 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,13 @@ macro_rules! uint_impl {
#[unstable(
feature = "unchecked_math",
reason = "niche optimization path",
issue = "none",
issue = "85122",
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[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
// `unchecked_add`.
unsafe { intrinsics::unchecked_add(self, rhs) }
Expand Down Expand Up @@ -460,12 +461,13 @@ macro_rules! uint_impl {
#[unstable(
feature = "unchecked_math",
reason = "niche optimization path",
issue = "none",
issue = "85122",
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[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
// `unchecked_sub`.
unsafe { intrinsics::unchecked_sub(self, rhs) }
Expand Down Expand Up @@ -498,12 +500,13 @@ macro_rules! uint_impl {
#[unstable(
feature = "unchecked_math",
reason = "niche optimization path",
issue = "none",
issue = "85122",
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[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
// `unchecked_mul`.
unsafe { intrinsics::unchecked_mul(self, rhs) }
Expand Down
14 changes: 12 additions & 2 deletions src/tools/tidy/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ pub struct Feature {
pub has_gate_test: bool,
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>;

Expand Down Expand Up @@ -361,10 +369,12 @@ fn get_and_check_lib_features(
if f.tracking_issue != s.tracking_issue && f.level != Status::Stable {
tidy_error!(
bad,
"{}:{}: mismatches the `issue` in {}",
"{}:{}: `issue` \"{}\" mismatches the {} `issue` of \"{}\"",
file.display(),
line,
display
f.tracking_issue_display(),
display,
s.tracking_issue_display(),
);
}
}
Expand Down