Skip to content

Commit

Permalink
Simplify to invoking Trait on ident
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Oct 21, 2020
1 parent 4e45df7 commit 1ee0392
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions library/alloc/src/macros.rs
Expand Up @@ -64,15 +64,6 @@ macro_rules! vec {
($($x:expr,)*) => (vec![$($x),*])
}

// HACK(jubilee): Shim for specializing format! It is possible to manually
// implement ToString, bypassing Display. "{}" normally formats in terms of
// Display. NeedsDisplay enforces equally strict type boundarie.
#[unstable(feature = "display_type_guard", issue = "none")]
#[allow(dead_code)]
struct NeedsDisplay<T: crate::fmt::Display> {
inner: T,
}

/// Creates a `String` using interpolation of runtime expressions.
///
/// The first argument `format!` receives is a format string. This must be a string
Expand Down Expand Up @@ -108,15 +99,12 @@ struct NeedsDisplay<T: crate::fmt::Display> {
/// format!("hello {}", "world!");
/// format!("x = {}, y = {y}", 10, y = 30);
/// ```
#[allow_internal_unstable(display_type_guard)]
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! format {
// A faster path for simple format! calls.
("{}", $($arg:tt,?)+) => {{
let fast = |t: NeedsDisplay<_> | $crate::string::ToString::to_string(t.inner);
// This TokenTree must resolve to a Displayable value to be valid.
fast(NeedsDisplay { inner: &{$($arg)*} })
("{}", $arg:ident) => {{
$crate::fmt::Display::to_string(&$arg)
}};
($($arg:tt)*) => {{
let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));
Expand Down

0 comments on commit 1ee0392

Please sign in to comment.