about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAndre Bogus <bogusandre@gmail.com>2019-04-10 06:00:35 +0200
committerAndre Bogus <bogusandre@gmail.com>2019-04-19 21:12:50 +0200
commitb641fd374e82fc8e3cf6b876fa57270f2de39b32 (patch)
tree3a417e0f21b296619ca85447dd26aec2140f28cc /src/libstd
parent08a4628bf6691067f28f387a2141265676c11d38 (diff)
downloadrust-b641fd374e82fc8e3cf6b876fa57270f2de39b32.tar.gz
rust-b641fd374e82fc8e3cf6b876fa57270f2de39b32.zip
extend ui test
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/macros.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index e245a048955..9eba76cc04a 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -321,6 +321,15 @@ macro_rules! eprintln {
 /// assert_eq!(dbg!(1usize, 2u32), (1, 2));
 /// ```
 ///
+/// However, a single argument with a trailing comma will still not be treated
+/// as a tuple, following the convention of ignoring trailing commas in macro
+/// invocations. You can use a 1-tuple directly if you need one:
+///
+/// ```
+/// assert_eq!(1, dbg!(1u32,)); // trailing comma ignored
+/// assert_eq!((1,), dbg!((1u32,))); // 1-tuple
+/// ```
+///
 /// [stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)
 /// [`debug!`]: https://docs.rs/log/*/log/macro.debug.html
 /// [`log`]: https://crates.io/crates/log
@@ -341,9 +350,11 @@ macro_rules! dbg {
             }
         }
     };
+    // Trailing comma with single argument is ignored
+    ($val:expr,) => { dbg!($val) };
     ($($val:expr),+ $(,)?) => {
         ($(dbg!($val)),+,)
-    }
+    };
 }
 
 /// Awaits the completion of an async call.