From 064c7c31c5eeebaf5dbe52435ad79402bb712666 Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Tue, 10 Dec 2024 22:12:47 +1100 Subject: [PATCH] feat(dbg): lift the latest version Signed-off-by: Anhad Singh --- src/macros.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index a7ef0c8e6d..c634f625d6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -45,8 +45,12 @@ macro_rules! eprintln { /// Lifted from libstd #[macro_export] macro_rules! dbg { + // NOTE: We cannot use `concat!` to make a static string as a format argument + // of `eprintln!` because `file!` could contain a `{` or + // `$val` expression could be a block (`{ .. }`), in which case the `eprintln!` + // will be malformed. () => { - eprintln!("[{}:{}]", file!(), line!()); + eprintln!("[{}:{}:{}]", file!(), line!(), column!()); }; ($val:expr) => { // Use of `match` here is intentional because it affects the lifetimes @@ -54,9 +58,10 @@ macro_rules! dbg { match $val { tmp => { eprintln!( - "[{}:{}] {} = {:#?}", + "[{}:{}:{}] {} = {:#?}", file!(), line!(), + column!(), stringify!($val), &tmp ); @@ -64,6 +69,9 @@ macro_rules! dbg { } } }; + ($($val:expr),+ $(,)?) => { + ($(dbg!($val)),+,) + }; } #[macro_export]