From 869ff2c6226dc6431f3a01679f1934c3f3ffa44a Mon Sep 17 00:00:00 2001 From: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com> Date: Thu, 13 May 2021 05:29:36 +0200 Subject: [PATCH] Clippy fixes (#246) Co-authored-by: Mark Mandel --- src/extensions/filter_manager.rs | 6 +++--- src/extensions/filter_registry.rs | 6 +++--- .../filters/local_rate_limit/mod.rs | 21 ++++++++++++------- src/proxy/server/mod.rs | 10 ++------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/extensions/filter_manager.rs b/src/extensions/filter_manager.rs index 4eb1a1330b..9edd136945 100644 --- a/src/extensions/filter_manager.rs +++ b/src/extensions/filter_manager.rs @@ -34,8 +34,8 @@ pub struct FilterManager { /// ListenerManagerArgs contains arguments when invoking the LDS resource manager. pub(crate) struct ListenerManagerArgs { - pub filter_registry: Arc, pub filter_chain_updates_tx: mpsc::Sender>, + pub filter_registry: Arc, pub metrics_registry: Registry, } @@ -46,9 +46,9 @@ impl ListenerManagerArgs { filter_chain_updates_tx: mpsc::Sender>, ) -> ListenerManagerArgs { ListenerManagerArgs { - metrics_registry, - filter_registry, filter_chain_updates_tx, + filter_registry, + metrics_registry, } } } diff --git a/src/extensions/filter_registry.rs b/src/extensions/filter_registry.rs index 68b13ecf57..9b0e3872f8 100644 --- a/src/extensions/filter_registry.rs +++ b/src/extensions/filter_registry.rs @@ -237,9 +237,9 @@ impl fmt::Display for Error { } } -impl Into for Error { - fn into(self) -> ValidationError { - ValidationError::FilterInvalid(self) +impl From for ValidationError { + fn from(error: Error) -> Self { + Self::FilterInvalid(error) } } diff --git a/src/extensions/filters/local_rate_limit/mod.rs b/src/extensions/filters/local_rate_limit/mod.rs index e2b3225881..8ada54b777 100644 --- a/src/extensions/filters/local_rate_limit/mod.rs +++ b/src/extensions/filters/local_rate_limit/mod.rs @@ -135,10 +135,12 @@ impl RateLimitFilter { while !refilled { let remaining_tokens = available_tokens.load(Ordering::Relaxed); - refilled = available_tokens.compare_and_swap( + refilled = available_tokens.compare_exchange( remaining_tokens, max_tokens, - Ordering::Relaxed) == remaining_tokens; + Ordering::Relaxed, + Ordering::Relaxed, + ).unwrap_or_else(|b| b) == remaining_tokens; } }, _ = &mut shutdown_rx => { @@ -166,11 +168,16 @@ impl RateLimitFilter { return None; } - if self.available_tokens.compare_and_swap( - remaining_tokens, - remaining_tokens - 1, - Ordering::Relaxed, - ) == remaining_tokens + if self + .available_tokens + .compare_exchange( + remaining_tokens, + remaining_tokens - 1, + Ordering::Relaxed, + Ordering::Relaxed, + ) + .unwrap_or_else(|b| b) + == remaining_tokens { return Some(()); } diff --git a/src/proxy/server/mod.rs b/src/proxy/server/mod.rs index d1263a9b9f..70f00c9bd1 100644 --- a/src/proxy/server/mod.rs +++ b/src/proxy/server/mod.rs @@ -611,14 +611,8 @@ mod tests { // since we don't know what the session ephemeral port is, we'll just // search for the filter strings. let result = endpoint.packet_rx.await.unwrap(); - assert!( - result.contains(msg), - format!("'{}' not found in '{}'", msg, result) - ); - assert!( - result.contains(":odr:"), - format!(":odr: not found in '{}'", result) - ); + assert!(result.contains(msg), "'{}' not found in '{}'", msg, result); + assert!(result.contains(":odr:"), ":odr: not found in '{}'", result); } #[tokio::test]