From b2002b16c5995130adc98917202e45063af1aaca Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Tue, 19 Mar 2024 15:32:26 +0000 Subject: [PATCH] Fix Clippy warnings on nightly Our nightly build is failing due to some dead code warnings that aren't being triggered on stable. This change runs `cargo +nightly clippy --fix` and then manually fixes the remaining issues. --- hyper-balance/src/lib.rs | 2 +- linkerd/app/admin/src/server.rs | 2 +- linkerd/app/gateway/src/http/tests.rs | 4 +--- linkerd/app/inbound/src/accept.rs | 1 - linkerd/app/inbound/src/detect/tests.rs | 4 ++-- linkerd/app/inbound/src/policy/http/tests.rs | 1 - linkerd/app/inbound/src/policy/tcp/tests.rs | 7 ++----- linkerd/app/integration/src/tests/identity.rs | 3 +-- linkerd/app/integration/src/tests/profiles.rs | 2 +- .../app/integration/src/tests/transparency.rs | 1 - linkerd/app/outbound/src/discover/tests.rs | 2 -- .../src/http/handle_proxy_error_headers.rs | 3 +-- linkerd/app/outbound/src/http/logical/tests.rs | 4 ++-- linkerd/app/outbound/src/ingress.rs | 2 +- linkerd/app/outbound/src/opaq/logical/tests.rs | 5 ++--- linkerd/app/outbound/src/tcp/tagged_transport.rs | 4 +--- linkerd/app/src/identity.rs | 16 +--------------- linkerd/http-retry/src/replay.rs | 4 ++-- linkerd/idle-cache/src/lib.rs | 4 ++-- linkerd/meshtls/rustls/src/server.rs | 4 ++-- linkerd/meshtls/tests/util.rs | 3 +-- linkerd/proxy/api-resolve/src/pb.rs | 1 - linkerd/proxy/http/src/classify/channel.rs | 5 +---- linkerd/proxy/spire-client/src/lib.rs | 3 +-- linkerd/proxy/tap/src/grpc/match_.rs | 1 - linkerd/stack/src/failfast/test.rs | 1 - linkerd/stack/src/lazy.rs | 1 - linkerd/stack/src/watch.rs | 1 - 28 files changed, 26 insertions(+), 65 deletions(-) diff --git a/hyper-balance/src/lib.rs b/hyper-balance/src/lib.rs index be44363d7e..4531212e32 100644 --- a/hyper-balance/src/lib.rs +++ b/hyper-balance/src/lib.rs @@ -418,7 +418,7 @@ mod tests { assert!(wk.upgrade().is_none()); } - struct Handle(Arc<()>); + struct Handle(#[allow(dead_code)] Arc<()>); impl Handle { fn new() -> (Self, Weak<()>) { let strong = Arc::new(()); diff --git a/linkerd/app/admin/src/server.rs b/linkerd/app/admin/src/server.rs index eb1c0cfddc..9a01667d7d 100644 --- a/linkerd/app/admin/src/server.rs +++ b/linkerd/app/admin/src/server.rs @@ -294,7 +294,7 @@ mod tests { use super::*; use http::method::Method; use std::time::Duration; - use tokio::{sync::mpsc, time::timeout}; + use tokio::{time::timeout}; use tower::util::ServiceExt; const TIMEOUT: Duration = Duration::from_secs(1); diff --git a/linkerd/app/gateway/src/http/tests.rs b/linkerd/app/gateway/src/http/tests.rs index 6759958860..4a553ed537 100644 --- a/linkerd/app/gateway/src/http/tests.rs +++ b/linkerd/app/gateway/src/http/tests.rs @@ -1,10 +1,8 @@ use super::*; use linkerd_app_core::{ - proxy::http, svc::{NewService, ServiceExt}, - tls, trace::test::trace_init, - Error, NameAddr, + NameAddr, }; use linkerd_app_inbound::GatewayLoop; use linkerd_proxy_server_policy as policy; diff --git a/linkerd/app/inbound/src/accept.rs b/linkerd/app/inbound/src/accept.rs index 3091afc9d4..3b26154a42 100644 --- a/linkerd/app/inbound/src/accept.rs +++ b/linkerd/app/inbound/src/accept.rs @@ -115,7 +115,6 @@ mod tests { use futures::future; use linkerd_app_core::{ svc::{NewService, ServiceExt}, - Error, }; use linkerd_proxy_server_policy::{Authentication, Authorization, Meta, ServerPolicy}; use std::sync::Arc; diff --git a/linkerd/app/inbound/src/detect/tests.rs b/linkerd/app/inbound/src/detect/tests.rs index d7f0150264..ac8973e277 100644 --- a/linkerd/app/inbound/src/detect/tests.rs +++ b/linkerd/app/inbound/src/detect/tests.rs @@ -4,9 +4,9 @@ use futures::future; use linkerd_app_core::{ io::AsyncWriteExt, svc::{NewService, ServiceExt}, - trace, Error, + trace }; -use linkerd_proxy_server_policy::{Authentication, Authorization, Meta, Protocol, ServerPolicy}; +use linkerd_proxy_server_policy::{Authentication, Authorization, Meta, ServerPolicy}; use std::sync::Arc; const HTTP1: &[u8] = b"GET / HTTP/1.1\r\nhost: example.com\r\n\r\n"; diff --git a/linkerd/app/inbound/src/policy/http/tests.rs b/linkerd/app/inbound/src/policy/http/tests.rs index 31497333f0..0369207938 100644 --- a/linkerd/app/inbound/src/policy/http/tests.rs +++ b/linkerd/app/inbound/src/policy/http/tests.rs @@ -1,7 +1,6 @@ use super::*; use crate::policy::{Authentication, Authorization, Meta, Protocol, ServerPolicy}; use linkerd_app_core::{svc::Service, Infallible}; -use std::sync::Arc; macro_rules! conn { ($client:expr, $dst:expr) => {{ diff --git a/linkerd/app/inbound/src/policy/tcp/tests.rs b/linkerd/app/inbound/src/policy/tcp/tests.rs index 74d805b8fc..d8635316b3 100644 --- a/linkerd/app/inbound/src/policy/tcp/tests.rs +++ b/linkerd/app/inbound/src/policy/tcp/tests.rs @@ -1,10 +1,7 @@ use super::*; use crate::policy::*; -use linkerd_app_core::{proxy::http, Error}; -use linkerd_proxy_server_policy::{ - authz::Suffix, Authentication, Authorization, Protocol, ServerPolicy, -}; -use std::{collections::BTreeSet, sync::Arc}; +use linkerd_app_core::{proxy::http}; +use std::{collections::BTreeSet}; #[derive(Clone)] pub(crate) struct MockSvc; diff --git a/linkerd/app/integration/src/tests/identity.rs b/linkerd/app/integration/src/tests/identity.rs index eef8939278..38ccfe7fc8 100644 --- a/linkerd/app/integration/src/tests/identity.rs +++ b/linkerd/app/integration/src/tests/identity.rs @@ -2,9 +2,8 @@ use crate::*; use std::{ sync::{ atomic::{AtomicBool, Ordering}, - Arc, }, - time::{Duration, SystemTime}, + time::{SystemTime}, }; #[tokio::test] diff --git a/linkerd/app/integration/src/tests/profiles.rs b/linkerd/app/integration/src/tests/profiles.rs index 2501b76bef..8505bc1a60 100644 --- a/linkerd/app/integration/src/tests/profiles.rs +++ b/linkerd/app/integration/src/tests/profiles.rs @@ -588,7 +588,7 @@ mod http2 { mod grpc_retry { use super::*; - use http::header::{HeaderMap, HeaderName, HeaderValue}; + use http::header::{HeaderName, HeaderValue}; static GRPC_STATUS: HeaderName = HeaderName::from_static("grpc-status"); static GRPC_STATUS_OK: HeaderValue = HeaderValue::from_static("0"); static GRPC_STATUS_UNAVAILABLE: HeaderValue = HeaderValue::from_static("14"); diff --git a/linkerd/app/integration/src/tests/transparency.rs b/linkerd/app/integration/src/tests/transparency.rs index 6a79a3a2a4..d72f8446c6 100644 --- a/linkerd/app/integration/src/tests/transparency.rs +++ b/linkerd/app/integration/src/tests/transparency.rs @@ -1,6 +1,5 @@ use crate::*; use std::error::Error as _; -use tokio::sync::mpsc; use tokio::time::timeout; #[tokio::test] diff --git a/linkerd/app/outbound/src/discover/tests.rs b/linkerd/app/outbound/src/discover/tests.rs index 25ca6b6900..525922669d 100644 --- a/linkerd/app/outbound/src/discover/tests.rs +++ b/linkerd/app/outbound/src/discover/tests.rs @@ -3,10 +3,8 @@ use crate::test_util::*; use linkerd_app_core::{ io, svc::{NewService, Service, ServiceExt}, - transport::addrs::OrigDstAddr, }; use std::{ - net::SocketAddr, sync::{ atomic::{AtomicUsize, Ordering}, Arc, diff --git a/linkerd/app/outbound/src/http/handle_proxy_error_headers.rs b/linkerd/app/outbound/src/http/handle_proxy_error_headers.rs index 7d85460d3e..4fb6aca237 100644 --- a/linkerd/app/outbound/src/http/handle_proxy_error_headers.rs +++ b/linkerd/app/outbound/src/http/handle_proxy_error_headers.rs @@ -157,9 +157,8 @@ fn update_response(rsp: &mut http::Response, closable: bool) -> bool { #[cfg(test)] mod test { use super::*; - use futures::future; use linkerd_app_core::{ - svc::{self, ServiceExt}, + svc::{ServiceExt}, Infallible, }; use linkerd_tracing::test; diff --git a/linkerd/app/outbound/src/http/logical/tests.rs b/linkerd/app/outbound/src/http/logical/tests.rs index da71eab457..52a6025168 100644 --- a/linkerd/app/outbound/src/http/logical/tests.rs +++ b/linkerd/app/outbound/src/http/logical/tests.rs @@ -2,12 +2,12 @@ use super::*; use crate::test_util::*; use ::http::StatusCode; use linkerd_app_core::{ - errors, exp_backoff::ExponentialBackoff, svc::NewService, svc::ServiceExt, trace, Error, + errors, exp_backoff::ExponentialBackoff, svc::NewService, svc::ServiceExt, trace, }; use linkerd_proxy_client_policy as client_policy; use parking_lot::Mutex; use std::{collections::HashMap, net::SocketAddr, sync::Arc, time::Duration}; -use tokio::{sync::watch, task, time}; +use tokio::{task, time}; use tracing::Instrument; const AUTHORITY: &str = "logical.test.svc.cluster.local"; diff --git a/linkerd/app/outbound/src/ingress.rs b/linkerd/app/outbound/src/ingress.rs index 60ea463cf0..b01c4d8236 100644 --- a/linkerd/app/outbound/src/ingress.rs +++ b/linkerd/app/outbound/src/ingress.rs @@ -658,7 +658,7 @@ impl From for Addr { #[cfg(test)] mod tests { use super::*; - use svc::{NewService, ServiceExt}; + use svc::{NewService}; use tokio::{io::AsyncReadExt, io::AsyncWriteExt, time}; use tower_test::mock; diff --git a/linkerd/app/outbound/src/opaq/logical/tests.rs b/linkerd/app/outbound/src/opaq/logical/tests.rs index 7d419dd3ee..4b9bf8e09c 100644 --- a/linkerd/app/outbound/src/opaq/logical/tests.rs +++ b/linkerd/app/outbound/src/opaq/logical/tests.rs @@ -3,9 +3,8 @@ use crate::test_util::*; use io::AsyncWriteExt; use linkerd_app_core::{ errors::{self, FailFastError}, - io::{self, AsyncReadExt}, - profiles::{self, Profile}, - svc::{self, NewService, ServiceExt}, + io::{AsyncReadExt}, + svc::{NewService, ServiceExt}, }; use std::net::SocketAddr; use tokio::time; diff --git a/linkerd/app/outbound/src/tcp/tagged_transport.rs b/linkerd/app/outbound/src/tcp/tagged_transport.rs index 0c4baf41ef..911effb7e7 100644 --- a/linkerd/app/outbound/src/tcp/tagged_transport.rs +++ b/linkerd/app/outbound/src/tcp/tagged_transport.rs @@ -139,12 +139,10 @@ where #[cfg(test)] mod test { use super::*; - use futures::future; use linkerd_app_core::{ io::{self, AsyncWriteExt}, - tls, transport::{ClientAddr, Local}, - transport_header::{self, TransportHeader}, + transport_header, }; use tower::util::{service_fn, ServiceExt}; diff --git a/linkerd/app/src/identity.rs b/linkerd/app/src/identity.rs index 6bab7dd0cd..b9b7df6a7c 100644 --- a/linkerd/app/src/identity.rs +++ b/linkerd/app/src/identity.rs @@ -3,12 +3,11 @@ use crate::spire; pub use linkerd_app_core::identity::{client, Id}; use linkerd_app_core::{ control, dns, - exp_backoff::{ExponentialBackoff, ExponentialBackoffStream}, identity::{ client::linkerd::Certify, creds, CertMetrics, Credentials, DerX509, Mode, WithCertMetrics, }, metrics::{prom, ControlHttp as ClientMetrics}, - Error, Result, + Result, }; use std::{future::Future, pin::Pin, time::SystemTime}; use tokio::sync::watch; @@ -47,9 +46,6 @@ pub struct Identity { pub type Task = Pin + Send + 'static>>; -#[derive(Clone, Debug)] -struct Recover(ExponentialBackoff); - /// Wraps a credential with a watch sender that notifies receivers when the store has been updated /// at least once. struct NotifyReady { @@ -177,13 +173,3 @@ impl Identity { self.task } } - -// === impl Recover === - -impl> linkerd_error::Recover for Recover { - type Backoff = ExponentialBackoffStream; - - fn recover(&self, _: E) -> Result { - Ok(self.0.stream()) - } -} diff --git a/linkerd/http-retry/src/replay.rs b/linkerd/http-retry/src/replay.rs index 73168fe85c..aa2804b0da 100644 --- a/linkerd/http-retry/src/replay.rs +++ b/linkerd/http-retry/src/replay.rs @@ -275,7 +275,7 @@ where if !rest.is_end_stream() { let res = futures::ready!(Pin::new(rest).poll_trailers(cx)).map(|tlrs| { if state.trailers.is_none() { - state.trailers = tlrs.clone(); + state.trailers.clone_from(&tlrs); } tlrs }); @@ -503,7 +503,7 @@ impl BodyState { #[cfg(test)] mod tests { use super::*; - use http::{HeaderMap, HeaderValue}; + use http::{HeaderValue}; #[tokio::test] async fn replays_one_chunk() { diff --git a/linkerd/idle-cache/src/lib.rs b/linkerd/idle-cache/src/lib.rs index 65f9ccc8e9..70def1950f 100644 --- a/linkerd/idle-cache/src/lib.rs +++ b/linkerd/idle-cache/src/lib.rs @@ -116,10 +116,10 @@ where Self { inner, idle } } - pub fn get(&self, key: &Q) -> Option> + pub fn get(&self, key: &Q) -> Option> where K: Borrow, - Q: Hash + Eq + fmt::Debug, + Q: Hash + Eq + fmt::Debug + ?Sized, V: Clone, { let cache = self.inner.read(); diff --git a/linkerd/meshtls/rustls/src/server.rs b/linkerd/meshtls/rustls/src/server.rs index 6bde857856..cac87589f7 100644 --- a/linkerd/meshtls/rustls/src/server.rs +++ b/linkerd/meshtls/rustls/src/server.rs @@ -50,7 +50,7 @@ impl Server { let mut orig_rx = self.rx; let mut c = (**orig_rx.borrow_and_update()).clone(); - c.alpn_protocols = alpn_protocols.clone(); + c.alpn_protocols.clone_from(&alpn_protocols); let (tx, rx) = watch::channel(c.into()); // Spawn a background task that watches the optional server configuration and publishes it @@ -74,7 +74,7 @@ impl Server { } let mut c = (*orig_rx.borrow().clone()).clone(); - c.alpn_protocols = alpn_protocols.clone(); + c.alpn_protocols.clone_from(&alpn_protocols); let _ = tx.send(c.into()); } }); diff --git a/linkerd/meshtls/tests/util.rs b/linkerd/meshtls/tests/util.rs index 65fbecf4a0..c294ecfecc 100644 --- a/linkerd/meshtls/tests/util.rs +++ b/linkerd/meshtls/tests/util.rs @@ -11,7 +11,7 @@ use linkerd_meshtls as meshtls; use linkerd_proxy_transport::{ addrs::*, listen::{Addrs, Bind, BindTcp}, - ConnectTcp, Keepalive, ListenAddr, + ConnectTcp, Keepalive, }; use linkerd_stack::{ layer::Layer, service_fn, ExtractParam, InsertParam, NewService, Param, ServiceExt, @@ -21,7 +21,6 @@ use linkerd_tls_test_util as test_util; use rcgen::{BasicConstraints, Certificate, CertificateParams, IsCa, SanType}; use std::str::FromStr; use std::{ - future::Future, net::SocketAddr, sync::mpsc, time::{Duration, SystemTime}, diff --git a/linkerd/proxy/api-resolve/src/pb.rs b/linkerd/proxy/api-resolve/src/pb.rs index 023f29be80..b90418e1c1 100644 --- a/linkerd/proxy/api-resolve/src/pb.rs +++ b/linkerd/proxy/api-resolve/src/pb.rs @@ -148,7 +148,6 @@ pub(crate) fn to_sock_addr(pb: TcpAddress) -> Option { #[cfg(test)] mod tests { use super::*; - use crate::api::destination::TlsIdentity; use linkerd2_proxy_api::destination::tls_identity::{ DnsLikeIdentity, Strategy, UriLikeIdentity, }; diff --git a/linkerd/proxy/http/src/classify/channel.rs b/linkerd/proxy/http/src/classify/channel.rs index d881cf11a6..d30a5655d8 100644 --- a/linkerd/proxy/http/src/classify/channel.rs +++ b/linkerd/proxy/http/src/classify/channel.rs @@ -278,11 +278,8 @@ impl PinnedDrop for ResponseBody { #[cfg(test)] mod tests { use super::*; - use crate::classify::ClassifyResponse; - use linkerd_error::Error; use linkerd_http_box::BoxBody; - use linkerd_http_classify::ClassifyEos; - use tokio::{sync::mpsc, time}; + use tokio::{ time}; use tokio_test::assert_ready; use tower_test::mock; diff --git a/linkerd/proxy/spire-client/src/lib.rs b/linkerd/proxy/spire-client/src/lib.rs index 4987209147..841fbfffbf 100644 --- a/linkerd/proxy/spire-client/src/lib.rs +++ b/linkerd/proxy/spire-client/src/lib.rs @@ -61,10 +61,9 @@ mod tests { use super::*; use crate::api::Svid; use linkerd_error::Result; - use linkerd_identity::{Credentials, DerX509, Id}; + use linkerd_identity::{DerX509}; use rcgen::{Certificate, CertificateParams, SanType, SerialNumber}; use std::time::SystemTime; - use tokio::sync::watch; fn gen_svid(id: Id, subject_alt_names: Vec, serial: SerialNumber) -> Svid { let mut params = CertificateParams::default(); diff --git a/linkerd/proxy/tap/src/grpc/match_.rs b/linkerd/proxy/tap/src/grpc/match_.rs index e1fb8fc32a..3f5f50492f 100644 --- a/linkerd/proxy/tap/src/grpc/match_.rs +++ b/linkerd/proxy/tap/src/grpc/match_.rs @@ -312,7 +312,6 @@ impl TryFrom for HttpMatch { #[cfg(test)] mod tests { use super::*; - use ipnet::{Ipv4Net, Ipv6Net}; use linkerd2_proxy_api::http_types; use quickcheck::*; use std::collections::HashMap; diff --git a/linkerd/stack/src/failfast/test.rs b/linkerd/stack/src/failfast/test.rs index 7ff84bdc9c..3e8ebf300d 100644 --- a/linkerd/stack/src/failfast/test.rs +++ b/linkerd/stack/src/failfast/test.rs @@ -1,5 +1,4 @@ use super::*; -use std::time::Duration; use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok, task}; use tower_test::mock::{self, Spawn}; diff --git a/linkerd/stack/src/lazy.rs b/linkerd/stack/src/lazy.rs index c34a0b9421..4d7d572f15 100644 --- a/linkerd/stack/src/lazy.rs +++ b/linkerd/stack/src/lazy.rs @@ -104,7 +104,6 @@ impl Clone for Lazy { mod tests { use super::*; use crate::layer::Layer; - use std::sync::Arc; use tokio_test::{assert_pending, assert_ready_ok}; use tower::ServiceExt; use tower_test::mock; diff --git a/linkerd/stack/src/watch.rs b/linkerd/stack/src/watch.rs index e85350cbbb..c6e3f58135 100644 --- a/linkerd/stack/src/watch.rs +++ b/linkerd/stack/src/watch.rs @@ -140,7 +140,6 @@ where #[cfg(test)] mod tests { use super::*; - use crate::NewService; use tokio::sync::watch; use tower::ServiceExt; use tower_test::mock;