Skip to content

Commit 1ee0392

Browse files
Simplify to invoking Trait on ident
1 parent 4e45df7 commit 1ee0392

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

library/alloc/src/macros.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ macro_rules! vec {
6464
($($x:expr,)*) => (vec![$($x),*])
6565
}
6666

67-
// HACK(jubilee): Shim for specializing format! It is possible to manually
68-
// implement ToString, bypassing Display. "{}" normally formats in terms of
69-
// Display. NeedsDisplay enforces equally strict type boundarie.
70-
#[unstable(feature = "display_type_guard", issue = "none")]
71-
#[allow(dead_code)]
72-
struct NeedsDisplay<T: crate::fmt::Display> {
73-
inner: T,
74-
}
75-
7667
/// Creates a `String` using interpolation of runtime expressions.
7768
///
7869
/// The first argument `format!` receives is a format string. This must be a string
@@ -108,15 +99,12 @@ struct NeedsDisplay<T: crate::fmt::Display> {
10899
/// format!("hello {}", "world!");
109100
/// format!("x = {}, y = {y}", 10, y = 30);
110101
/// ```
111-
#[allow_internal_unstable(display_type_guard)]
112102
#[macro_export]
113103
#[stable(feature = "rust1", since = "1.0.0")]
114104
macro_rules! format {
115105
// A faster path for simple format! calls.
116-
("{}", $($arg:tt,?)+) => {{
117-
let fast = |t: NeedsDisplay<_> | $crate::string::ToString::to_string(t.inner);
118-
// This TokenTree must resolve to a Displayable value to be valid.
119-
fast(NeedsDisplay { inner: &{$($arg)*} })
106+
("{}", $arg:ident) => {{
107+
$crate::fmt::Display::to_string(&$arg)
120108
}};
121109
($($arg:tt)*) => {{
122110
let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));

0 commit comments

Comments
 (0)