about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-07-22 06:52:48 +0000
committerbors <bors@rust-lang.org>2018-07-22 06:52:48 +0000
commit3d5108630371932b05d4e650d20536910434c947 (patch)
treea3cdf0d3c6863f06f653a992aa299682547ff095 /src/libstd
parenta57d5d7b25d471c902608223793d9b3bb8c4643c (diff)
parentdc563d950017fedaa4690165d2d8b9b3e6cbd982 (diff)
downloadrust-3d5108630371932b05d4e650d20536910434c947.tar.gz
rust-3d5108630371932b05d4e650d20536910434c947.zip
Auto merge of #52394 - estebank:println, r=oli-obk
Improve suggestion for missing fmt str in println

Avoid using `concat!(fmt, "\n")` to improve the diagnostics being
emitted when the first `println!()` argument isn't a formatting string
literal.

Fix #52347.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/macros.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index 75f038407c1..76f38646308 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -153,10 +153,17 @@ macro_rules! print {
 /// ```
 #[macro_export]
 #[stable(feature = "rust1", since = "1.0.0")]
+#[allow_internal_unstable]
 macro_rules! println {
     () => (print!("\n"));
-    ($fmt:expr) => (print!(concat!($fmt, "\n")));
-    ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($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.
@@ -210,10 +217,17 @@ macro_rules! eprint {
 /// ```
 #[macro_export]
 #[stable(feature = "eprint", since = "1.19.0")]
+#[allow_internal_unstable]
 macro_rules! eprintln {
     () => (eprint!("\n"));
-    ($fmt:expr) => (eprint!(concat!($fmt, "\n")));
-    ($fmt:expr, $($arg:tt)*) => (eprint!(concat!($fmt, "\n"), $($arg)*));
+    ($($arg:tt)*) => ({
+        #[cfg(all(not(stage0), not(stage1)))] {
+            ($crate::io::_eprint(format_args_nl!($($arg)*)));
+        }
+        #[cfg(any(stage0, stage1))] {
+            eprint!("{}\n", format_args!($($arg)*))
+        }
+    })
 }
 
 #[macro_export]