Skip to content

Commit 1e4c8b1

Browse files
authored
Auto merge of #36825 - sbwtw:master, r=alexcrichton
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()
2 parents ead9212 + 7d6227a commit 1e4c8b1

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/libstd/macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ macro_rules! print {
112112
/// # Examples
113113
///
114114
/// ```
115+
/// println!();
115116
/// println!("hello there!");
116117
/// println!("format {} arguments", "some");
117118
/// ```
118119
#[macro_export]
119120
#[stable(feature = "rust1", since = "1.0.0")]
120121
macro_rules! println {
122+
() => (print!("\n"));
121123
($fmt:expr) => (print!(concat!($fmt, "\n")));
122124
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
123125
}

src/test/compile-fail/empty-comment.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
// This could break some internal logic that assumes the length of a doc comment is at least 5,
1313
// leading to an ICE.
1414

15+
macro_rules! one_arg_macro {
16+
($fmt:expr) => (print!(concat!($fmt, "\n")));
17+
}
18+
1519
fn main() {
16-
println!(/**/); //~ ERROR unexpected end
20+
one_arg_macro!(/**/); //~ ERROR unexpected end
1721
}

src/test/compile-fail/issue-7970a.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
macro_rules! one_arg_macro {
12+
($fmt:expr) => (print!(concat!($fmt, "\n")));
13+
}
14+
1115
fn main() {
12-
println!();
16+
one_arg_macro!();
1317
//~^ ERROR unexpected end of macro invocation
1418
}

0 commit comments

Comments
 (0)