From 04431a3794a39db6fea6270fa4dea1376c4a034a Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 18 Nov 2020 14:17:40 -0800 Subject: [PATCH] style: fix some random clippy lints (#749) This commit fixes a few clippy lints, primarily the use of `.clone()` on types which implement `Copy`. I stumbled across this while trying to use clippy to find instances of passing references to `SocketAddr`s instead of copying them, which is inefficient...but it turns out that we don't actually do that anywhere... Signed-off-by: Eliza Weisman --- linkerd/addr/src/lib.rs | 1 - linkerd/app/core/src/control.rs | 2 +- linkerd/app/inbound/src/lib.rs | 2 +- linkerd/app/integration/src/client.rs | 2 +- linkerd/app/integration/src/proxy.rs | 6 ++---- linkerd/app/outbound/src/http/endpoint.rs | 2 +- linkerd/app/profiling/src/bin/profile.rs | 4 ++-- linkerd/dns/name/src/name.rs | 3 ++- linkerd/exp-backoff/src/lib.rs | 2 +- linkerd/proxy/http/src/h2.rs | 2 +- linkerd/proxy/transport/src/listen.rs | 2 +- linkerd/timeout/src/failfast.rs | 2 +- 12 files changed, 14 insertions(+), 16 deletions(-) diff --git a/linkerd/addr/src/lib.rs b/linkerd/addr/src/lib.rs index e1a23819c7..34d3433f9b 100644 --- a/linkerd/addr/src/lib.rs +++ b/linkerd/addr/src/lib.rs @@ -1,6 +1,5 @@ #![deny(warnings, rust_2018_idioms)] -use http; use linkerd2_dns_name::Name; use std::{ fmt, diff --git a/linkerd/app/core/src/control.rs b/linkerd/app/core/src/control.rs index f7f52600ab..592b412245 100644 --- a/linkerd/app/core/src/control.rs +++ b/linkerd/app/core/src/control.rs @@ -61,7 +61,7 @@ impl Config { .push(tls::ConnectLayer::new(identity)) .push_timeout(self.connect.timeout) .push(self::client::layer()) - .push(reconnect::layer(backoff.clone())) + .push(reconnect::layer(backoff)) .push(self::resolve::layer(dns, backoff)) .push_on_response(self::control::balance::layer()) .into_new_service() diff --git a/linkerd/app/inbound/src/lib.rs b/linkerd/app/inbound/src/lib.rs index 30f1f42821..1e46ffd74a 100644 --- a/linkerd/app/inbound/src/lib.rs +++ b/linkerd/app/inbound/src/lib.rs @@ -210,7 +210,7 @@ impl Config { connect.h2_settings, )) .push(reconnect::layer({ - let backoff = connect.backoff.clone(); + let backoff = connect.backoff; move |_| Ok(backoff.stream()) })) .check_new_service::>(); diff --git a/linkerd/app/integration/src/client.rs b/linkerd/app/integration/src/client.rs index c75d01479f..b7917ff2b5 100644 --- a/linkerd/app/integration/src/client.rs +++ b/linkerd/app/integration/src/client.rs @@ -278,7 +278,7 @@ impl tower::Service for Conn { fn call(&mut self, _: hyper::Uri) -> Self::Future { let tls = self.tls.clone(); - let conn = TcpStream::connect(self.addr.clone()); + let conn = TcpStream::connect(self.addr); let abs_form = self.absolute_uris; let running = self .running diff --git a/linkerd/app/integration/src/proxy.rs b/linkerd/app/integration/src/proxy.rs index 15d5866ef6..e2927b50a0 100644 --- a/linkerd/app/integration/src/proxy.rs +++ b/linkerd/app/integration/src/proxy.rs @@ -82,8 +82,7 @@ impl Proxy { } pub fn inbound(mut self, s: server::Listening) -> Self { - let addr = s.addr.clone(); - self.inbound = Some(addr); + self.inbound = Some(s.addr); self.inbound_server = Some(s); self } @@ -107,8 +106,7 @@ impl Proxy { } pub fn outbound(mut self, s: server::Listening) -> Self { - let addr = s.addr.clone(); - self.outbound = Some(addr); + self.outbound = Some(s.addr); self.outbound_server = Some(s); self } diff --git a/linkerd/app/outbound/src/http/endpoint.rs b/linkerd/app/outbound/src/http/endpoint.rs index e026cadc03..3e80b2708e 100644 --- a/linkerd/app/outbound/src/http/endpoint.rs +++ b/linkerd/app/outbound/src/http/endpoint.rs @@ -44,7 +44,7 @@ where .push(http::client::layer(config.h1_settings, config.h2_settings)) // Re-establishes a connection when the client fails. .push(reconnect::layer({ - let backoff = config.backoff.clone(); + let backoff = config.backoff; move |e: Error| { if tcp::connect::is_loop(&*e) { Err(e) diff --git a/linkerd/app/profiling/src/bin/profile.rs b/linkerd/app/profiling/src/bin/profile.rs index 03e08abb14..bbfce42909 100644 --- a/linkerd/app/profiling/src/bin/profile.rs +++ b/linkerd/app/profiling/src/bin/profile.rs @@ -24,8 +24,8 @@ async fn main() { .next() .expect("PROFILING_SUPPORT_SERVER resolved to no addrs!"); - let srv = server::mock_listening(addr.clone()); - let srv2 = server::mock_listening(addr.clone()); + let srv = server::mock_listening(addr); + let srv2 = server::mock_listening(addr); let ctrl = controller::new(); let transparency_tx = ctrl.destination_tx("transparency.test.svc.cluster.local"); diff --git a/linkerd/dns/name/src/name.rs b/linkerd/dns/name/src/name.rs index 2e6c623063..b8cc7d4295 100644 --- a/linkerd/dns/name/src/name.rs +++ b/linkerd/dns/name/src/name.rs @@ -12,7 +12,8 @@ pub struct InvalidName; impl Name { pub fn is_localhost(&self) -> bool { - *self == Name::try_from("localhost.".as_bytes()).unwrap() + use std::str::FromStr; + *self == Name::from_str("localhost.").unwrap() } pub fn without_trailing_dot(&self) -> &str { diff --git a/linkerd/exp-backoff/src/lib.rs b/linkerd/exp-backoff/src/lib.rs index 3c483229dc..3c7849b968 100644 --- a/linkerd/exp-backoff/src/lib.rs +++ b/linkerd/exp-backoff/src/lib.rs @@ -43,7 +43,7 @@ pub struct InvalidBackoff(&'static str); impl ExponentialBackoff { pub fn stream(&self) -> ExponentialBackoffStream { ExponentialBackoffStream { - backoff: self.clone(), + backoff: *self, rng: SmallRng::from_entropy(), iterations: 0, delay: None, diff --git a/linkerd/proxy/http/src/h2.rs b/linkerd/proxy/http/src/h2.rs index 3ef16e2a01..e882e8a2ae 100644 --- a/linkerd/proxy/http/src/h2.rs +++ b/linkerd/proxy/http/src/h2.rs @@ -52,7 +52,7 @@ impl Clone for Connect { fn clone(&self) -> Self { Connect { connect: self.connect.clone(), - h2_settings: self.h2_settings.clone(), + h2_settings: self.h2_settings, _marker: PhantomData, } } diff --git a/linkerd/proxy/transport/src/listen.rs b/linkerd/proxy/transport/src/listen.rs index 456c8746d5..ad42d3dd5a 100644 --- a/linkerd/proxy/transport/src/listen.rs +++ b/linkerd/proxy/transport/src/listen.rs @@ -297,7 +297,7 @@ mod mock { impl OrigDstAddr for MockOrigDstAddr { fn orig_dst_addr(&self, _: &TcpStream) -> Option { - Some(self.0.clone()) + Some(self.0) } } } diff --git a/linkerd/timeout/src/failfast.rs b/linkerd/timeout/src/failfast.rs index f70339b026..1aba3e4bb3 100644 --- a/linkerd/timeout/src/failfast.rs +++ b/linkerd/timeout/src/failfast.rs @@ -71,7 +71,7 @@ where // triggering failfast. Self { inner: self.inner.clone(), - max_unavailable: self.max_unavailable.clone(), + max_unavailable: self.max_unavailable, state: State::Open, } }