From 380bbe8d478e2252b60b79b82f285b9464227f5c Mon Sep 17 00:00:00 2001 From: ltdk Date: Sat, 8 May 2021 20:18:44 -0400 Subject: [PATCH 1/2] Make unchecked_{add,sub,mul} inherent methods unstably const --- library/core/src/lib.rs | 1 + library/core/src/num/int_macros.rs | 15 +++++++++------ library/core/src/num/uint_macros.rs | 15 +++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 0e2c140c367..71008381475 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -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)] diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 4b341132e31..47b2b30563c 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -412,12 +412,13 @@ pub const fn checked_add(self, rhs: Self) -> Option { #[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) } @@ -450,12 +451,13 @@ pub const fn checked_sub(self, rhs: Self) -> Option { #[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) } @@ -488,12 +490,13 @@ pub const fn checked_mul(self, rhs: Self) -> Option { #[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) } diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 08d9161eff1..f9fd28b6a8c 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -422,12 +422,13 @@ pub const fn checked_add(self, rhs: Self) -> Option { #[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) } @@ -460,12 +461,13 @@ pub const fn checked_sub(self, rhs: Self) -> Option { #[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) } @@ -498,12 +500,13 @@ pub const fn checked_mul(self, rhs: Self) -> Option { #[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) } From e6b12c8e4f7817d6317ab7b981e440f260a8137e Mon Sep 17 00:00:00 2001 From: ltdk Date: Sun, 9 May 2021 17:13:22 -0400 Subject: [PATCH 2/2] Fix `Step` feature flag, make tidy lint more useful to find things like this --- library/core/src/iter/range.rs | 4 ++-- src/tools/tidy/src/features.rs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/library/core/src/iter/range.rs b/library/core/src/iter/range.rs index 4b293c596e7..5e39e71252f 100644 --- a/library/core/src/iter/range.rs +++ b/library/core/src/iter/range.rs @@ -106,7 +106,7 @@ fn forward(start: Self, count: usize) -> Self { /// 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) } @@ -178,7 +178,7 @@ fn backward(start: Self, count: usize) -> Self { /// 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) } diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index b14b5aeb572..a7e700b935e 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -51,6 +51,14 @@ pub struct Feature { pub has_gate_test: bool, pub tracking_issue: Option, } +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; @@ -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(), ); } }