Skip to content
Open
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
1 change: 0 additions & 1 deletion library/alloctests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
12 changes: 4 additions & 8 deletions library/core/src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ macro_rules! impl_Display {
/// # Examples
///
/// ```
/// #![feature(int_format_into)]
/// use core::fmt::NumBuffer;
///
#[doc = concat!("let n = 0", stringify!($Signed), ";")]
Expand All @@ -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<Self>) -> &str {
let mut offset;

Expand Down Expand Up @@ -305,7 +304,6 @@ macro_rules! impl_Display {
/// # Examples
///
/// ```
/// #![feature(int_format_into)]
/// use core::fmt::NumBuffer;
///
#[doc = concat!("let n = 0", stringify!($Unsigned), ";")]
Expand All @@ -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<Self>) -> &str {
let offset;

Expand Down Expand Up @@ -744,7 +742,6 @@ impl u128 {
/// # Examples
///
/// ```
/// #![feature(int_format_into)]
/// use core::fmt::NumBuffer;
///
/// let n = 0u128;
Expand All @@ -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<Self>) -> &str {
let diff = buf.capacity() - U128_MAX_DEC_N;
// FIXME: Once const generics are better, use `NumberBufferTrait::BUF_SIZE` as generic const
Expand All @@ -779,7 +776,6 @@ impl i128 {
/// # Examples
///
/// ```
/// #![feature(int_format_into)]
/// use core::fmt::NumBuffer;
///
/// let n = 0i128;
Expand All @@ -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<Self>) -> &str {
let diff = buf.capacity() - U128_MAX_DEC_N;
// FIXME: Once const generics are better, use `NumberBufferTrait::BUF_SIZE` as generic const
Expand Down
18 changes: 9 additions & 9 deletions library/core/src/fmt/num_buffer.rs
Original file line number Diff line number Diff line change
@@ -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 {
Comment thread
GuillaumeGomez marked this conversation as resolved.
/// 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;
}
Expand All @@ -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<T: NumBufferTrait> {
// FIXME: Once const generics feature is working, use `T::BUF_SIZE` instead of 40.
Expand All @@ -43,18 +44,17 @@ pub struct NumBuffer<T: NumBufferTrait> {
phantom: core::marker::PhantomData<T>,
}

#[unstable(feature = "int_format_into", issue = "138215")]
#[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")]
impl<T: NumBufferTrait> NumBuffer<T> {
/// 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::<u8>::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 {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the size of NumBuffer is always the same, we are forced to use this method until we can actually use the NumBufferTrat::BUF_SIZE when declaring NumBuffer.

self.buf.len()
}
}
Loading