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

Stabilize nonzero_leading_trailing_zeros #84082

Merged
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
2 changes: 1 addition & 1 deletion library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ extern "rust-intrinsic" {
/// let num_trailing = unsafe { cttz_nonzero(x) };
/// assert_eq!(num_trailing, 3);
/// ```
#[rustc_const_unstable(feature = "const_cttz", issue = "none")]
#[rustc_const_stable(feature = "const_cttz", since = "1.53.0")]
pub fn cttz_nonzero<T: Copy>(x: T) -> T;

/// Reverses the bytes in an integer type `T`.
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
#![feature(const_int_unchecked_arith)]
#![feature(const_mut_refs)]
#![feature(const_refs_to_cell)]
#![feature(const_cttz)]
#![feature(const_panic)]
#![feature(const_pin)]
#![feature(const_fn)]
Expand Down
10 changes: 4 additions & 6 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,12 @@ macro_rules! nonzero_leading_trailing_zeros {
/// Basic usage:
///
/// ```
/// #![feature(nonzero_leading_trailing_zeros)]
#[doc = concat!("let n = std::num::", stringify!($Ty), "::new(", stringify!($LeadingTestExpr), ").unwrap();")]
///
/// assert_eq!(n.leading_zeros(), 0);
/// ```
#[unstable(feature = "nonzero_leading_trailing_zeros", issue = "79143")]
#[rustc_const_unstable(feature = "nonzero_leading_trailing_zeros", issue = "79143")]
#[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
#[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
andjo403 marked this conversation as resolved.
Show resolved Hide resolved
#[inline]
pub const fn leading_zeros(self) -> u32 {
// SAFETY: since `self` can not be zero it is safe to call ctlz_nonzero
Expand All @@ -214,13 +213,12 @@ macro_rules! nonzero_leading_trailing_zeros {
/// Basic usage:
///
/// ```
/// #![feature(nonzero_leading_trailing_zeros)]
#[doc = concat!("let n = std::num::", stringify!($Ty), "::new(0b0101000).unwrap();")]
///
/// assert_eq!(n.trailing_zeros(), 3);
/// ```
#[unstable(feature = "nonzero_leading_trailing_zeros", issue = "79143")]
#[rustc_const_unstable(feature = "nonzero_leading_trailing_zeros", issue = "79143")]
#[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
#[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
#[inline]
pub const fn trailing_zeros(self) -> u32 {
// SAFETY: since `self` can not be zero it is safe to call cttz_nonzero
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
#![feature(ptr_metadata)]
#![feature(once_cell)]
#![feature(unsized_tuple_coercion)]
#![feature(nonzero_leading_trailing_zeros)]
#![feature(const_option)]
#![feature(integer_atomics)]
#![feature(slice_group_by)]
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/consts/const-int-unchecked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,13 @@ const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::MIN, -1) };
//~^ ERROR any use of this value will cause an error
//~| WARN this was previously accepted by the compiler but is being phased out

// capture fault with zero value

const _: u32 = unsafe { std::intrinsics::ctlz_nonzero(0) };
//~^ ERROR any use of this value will cause an error
//~| WARN this was previously accepted by the compiler but is being phased out
const _: u32 = unsafe { std::intrinsics::cttz_nonzero(0) };
//~^ ERROR any use of this value will cause an error
//~| WARN this was previously accepted by the compiler but is being phased out

fn main() {}
24 changes: 23 additions & 1 deletion src/test/ui/consts/const-int-unchecked.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -516,5 +516,27 @@ LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::MIN, -1) };
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

error: aborting due to 47 previous errors
error: any use of this value will cause an error
--> $DIR/const-int-unchecked.rs:191:25
|
LL | const _: u32 = unsafe { std::intrinsics::ctlz_nonzero(0) };
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| `ctlz_nonzero` called on 0
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

error: any use of this value will cause an error
--> $DIR/const-int-unchecked.rs:194:25
|
LL | const _: u32 = unsafe { std::intrinsics::cttz_nonzero(0) };
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| `cttz_nonzero` called on 0
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

error: aborting due to 49 previous errors