diff options
| author | bors <bors@rust-lang.org> | 2019-04-20 20:55:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-04-20 20:55:29 +0000 |
| commit | 33fe1131cadba69d317156847be9a402b89f11bb (patch) | |
| tree | 9975e59b97617de157e3df82cd127cb809279b03 /src/libstd | |
| parent | 4530c528ba4eadd7623813316d75bd4b97012b6c (diff) | |
| parent | b641fd374e82fc8e3cf6b876fa57270f2de39b32 (diff) | |
| download | rust-33fe1131cadba69d317156847be9a402b89f11bb.tar.gz rust-33fe1131cadba69d317156847be9a402b89f11bb.zip | |
Auto merge of #59826 - llogiq:multi-dbg, r=SimonSapin
allow multiple args to `dbg!(..)` This closes #59763
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/macros.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 14b266a4344..9eba76cc04a 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -314,6 +314,22 @@ macro_rules! eprintln { /// You can also use `dbg!()` without a value to just print the /// file and line whenever it's reached. /// +/// Finally, if you want to `dbg!(..)` multiple values, it will treat them as +/// a tuple (and return it, too): +/// +/// ``` +/// 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 @@ -333,7 +349,12 @@ macro_rules! dbg { tmp } } - } + }; + // Trailing comma with single argument is ignored + ($val:expr,) => { dbg!($val) }; + ($($val:expr),+ $(,)?) => { + ($(dbg!($val)),+,) + }; } /// Awaits the completion of an async call. |
