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]