about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-05-10 13:57:26 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-05-15 23:22:06 -0700
commit8767093eb98358a1d62a934a58e1c89c72223cd6 (patch)
tree9e8acd5b4e5b5b0f207a0326555b8e40021d5f93
parent854d95f9ffe83c8f77782b5dc76d18799579ba95 (diff)
downloadrust-8767093eb98358a1d62a934a58e1c89c72223cd6.tar.gz
rust-8767093eb98358a1d62a934a58e1c89c72223cd6.zip
std: Rewrite the `write!` and `writeln!` macros
These are reimplemented using the new `core::fmt` module.
-rw-r--r--src/libstd/macros.rs17
1 files 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 @@ macro_rules! format_strbuf(
 /// 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 @@ macro_rules! write(
 /// 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)*)
     })
 )