From 789f4f2ef1b7883a3cc3f9331dce1b4f85921ccb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 28 Mar 2026 13:07:02 +0100 Subject: [PATCH] Stabilize `int_format_into` feature --- library/alloctests/tests/lib.rs | 1 - library/core/src/fmt/mod.rs | 6 ++++-- library/core/src/fmt/num.rs | 12 ++++-------- library/core/src/fmt/num_buffer.rs | 18 +++++++++--------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/library/alloctests/tests/lib.rs b/library/alloctests/tests/lib.rs index 699a5010282b0..4531b4710c85a 100644 --- a/library/alloctests/tests/lib.rs +++ b/library/alloctests/tests/lib.rs @@ -8,7 +8,6 @@ #![feature(downcast_unchecked)] #![feature(exact_size_is_empty)] #![feature(hashmap_internals)] -#![feature(int_format_into)] #![feature(linked_list_cursors)] #![feature(map_try_insert)] #![feature(pattern)] diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index ecd1e34078e29..ddd3b9e27925e 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -36,8 +36,10 @@ pub enum Alignment { Center, } -#[unstable(feature = "int_format_into", issue = "138215")] -pub use num_buffer::{NumBuffer, NumBufferTrait}; +#[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] +pub use num_buffer::NumBuffer; +#[unstable(feature = "fmt_internals", issue = "none")] +pub use num_buffer::NumBufferTrait; #[stable(feature = "debug_builders", since = "1.2.0")] pub use self::builders::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple}; diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index e9302a6127f5c..86c6a3a8321c8 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -260,7 +260,6 @@ macro_rules! impl_Display { /// # Examples /// /// ``` - /// #![feature(int_format_into)] /// use core::fmt::NumBuffer; /// #[doc = concat!("let n = 0", stringify!($Signed), ";")] @@ -273,7 +272,7 @@ macro_rules! impl_Display { #[doc = concat!("let n2 = ", stringify!($Signed::MAX), ";")] #[doc = concat!("assert_eq!(n2.format_into(&mut buf), ", stringify!($Signed::MAX), ".to_string());")] /// ``` - #[unstable(feature = "int_format_into", issue = "138215")] + #[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] pub fn format_into(self, buf: &mut NumBuffer) -> &str { let mut offset; @@ -305,7 +304,6 @@ macro_rules! impl_Display { /// # Examples /// /// ``` - /// #![feature(int_format_into)] /// use core::fmt::NumBuffer; /// #[doc = concat!("let n = 0", stringify!($Unsigned), ";")] @@ -318,7 +316,7 @@ macro_rules! impl_Display { #[doc = concat!("let n2 = ", stringify!($Unsigned::MAX), ";")] #[doc = concat!("assert_eq!(n2.format_into(&mut buf), ", stringify!($Unsigned::MAX), ".to_string());")] /// ``` - #[unstable(feature = "int_format_into", issue = "138215")] + #[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] pub fn format_into(self, buf: &mut NumBuffer) -> &str { let offset; @@ -744,7 +742,6 @@ impl u128 { /// # Examples /// /// ``` - /// #![feature(int_format_into)] /// use core::fmt::NumBuffer; /// /// let n = 0u128; @@ -759,7 +756,7 @@ impl u128 { /// let mut buf2 = NumBuffer::new(); /// assert_eq!(n2.format_into(&mut buf2), u128::MAX.to_string()); /// ``` - #[unstable(feature = "int_format_into", issue = "138215")] + #[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] pub fn format_into(self, buf: &mut NumBuffer) -> &str { let diff = buf.capacity() - U128_MAX_DEC_N; // FIXME: Once const generics are better, use `NumberBufferTrait::BUF_SIZE` as generic const @@ -779,7 +776,6 @@ impl i128 { /// # Examples /// /// ``` - /// #![feature(int_format_into)] /// use core::fmt::NumBuffer; /// /// let n = 0i128; @@ -792,7 +788,7 @@ impl i128 { /// let n2 = i128::MAX; /// assert_eq!(n2.format_into(&mut buf), i128::MAX.to_string()); /// ``` - #[unstable(feature = "int_format_into", issue = "138215")] + #[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] pub fn format_into(self, buf: &mut NumBuffer) -> &str { let diff = buf.capacity() - U128_MAX_DEC_N; // FIXME: Once const generics are better, use `NumberBufferTrait::BUF_SIZE` as generic const diff --git a/library/core/src/fmt/num_buffer.rs b/library/core/src/fmt/num_buffer.rs index 474a8d20ef6c5..a5b21979cb165 100644 --- a/library/core/src/fmt/num_buffer.rs +++ b/library/core/src/fmt/num_buffer.rs @@ -1,21 +1,22 @@ use crate::mem::MaybeUninit; /// Trait used to describe the maximum number of digits in decimal base of the implemented integer. -#[unstable(feature = "int_format_into", issue = "138215")] +#[unstable(feature = "fmt_internals", issue = "none")] pub trait NumBufferTrait { /// Maximum number of digits in decimal base of the implemented integer. + #[unstable(feature = "fmt_internals", issue = "none")] const BUF_SIZE: usize; } macro_rules! impl_NumBufferTrait { ($($signed:ident, $unsigned:ident,)*) => { $( - #[unstable(feature = "int_format_into", issue = "138215")] + #[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] impl NumBufferTrait for $signed { // `+ 2` and not `+ 1` to include the `-` character. const BUF_SIZE: usize = $signed::MAX.ilog(10) as usize + 2; } - #[unstable(feature = "int_format_into", issue = "138215")] + #[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] impl NumBufferTrait for $unsigned { const BUF_SIZE: usize = $unsigned::MAX.ilog(10) as usize + 1; } @@ -34,7 +35,7 @@ impl_NumBufferTrait! { /// A buffer wrapper of which the internal size is based on the maximum /// number of digits the associated integer can have. -#[unstable(feature = "int_format_into", issue = "138215")] +#[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] #[derive(Debug)] pub struct NumBuffer { // FIXME: Once const generics feature is working, use `T::BUF_SIZE` instead of 40. @@ -43,18 +44,17 @@ pub struct NumBuffer { phantom: core::marker::PhantomData, } -#[unstable(feature = "int_format_into", issue = "138215")] +#[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] impl NumBuffer { /// Initializes internal buffer. - #[unstable(feature = "int_format_into", issue = "138215")] + #[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")] pub const fn new() -> Self { // FIXME: Once const generics feature is working, use `T::BUF_SIZE` instead of 40. NumBuffer { buf: [MaybeUninit::::uninit(); 40], phantom: core::marker::PhantomData } } - /// Returns the length of the internal buffer. - #[unstable(feature = "int_format_into", issue = "138215")] - pub const fn capacity(&self) -> usize { + pub(crate) const fn capacity(&self) -> usize { self.buf.len() } }