Auto merge of #59826 - llogiq:multi-dbg, r=SimonSapin
allow multiple args to `dbg!(..)` This closes #59763
This commit is contained in:
commit
33fe1131ca
2 changed files with 44 additions and 1 deletions
|
@ -314,6 +314,22 @@ macro_rules! eprintln {
|
||||||
/// You can also use `dbg!()` without a value to just print the
|
/// You can also use `dbg!()` without a value to just print the
|
||||||
/// file and line whenever it's reached.
|
/// 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)
|
/// [stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)
|
||||||
/// [`debug!`]: https://docs.rs/log/*/log/macro.debug.html
|
/// [`debug!`]: https://docs.rs/log/*/log/macro.debug.html
|
||||||
/// [`log`]: https://crates.io/crates/log
|
/// [`log`]: https://crates.io/crates/log
|
||||||
|
@ -333,7 +349,12 @@ macro_rules! dbg {
|
||||||
tmp
|
tmp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
// Trailing comma with single argument is ignored
|
||||||
|
($val:expr,) => { dbg!($val) };
|
||||||
|
($($val:expr),+ $(,)?) => {
|
||||||
|
($(dbg!($val)),+,)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Awaits the completion of an async call.
|
/// Awaits the completion of an async call.
|
||||||
|
|
|
@ -54,6 +54,17 @@ fn test() {
|
||||||
7331
|
7331
|
||||||
}));
|
}));
|
||||||
assert_eq!(foo, 42);
|
assert_eq!(foo, 42);
|
||||||
|
|
||||||
|
// Test trailing comma:
|
||||||
|
assert_eq!(("Yeah",), dbg!(("Yeah",)));
|
||||||
|
|
||||||
|
// Test multiple arguments:
|
||||||
|
assert_eq!((1u8, 2u32), dbg!(1,
|
||||||
|
2));
|
||||||
|
|
||||||
|
// Test multiple arguments + trailing comma:
|
||||||
|
assert_eq!((1u8, 2u32, "Yeah"), dbg!(1u8, 2u32,
|
||||||
|
"Yeah",));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_stderr(stderr: Vec<String>) {
|
fn validate_stderr(stderr: Vec<String>) {
|
||||||
|
@ -85,6 +96,17 @@ fn validate_stderr(stderr: Vec<String>) {
|
||||||
|
|
||||||
"before",
|
"before",
|
||||||
":51] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
|
":51] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
|
||||||
|
|
||||||
|
":59] (\"Yeah\",) = (",
|
||||||
|
" \"Yeah\",",
|
||||||
|
")",
|
||||||
|
|
||||||
|
":62] 1 = 1",
|
||||||
|
":62] 2 = 2",
|
||||||
|
|
||||||
|
":66] 1u8 = 1",
|
||||||
|
":66] 2u32 = 2",
|
||||||
|
":66] \"Yeah\" = \"Yeah\"",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue