Skip to content

Commit a0b346a

Browse files
committed
Allow writeln! without arguments, in symmetry with println!
1 parent 10271ea commit a0b346a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/libcore/macros.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,11 @@ macro_rules! write {
404404
/// use std::io::Write;
405405
///
406406
/// let mut w = Vec::new();
407+
/// writeln!(&mut w).unwrap();
407408
/// writeln!(&mut w, "test").unwrap();
408409
/// writeln!(&mut w, "formatted {}", "arguments").unwrap();
409410
///
410-
/// assert_eq!(&w[..], "test\nformatted arguments\n".as_bytes());
411+
/// assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
411412
/// ```
412413
///
413414
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
@@ -427,6 +428,9 @@ macro_rules! write {
427428
#[macro_export]
428429
#[stable(feature = "rust1", since = "1.0.0")]
429430
macro_rules! writeln {
431+
($dst:expr) => (
432+
write!($dst, "\n")
433+
);
430434
($dst:expr, $fmt:expr) => (
431435
write!($dst, concat!($fmt, "\n"))
432436
);

src/libstd/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ macro_rules! print {
112112
/// # Examples
113113
///
114114
/// ```
115-
/// println!();
115+
/// println!(); // prints just a newline
116116
/// println!("hello there!");
117117
/// println!("format {} arguments", "some");
118118
/// ```

0 commit comments

Comments
 (0)