Skip to content

Commit

Permalink
Rollup merge of rust-lang#103570 - lukas-code:stabilize-ilog, r=scottmcm
Browse files Browse the repository at this point in the history
Stabilize integer logarithms

Stabilizes feature `int_log`.

I've also made the functions const stable, because they don't depend on any unstable const features. `rustc_allow_const_fn_unstable` is just there for `Option::expect`, which could be replaced with a `match` and `panic!`. cc ```@rust-lang/wg-const-eval```

closes rust-lang#70887 (tracking issue)

~~blocked on FCP finishing: rust-lang#70887 (comment)
FCP finished: rust-lang#70887 (comment)
  • Loading branch information
Manishearth authored Nov 9, 2022
2 parents 25be18b + 9e36fd9 commit 147e5df
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
1 change: 0 additions & 1 deletion library/core/benches/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// wasm32 does not support benches (no time).
#![cfg(not(target_arch = "wasm32"))]
#![feature(flt2dec)]
#![feature(int_log)]
#![feature(test)]
#![feature(trusted_random_access)]
#![feature(iter_array_chunks)]
Expand Down
29 changes: 16 additions & 13 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2271,15 +2271,16 @@ macro_rules! int_impl {
/// # Panics
///
/// This function will panic if `self` is less than or equal to zero,
/// or if `base` is less then 2.
/// or if `base` is less than 2.
///
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".ilog(5), 1);")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_option)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -2298,10 +2299,11 @@ macro_rules! int_impl {
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".ilog2(), 1);")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_option)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -2319,10 +2321,11 @@ macro_rules! int_impl {
/// # Example
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(10", stringify!($SelfT), ".ilog10(), 1);")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_option)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -2343,10 +2346,10 @@ macro_rules! int_impl {
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_ilog(5), Some(1));")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -2379,10 +2382,10 @@ macro_rules! int_impl {
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".checked_ilog2(), Some(1));")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -2403,10 +2406,10 @@ macro_rules! int_impl {
/// # Example
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(10", stringify!($SelfT), ".checked_ilog10(), Some(1));")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,14 @@ macro_rules! nonzero_unsigned_operations {
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
///
#[doc = concat!("assert_eq!(", stringify!($Ty), "::new(7).unwrap().ilog2(), 2);")]
#[doc = concat!("assert_eq!(", stringify!($Ty), "::new(8).unwrap().ilog2(), 3);")]
#[doc = concat!("assert_eq!(", stringify!($Ty), "::new(9).unwrap().ilog2(), 3);")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -485,14 +485,14 @@ macro_rules! nonzero_unsigned_operations {
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
///
#[doc = concat!("assert_eq!(", stringify!($Ty), "::new(99).unwrap().ilog10(), 1);")]
#[doc = concat!("assert_eq!(", stringify!($Ty), "::new(100).unwrap().ilog10(), 2);")]
#[doc = concat!("assert_eq!(", stringify!($Ty), "::new(101).unwrap().ilog10(), 2);")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down
29 changes: 16 additions & 13 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,15 +692,16 @@ macro_rules! uint_impl {
///
/// # Panics
///
/// This function will panic if `self` is zero, or if `base` is less then 2.
/// This function will panic if `self` is zero, or if `base` is less than 2.
///
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".ilog(5), 1);")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_option)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -719,10 +720,11 @@ macro_rules! uint_impl {
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".ilog2(), 1);")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_option)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -740,10 +742,11 @@ macro_rules! uint_impl {
/// # Example
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(10", stringify!($SelfT), ".ilog10(), 1);")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_option)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -764,10 +767,10 @@ macro_rules! uint_impl {
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_ilog(5), Some(1));")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -800,10 +803,10 @@ macro_rules! uint_impl {
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".checked_ilog2(), Some(1));")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -822,10 +825,10 @@ macro_rules! uint_impl {
/// # Examples
///
/// ```
/// #![feature(int_log)]
#[doc = concat!("assert_eq!(10", stringify!($SelfT), ".checked_ilog10(), Some(1));")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "int_log", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
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 @@ -64,7 +64,6 @@
#![feature(try_trait_v2)]
#![feature(slice_internals)]
#![feature(slice_partition_dedup)]
#![feature(int_log)]
#![feature(iter_advance_by)]
#![feature(iter_array_chunks)]
#![feature(iter_collect_into)]
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![feature(never_type)]
#![feature(try_blocks)]
#![feature(io_error_more)]
#![feature(int_log)]
#![feature(variant_count)]
#![feature(yeet_expr)]
#![feature(is_some_and)]
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/tests/pass/integer-ops.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@compile-flags: -Coverflow-checks=off
#![feature(int_log)]
#![allow(arithmetic_overflow)]

pub fn main() {
Expand Down

0 comments on commit 147e5df

Please sign in to comment.