Rollup merge of #132445 - RalfJung:const-unchecked-shifts, r=tgross35

Cleanup attributes around unchecked shifts and unchecked negation in const

The underlying intrinsic is marked as "safe to expose on stable", so we shouldn't need any `rustc_allow_const_fn_unstable(unchecked_shifts)` anywhere. However, bootstrap rustc doesn't yet have the new const stability checks, so these changes only apply under `cfg(not(bootstrap))`.
This commit is contained in:
Guillaume Gomez 2024-11-02 03:08:54 +08:00 committed by GitHub
commit 8366ecca2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 20 deletions

View File

@ -1161,7 +1161,7 @@ pub const fn checked_neg(self) -> Option<Self> {
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "unchecked_neg", issue = "85122")]
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "unchecked_neg", issue = "85122"))]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_neg(self) -> Self {
@ -1227,8 +1227,7 @@ pub const fn strict_neg(self) -> Self {
/// ```
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
// We could always go back to wrapping
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_shifts))]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
@ -1294,7 +1293,7 @@ pub const fn strict_shl(self, rhs: u32) -> Self {
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "unchecked_shifts", issue = "85122"))]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
@ -1353,8 +1352,7 @@ pub const fn unbounded_shl(self, rhs: u32) -> $SelfT{
/// ```
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
// We could always go back to wrapping
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_shifts))]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
@ -1420,7 +1418,7 @@ pub const fn strict_shr(self, rhs: u32) -> Self {
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "unchecked_shifts", issue = "85122"))]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
@ -2151,7 +2149,7 @@ pub const fn wrapping_neg(self) -> Self {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_shifts))]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
// out of bounds
@ -2181,7 +2179,7 @@ pub const fn wrapping_shl(self, rhs: u32) -> Self {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_shifts))]
pub const fn wrapping_shr(self, rhs: u32) -> Self {
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
// out of bounds

View File

@ -1416,8 +1416,7 @@ pub const fn strict_neg(self) -> Self {
/// ```
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
// We could always go back to wrapping
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_shifts))]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
@ -1483,7 +1482,7 @@ pub const fn strict_shl(self, rhs: u32) -> Self {
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "unchecked_shifts", issue = "85122"))]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
@ -1542,8 +1541,7 @@ pub const fn unbounded_shl(self, rhs: u32) -> $SelfT{
/// ```
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
// We could always go back to wrapping
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_shifts))]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
@ -1609,7 +1607,7 @@ pub const fn strict_shr(self, rhs: u32) -> Self {
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "unchecked_shifts", issue = "85122"))]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
@ -2132,7 +2130,7 @@ pub const fn wrapping_neg(self) -> Self {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_shifts))]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
// out of bounds
@ -2165,7 +2163,7 @@ pub const fn wrapping_shl(self, rhs: u32) -> Self {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_shifts))]
pub const fn wrapping_shr(self, rhs: u32) -> Self {
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
// out of bounds

View File

@ -1005,7 +1005,7 @@ const fn comptime(_: *const (), _: usize, _: usize) -> bool {
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[rustc_allow_const_fn_unstable(unchecked_neg)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_neg))]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn sub(self, count: usize) -> Self

View File

@ -1085,7 +1085,7 @@ const fn comptime(_: *const (), _: usize, _: usize) -> bool {
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[rustc_allow_const_fn_unstable(unchecked_neg)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_neg))]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn sub(self, count: usize) -> Self

View File

@ -635,7 +635,7 @@ pub const fn cast<U>(self) -> NonNull<U> {
#[must_use = "returns a new pointer rather than modifying its argument"]
#[stable(feature = "non_null_convenience", since = "1.80.0")]
#[rustc_const_stable(feature = "non_null_convenience", since = "1.80.0")]
#[rustc_allow_const_fn_unstable(unchecked_neg)]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(unchecked_neg))]
pub const unsafe fn sub(self, count: usize) -> Self
where
T: Sized,