]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #36825 - sbwtw:master, r=alexcrichton
authorbors <bors@rust-lang.org>
Tue, 11 Oct 2016 08:17:03 +0000 (01:17 -0700)
committerGitHub <noreply@github.com>
Tue, 11 Oct 2016 08:17:03 +0000 (01:17 -0700)
add println!() macro with out any arguments

lets add println!() to write "\n".
like java https://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html#println()

src/libstd/macros.rs
src/test/compile-fail/empty-comment.rs
src/test/compile-fail/issue-7970a.rs

index 8946af8af53d756c124ffd93eb344e5cb8d5d182..40e5dd6ba1903ef4973f3521cf6edafe39939fc2 100644 (file)
@@ -112,12 +112,14 @@ macro_rules! print {
 /// # Examples
 ///
 /// ```
+/// println!();
 /// println!("hello there!");
 /// println!("format {} arguments", "some");
 /// ```
 #[macro_export]
 #[stable(feature = "rust1", since = "1.0.0")]
 macro_rules! println {
+    () => (print!("\n"));
     ($fmt:expr) => (print!(concat!($fmt, "\n")));
     ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
 }
index 5c521a5f304d458b5624d34b742e55ea72f648bd..a5568ff826be14bb514d34579a28e783cd974efc 100644 (file)
 // This could break some internal logic that assumes the length of a doc comment is at least 5,
 // leading to an ICE.
 
+macro_rules! one_arg_macro {
+    ($fmt:expr) => (print!(concat!($fmt, "\n")));
+}
+
 fn main() {
-    println!(/**/); //~ ERROR unexpected end
+    one_arg_macro!(/**/); //~ ERROR unexpected end
 }
index 114db74f42048a9660773948278ee8c63f60f038..b97c3037770a65ae7b35d77a2a74017949f97bf4 100644 (file)
@@ -8,7 +8,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+macro_rules! one_arg_macro {
+    ($fmt:expr) => (print!(concat!($fmt, "\n")));
+}
+
 fn main() {
-    println!();
+    one_arg_macro!();
     //~^ ERROR unexpected end of macro invocation
 }