about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorEsteban Küber <esteban@commure.com>2018-07-19 18:53:26 -0700
committerEsteban Küber <esteban@commure.com>2018-07-19 23:18:07 -0700
commit154dee2dccd45f929b0a3d2ce2d45739513f77c8 (patch)
tree4170231db8b43d3c03f074eb1521ec7f010c2720 /src/libstd
parenta47653214f8f8561196acf25b8898e7148f1c052 (diff)
downloadrust-154dee2dccd45f929b0a3d2ce2d45739513f77c8.tar.gz
rust-154dee2dccd45f929b0a3d2ce2d45739513f77c8.zip
rework println
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/macros.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index 527bab759b0..a4bcf7fd26c 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -153,9 +153,17 @@ macro_rules! print {
 /// ```
 #[macro_export]
 #[stable(feature = "rust1", since = "1.0.0")]
+#[allow_internal_unstable]
 macro_rules! println {
     () => (print!("\n"));
-    ($($arg:tt)*) => (print!("{}\n", format_args!($($arg)*)));
+    ($($arg:tt)*) => ({
+        #[cfg(not(stage0))] {
+            ($crate::io::_print(format_args_nl!($($arg)*)));
+        }
+        #[cfg(stage0)] {
+            print!("{}\n", format_args!($($arg)*))
+        }
+    })
 }
 
 /// Macro for printing to the standard error.
@@ -211,7 +219,8 @@ macro_rules! eprint {
 #[stable(feature = "eprint", since = "1.19.0")]
 macro_rules! eprintln {
     () => (eprint!("\n"));
-    ($($arg:tt)*) => (eprint!("{}\n", format_args!($($arg)*)));
+    ($fmt:expr) => (eprint!(concat!($fmt, "\n")));
+    ($fmt:expr, $($arg:tt)*) => (eprint!(concat!($fmt, "\n"), $($arg)*));
 }
 
 #[macro_export]
@@ -397,6 +406,19 @@ pub mod builtin {
         ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ });
     }
 
+    /// Internal version of [`format_args`].
+    ///
+    /// This macro differs from [`format_args`] in that it appends a newline to the format string
+    /// and nothing more. It is perma-unstable.
+    ///
+    /// [`format_args`]: ../std/macro.format_args.html
+    #[doc(hidden)]
+    #[unstable(feature = "println_format_args", issue="0")]
+    #[macro_export]
+    macro_rules! format_args_nl {
+        ($fmt:expr) => ({ /* compiler built-in */ });
+        ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ });
+    }
     /// Inspect an environment variable at compile time.
     ///
     /// This macro will expand to the value of the named environment variable at