Skip to content

Commit

Permalink
Destabilize format_args! internals.
Browse files Browse the repository at this point in the history
Arguments, Formatters, and the various format traits remain stable. The
format_args! macro uses #[allow_internal_unstable] to allow it access to
the unstable things in core::fmt.

Destabilized things include a "v1" in their name:
 * core::fmt::rt
 * core::fmt::rt::v1 (the module and all contents)
 * core::fmt::ArgumentV1
 * core::fmt::ArgumentV1::new
 * core::fmt::ArgumentV1::from_usize
 * core::fmt::Arguments::new_v1
 * core::fmt::Arguments::new_v1_formatted

The unstable message was copied from that of std::io::_print.
  • Loading branch information
rprichard committed Apr 13, 2015
1 parent bd26307 commit 9cdc9e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
18 changes: 12 additions & 6 deletions src/libcore/fmt/mod.rs
Expand Up @@ -38,7 +38,8 @@ mod num;
mod float;
mod builders;

#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
#[doc(hidden)]
pub mod rt {
pub mod v1;
Expand Down Expand Up @@ -134,7 +135,8 @@ enum Void {}
/// compile time it is ensured that the function and the value have the correct
/// types, and then this struct is used to canonicalize arguments to one type.
#[derive(Copy)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
#[doc(hidden)]
pub struct ArgumentV1<'a> {
value: &'a Void,
Expand All @@ -154,7 +156,8 @@ impl<'a> ArgumentV1<'a> {
}

#[doc(hidden)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
pub fn new<'b, T>(x: &'b T,
f: fn(&T, &mut Formatter) -> Result) -> ArgumentV1<'b> {
unsafe {
Expand All @@ -166,7 +169,8 @@ impl<'a> ArgumentV1<'a> {
}

#[doc(hidden)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
pub fn from_usize(x: &usize) -> ArgumentV1 {
ArgumentV1::new(x, ArgumentV1::show_usize)
}
Expand All @@ -189,7 +193,8 @@ impl<'a> Arguments<'a> {
/// When using the format_args!() macro, this function is used to generate the
/// Arguments structure.
#[doc(hidden)] #[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
pub fn new_v1(pieces: &'a [&'a str],
args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
Arguments {
Expand All @@ -206,7 +211,8 @@ impl<'a> Arguments<'a> {
/// created with `argumentusize`. However, failing to do so doesn't cause
/// unsafety, but will ignore invalid .
#[doc(hidden)] #[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
pub fn new_v1_formatted(pieces: &'a [&'a str],
args: &'a [ArgumentV1<'a>],
fmt: &'a [rt::v1::Argument]) -> Arguments<'a> {
Expand Down
47 changes: 24 additions & 23 deletions src/libcore/fmt/rt/v1.rs
Expand Up @@ -14,68 +14,69 @@
//! These definitions are similar to their `ct` equivalents, but differ in that
//! these can be statically allocated and are slightly optimized for the runtime

#![stable(feature = "rust1", since = "1.0.0")]
#![cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
#![cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]

#[derive(Copy, Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub struct Argument {
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub position: Position,
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub format: FormatSpec,
}

#[derive(Copy, Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub struct FormatSpec {
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub fill: char,
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub align: Alignment,
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub flags: u32,
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub precision: Count,
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub width: Count,
}

/// Possible alignments that can be requested as part of a formatting directive.
#[derive(Copy, Clone, PartialEq)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub enum Alignment {
/// Indication that contents should be left-aligned.
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
Left,
/// Indication that contents should be right-aligned.
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
Right,
/// Indication that contents should be center-aligned.
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
Center,
/// No alignment was requested.
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
Unknown,
}

#[derive(Copy, Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub enum Count {
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
Is(usize),
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
Param(usize),
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
NextParam,
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
Implied,
}

#[derive(Copy, Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
pub enum Position {
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
Next,
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
At(usize)
}

0 comments on commit 9cdc9e9

Please sign in to comment.