diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-07-09 13:05:11 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-07-09 13:05:11 +0300 |
commit | 93f3d6e230f15b428f5be3a49b813cad093c0aa2 (patch) | |
tree | 2f2aa81847845655eeb3e549e4d1d3d4c2e9cab0 /melib/src/lib.rs | |
parent | 70e594959054b7955ddef0854e02fe588392e0db (diff) |
remove std::dbg uses
Diffstat (limited to 'melib/src/lib.rs')
-rw-r--r-- | melib/src/lib.rs | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/melib/src/lib.rs b/melib/src/lib.rs index 9edf2838..97b142dc 100644 --- a/melib/src/lib.rs +++ b/melib/src/lib.rs @@ -42,21 +42,27 @@ pub mod dbg { } }; ($val:expr) => { - { if cfg!(debug_assertions) { - eprint!( - "[{:?}] {}:{}_{}: ", - std::thread::current() - .name() - .map(std::string::ToString::to_string) - .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), - file!(), - line!(), - column!() - ); - eprintln!("{} = {:?}", stringify!($val), $val); - } - $val + // Use of `match` here is intentional because it affects the lifetimes + // of temporaries - https://stackoverflow.com/a/48732525/1063961 + match $val { + tmp => { + eprint!( + "[{:?}] {}:{}_{}: ", + std::thread::current() + .name() + .map(std::string::ToString::to_string) + .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), + file!(), + line!(), + column!() + ); + eprintln!("{} = {:?}", stringify!(tmp), tmp); + tmp + } + } + } else { + $val } }; ($fmt:literal, $($arg:tt)*) => { |