From 8767093eb98358a1d62a934a58e1c89c72223cd6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 10 May 2014 13:57:26 -0700 Subject: [PATCH] std: Rewrite the `write!` and `writeln!` macros These are reimplemented using the new `core::fmt` module. --- src/libstd/macros.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 3a0e78b39d1..063ee0d8215 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -251,10 +251,17 @@ fn run_fmt(fmt: &::std::fmt::Arguments) -> ! { /// write!(&mut w, "formatted {}", "arguments"); /// ``` #[macro_export] +#[cfg(not(stage0))] macro_rules! write( ($dst:expr, $($arg:tt)*) => ({ - let dst: &mut ::std::io::Writer = $dst; - format_args!(|args| { ::std::fmt::write(dst, args) }, $($arg)*) + format_args_method!($dst, write_fmt, $($arg)*) + }) +) +#[cfg(stage0)] +#[macro_export] +macro_rules! write( + ($dst:expr, $($arg:tt)*) => ({ + format_args!(|args| { $dst.write_fmt(args) }, $($arg)*) }) ) @@ -262,9 +269,9 @@ fn run_fmt(fmt: &::std::fmt::Arguments) -> ! { /// the message is written. #[macro_export] macro_rules! writeln( - ($dst:expr, $($arg:tt)*) => ({ - let dst: &mut ::std::io::Writer = $dst; - format_args!(|args| { ::std::fmt::writeln(dst, args) }, $($arg)*) + ($dst:expr, $fmt:expr $($arg:tt)*) => ({ + format_args!(|args| { $dst.write_fmt(args) }, + concat!($fmt, "\n") $($arg)*) }) ) -- GitLab