From 68875359529f1a253bed09f9e20382058eb9789e Mon Sep 17 00:00:00 2001 From: Caleb Leinz Date: Thu, 25 Jan 2024 10:16:10 -0800 Subject: [PATCH] Fix unused variables warnings when not using log --- src/log.rs | 50 +++++++++++++++++++++++++++++++++++++++---------- src/tokio/io.rs | 16 ++++++++-------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/log.rs b/src/log.rs index ee826f1..a4d2378 100644 --- a/src/log.rs +++ b/src/log.rs @@ -1,38 +1,68 @@ #[allow(unused_macros)] macro_rules! trace { - ($($arg:tt)*) => { + ($($arg:expr),*) => { #[cfg(feature = "log")] - log::trace!($($arg)*); + log::trace!($($arg),*); + #[cfg(not(feature = "log"))] + { + $( + let _ = $arg; + )* + } }; } #[allow(unused_macros)] macro_rules! debug { - ($($arg:tt)*) => { + ($($arg:expr),*) => { #[cfg(feature = "log")] - log::debug!($($arg)*); + log::debug!($($arg),*); + #[cfg(not(feature = "log"))] + { + $( + let _ = $arg; + )* + } }; } macro_rules! info { - ($($arg:tt)*) => { + ($($arg:expr),*) => { #[cfg(feature = "log")] - log::info!($($arg)*); + log::info!($($arg),*); + #[cfg(not(feature = "log"))] + { + $( + let _ = $arg; + )* + } }; } #[allow(unused_macros)] macro_rules! warn { - ($($arg:tt)*) => { + ($($arg:expr),*) => { #[cfg(feature = "log")] - log::warn!($($arg)*); + log::warn!($($arg),*); + #[cfg(not(feature = "log"))] + { + $( + let _ = $arg; + )* + } }; } macro_rules! error { - ($($arg:tt)*) => { + ($($arg:expr),*) => { #[cfg(feature = "log")] - log::error!($($arg)*); + log::error!($($arg),*); + #[cfg(not(feature = "log"))] + { + $( + let _ = $arg; + )* + } }; } diff --git a/src/tokio/io.rs b/src/tokio/io.rs index f854636..b1a6705 100644 --- a/src/tokio/io.rs +++ b/src/tokio/io.rs @@ -160,16 +160,16 @@ where let mut result = Err(e); for (i, duration) in (options.retries_to_attempt_fn)().enumerate() { - let _reconnect_num = i + 1; + let reconnect_num = i + 1; info!( "Will re-perform initial connect attempt #{} in {:?}.", - _reconnect_num, duration + reconnect_num, duration ); sleep(duration).await; - info!("Attempting reconnect #{} now.", _reconnect_num); + info!("Attempting reconnect #{} now.", reconnect_num); match T::establish(ctor_arg.clone()).await { Ok(tcp) => { @@ -236,11 +236,11 @@ where let future_instant = sleep(next_duration); reconnect_status.attempts_tracker.attempt_num += 1; - let _cur_num = reconnect_status.attempts_tracker.attempt_num; + let cur_num = reconnect_status.attempts_tracker.attempt_num; let reconnect_attempt = async move { future_instant.await; - info!("Attempting reconnect #{} now.", _cur_num); + info!("Attempting reconnect #{} now.", cur_num); T::establish(ctor_arg).await }; @@ -256,7 +256,7 @@ where } fn poll_disconnect(mut self: Pin<&mut Self>, cx: &mut Context) { - let (attempt, _attempt_num) = match &mut self.status { + let (attempt, attempt_num) = match &mut self.status { Status::Connected => unreachable!(), Status::Disconnected(ref mut status) => ( Pin::new(&mut status.reconnect_attempt), @@ -273,8 +273,8 @@ where (self.options.on_connect_callback)(); self.underlying_io = underlying_io; } - Poll::Ready(Err(_err)) => { - error!("Connection attempt #{} failed: {:?}", _attempt_num, _err); + Poll::Ready(Err(err)) => { + error!("Connection attempt #{} failed: {:?}", attempt_num, err); self.on_disconnect(cx); } Poll::Pending => {}