From 93f3d6e230f15b428f5be3a49b813cad093c0aa2 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 9 Jul 2019 13:05:11 +0300 Subject: [PATCH] remove std::dbg uses --- melib/src/backends/maildir/backend.rs | 2 +- melib/src/lib.rs | 34 ++++++++++++++++----------- src/bin.rs | 2 +- ui/src/conf/accounts.rs | 4 ++-- ui/src/terminal/text_editing.rs | 4 +--- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/melib/src/backends/maildir/backend.rs b/melib/src/backends/maildir/backend.rs index 9d1b45ea..08613661 100644 --- a/melib/src/backends/maildir/backend.rs +++ b/melib/src/backends/maildir/backend.rs @@ -478,7 +478,7 @@ impl MaildirType { continue 'entries; } if path.is_dir() { - let path_children = std::dbg!(recurse_folders(folders, &path)); + let path_children = recurse_folders(folders, &path); if let Ok(f) = MaildirFolder::new( path.to_str().unwrap().to_string(), path.file_name().unwrap().to_str().unwrap().to_string(), 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)*) => { diff --git a/src/bin.rs b/src/bin.rs index ec24b838..e94f6901 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -92,7 +92,7 @@ fn main() { /* Poll on all channels. Currently we have the input channel for stdin, watching events and the signal watcher. */ chan_select! { receiver.recv() -> r => { - match std::dbg!(r.unwrap()) { + match debug!(r.unwrap()) { ThreadEvent::Input(Key::Ctrl('z')) => { state.switch_to_main_screen(); //_thread_handler.join().expect("Couldn't join on the associated thread"); diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 589bb09c..8214cbf5 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -491,8 +491,8 @@ impl Account { } } debug!("didn't find {}", h); - std::dbg!(&self.folders); - std::dbg!(&self.collection.envelopes); + debug!(&self.folders); + debug!(&self.collection.envelopes); unreachable!() } pub fn thread_to_mail_mut(&mut self, h: ThreadHash, f: FolderHash) -> &mut Envelope { diff --git a/ui/src/terminal/text_editing.rs b/ui/src/terminal/text_editing.rs index a1b8cec9..e19588dc 100644 --- a/ui/src/terminal/text_editing.rs +++ b/ui/src/terminal/text_editing.rs @@ -130,8 +130,6 @@ impl UText { }; self.cursor_dec(); - self.content - .drain(std::dbg!(offset..offset + graph_len)) - .count(); + self.content.drain(offset..offset + graph_len).count(); } }