Skip to content

Commit

Permalink
Auto merge of #38469 - tbu-:pr_writeln_no_args, r=brson
Browse files Browse the repository at this point in the history
Allow `writeln!` without arguments, in symmetry with `println!`

CC #36825.
  • Loading branch information
bors committed Jan 7, 2017
2 parents b9637f7 + a0b346a commit e1dfe3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,11 @@ macro_rules! write {
/// use std::io::Write;
///
/// let mut w = Vec::new();
/// writeln!(&mut w).unwrap();
/// writeln!(&mut w, "test").unwrap();
/// writeln!(&mut w, "formatted {}", "arguments").unwrap();
///
/// assert_eq!(&w[..], "test\nformatted arguments\n".as_bytes());
/// assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
/// ```
///
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
Expand All @@ -427,6 +428,9 @@ macro_rules! write {
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! writeln {
($dst:expr) => (
write!($dst, "\n")
);
($dst:expr, $fmt:expr) => (
write!($dst, concat!($fmt, "\n"))
);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ macro_rules! print {
/// # Examples
///
/// ```
/// println!();
/// println!(); // prints just a newline
/// println!("hello there!");
/// println!("format {} arguments", "some");
/// ```
Expand Down

0 comments on commit e1dfe3d

Please sign in to comment.