diff options
| author | 石博文 <sbw@sbw.so> | 2016-09-29 17:26:54 +0800 |
|---|---|---|
| committer | 石博文 <sbw@sbw.so> | 2016-09-30 09:11:18 +0800 |
| commit | 7d6227a9b34670fe235d6c35416e8ab643c1341c (patch) | |
| tree | 8bf693a6c2f4d8c18604eb7f53f283ec0fd3a49c | |
| parent | eee2d04d877fe909309c39b6bdf711dc586d0a1e (diff) | |
| download | rust-7d6227a9b34670fe235d6c35416e8ab643c1341c.tar.gz rust-7d6227a9b34670fe235d6c35416e8ab643c1341c.zip | |
add println!() macro with out any arguments
| -rw-r--r-- | src/libstd/macros.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/empty-comment.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-7970a.rs | 6 |
3 files changed, 12 insertions, 2 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index c78840bd42b..f18f1572cea 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -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)*)); } diff --git a/src/test/compile-fail/empty-comment.rs b/src/test/compile-fail/empty-comment.rs index 5c521a5f304..a5568ff826b 100644 --- a/src/test/compile-fail/empty-comment.rs +++ b/src/test/compile-fail/empty-comment.rs @@ -12,6 +12,10 @@ // 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 } diff --git a/src/test/compile-fail/issue-7970a.rs b/src/test/compile-fail/issue-7970a.rs index 114db74f420..b97c3037770 100644 --- a/src/test/compile-fail/issue-7970a.rs +++ b/src/test/compile-fail/issue-7970a.rs @@ -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 } |
