From 320f96114c0cd47f5205fc15a840658ad7c47750 Mon Sep 17 00:00:00 2001 From: Erin Power Date: Fri, 22 Mar 2024 11:23:33 +0100 Subject: [PATCH] Update to Rust 1.77.0 --- benches/cluster_map.rs | 2 +- benches/shared.rs | 4 ++-- rust-toolchain.toml | 2 +- src/components/admin.rs | 1 + src/components/agent.rs | 2 ++ src/components/manage.rs | 2 ++ src/components/proxy/packet_router.rs | 2 +- src/components/proxy/sessions.rs | 2 +- src/config.rs | 13 +++++-------- src/config/providers/k8s.rs | 2 +- src/config/slot.rs | 5 +---- src/net.rs | 18 ------------------ src/net/xds/resource.rs | 5 ++--- src/net/xds/server.rs | 2 +- 14 files changed, 21 insertions(+), 41 deletions(-) diff --git a/benches/cluster_map.rs b/benches/cluster_map.rs index d059ac0535..b132d538c8 100644 --- a/benches/cluster_map.rs +++ b/benches/cluster_map.rs @@ -230,7 +230,7 @@ mod serde { resources.push( resource_type .encode_to_any(&Cluster { - locality: cluster.key().clone().map(|l| l.try_into().unwrap()), + locality: cluster.key().clone().map(From::from), endpoints: cluster .endpoints .iter() diff --git a/benches/shared.rs b/benches/shared.rs index ff00ba06af..9760163b95 100644 --- a/benches/shared.rs +++ b/benches/shared.rs @@ -1,8 +1,8 @@ #![allow(dead_code)] pub use std::{ - net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket}, - sync::{atomic, mpsc, Arc}, + net::{Ipv4Addr, SocketAddr, UdpSocket}, + sync::{mpsc, Arc}, }; pub const READ_QUILKIN_PORT: u16 = 9001; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index a3f193cc10..ba103b0383 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -13,5 +13,5 @@ # limitations under the License. [toolchain] -channel = "1.74.0" +channel = "1.77.0" components = ["rustfmt", "clippy"] diff --git a/src/components/admin.rs b/src/components/admin.rs index 512c1385e4..bbb344841a 100644 --- a/src/components/admin.rs +++ b/src/components/admin.rs @@ -237,6 +237,7 @@ mod tests { assert_eq!(response.status(), hyper::StatusCode::OK); } + #[cfg(target_os = "linux")] #[tokio::test] async fn collect_pprof() { // Custom time to make the test fast. diff --git a/src/components/agent.rs b/src/components/agent.rs index 2f05d48dfe..3a8bb831f6 100644 --- a/src/components/agent.rs +++ b/src/components/agent.rs @@ -73,6 +73,8 @@ impl Agent { result = task => { let client = result?; + // The inner fields are unused. + #[allow(dead_code)] enum XdsTask { Delta(crate::net::xds::client::DeltaSubscription), Aggregated(crate::net::xds::client::MdsStream), diff --git a/src/components/manage.rs b/src/components/manage.rs index 864e34f9f2..0a222ca015 100644 --- a/src/components/manage.rs +++ b/src/components/manage.rs @@ -44,6 +44,8 @@ impl Manage { ) .await?; + // The inner fields are unused. + #[allow(dead_code)] enum XdsTask { Delta(crate::net::xds::client::DeltaSubscription), Aggregated(crate::net::xds::client::MdsStream), diff --git a/src/components/proxy/packet_router.rs b/src/components/proxy/packet_router.rs index 164a538866..e48eda20f1 100644 --- a/src/components/proxy/packet_router.rs +++ b/src/components/proxy/packet_router.rs @@ -111,7 +111,7 @@ impl DownstreamReceiveWorkerConfig { let (result, contents) = socket.recv_from(buffer).await; match result { Ok((_size, mut source)) => { - crate::net::to_canonical(&mut source); + source.set_ip(source.ip().to_canonical()); let packet = DownstreamPacket { received_at: crate::unix_timestamp(), asn_info: crate::net::maxmind_db::MaxmindDb::lookup(source.ip()), diff --git a/src/components/proxy/sessions.rs b/src/components/proxy/sessions.rs index 4e819fa344..553d073162 100644 --- a/src/components/proxy/sessions.rs +++ b/src/components/proxy/sessions.rs @@ -205,7 +205,7 @@ impl SessionPool { last_received_at: &mut Option, ) { let received_at = crate::unix_timestamp(); - crate::net::to_canonical(&mut recv_addr); + recv_addr.set_ip(recv_addr.ip().to_canonical()); let (downstream_addr, asn_info): (SocketAddr, Option) = { let storage = self.storage.read().await; let Some(downstream_addr) = storage.destination_to_sources.get(&(recv_addr, port)) diff --git a/src/config.rs b/src/config.rs index 91c9d613db..fb99f51436 100644 --- a/src/config.rs +++ b/src/config.rs @@ -196,20 +196,20 @@ impl Config { if names.is_empty() { for cluster in self.clusters.read().iter() { resources.push(resource_type.encode_to_any( - &crate::net::cluster::proto::Cluster::try_from(( + &crate::net::cluster::proto::Cluster::from(( cluster.key(), &cluster.value().endpoints, - ))?, + )), )?); } } else { for locality in names.iter().filter_map(|name| name.parse().ok()) { if let Some(cluster) = self.clusters.read().get(&Some(locality)) { resources.push(resource_type.encode_to_any( - &crate::net::cluster::proto::Cluster::try_from(( + &crate::net::cluster::proto::Cluster::from(( cluster.key(), &cluster.value().endpoints, - ))?, + )), )?); } } @@ -305,10 +305,7 @@ impl Config { name: key.as_ref().map(|k| k.to_string()).unwrap_or_default(), version: current_version.to_string(), resource: Some(resource_type.encode_to_any( - &crate::net::cluster::proto::Cluster::try_from(( - key, - &value.endpoints, - ))?, + &crate::net::cluster::proto::Cluster::from((key, &value.endpoints)), )?), ..Default::default() }); diff --git a/src/config/providers/k8s.rs b/src/config/providers/k8s.rs index c06d8f3a93..2fd4ade9ce 100644 --- a/src/config/providers/k8s.rs +++ b/src/config/providers/k8s.rs @@ -29,7 +29,7 @@ pub fn update_filters_from_configmap( let configmap = match event { Event::Applied(configmap) => configmap, - Event::Restarted(configmaps) => match configmaps.get(0) { + Event::Restarted(configmaps) => match configmaps.first() { Some(configmap) => configmap.clone(), None => { yield Ok(()); diff --git a/src/config/slot.rs b/src/config/slot.rs index 58ae52263e..1f022197b3 100644 --- a/src/config/slot.rs +++ b/src/config/slot.rs @@ -117,10 +117,7 @@ impl Slot { /// slot. Any changes made will update the value in the slot. pub fn modify(&self, mut modify: impl FnMut(&mut T)) { self.inner.rcu(|value| { - let mut current = value - .as_deref() - .map(|value| T::clone(value)) - .unwrap_or_default(); + let mut current = value.as_deref().cloned().unwrap_or_default(); (modify)(&mut current); Some(Arc::new(current)) }); diff --git a/src/net.rs b/src/net.rs index 948bfa9ff5..1f48faaac7 100644 --- a/src/net.rs +++ b/src/net.rs @@ -429,21 +429,3 @@ mod tests { ); } } - -/// Converts a a socket address to its canonical version. -/// This is just a copy of the method available in std but that is currently -/// nightly only. -pub fn to_canonical(addr: &mut SocketAddr) { - let ip = match addr.ip() { - std::net::IpAddr::V6(ip) => { - if let Some(mapped) = ip.to_ipv4_mapped() { - std::net::IpAddr::V4(mapped) - } else { - std::net::IpAddr::V6(ip) - } - } - addr => addr, - }; - - addr.set_ip(ip); -} diff --git a/src/net/xds/resource.rs b/src/net/xds/resource.rs index e263bbc2ea..88fb7e7a9a 100644 --- a/src/net/xds/resource.rs +++ b/src/net/xds/resource.rs @@ -71,10 +71,9 @@ impl Resource { /// In the relay service, it receives datacenter resources from the agents /// without a host, because hosts don't know their own public IP, but the /// relay does, so we add it to the `Resource`. - pub fn add_host_to_datacenter(&mut self, mut addr: std::net::SocketAddr) { + pub fn add_host_to_datacenter(&mut self, addr: std::net::SocketAddr) { if let Self::Datacenter(dc) = self { - crate::net::to_canonical(&mut addr); - dc.host = addr.ip().to_string(); + dc.host = addr.ip().to_canonical().to_string(); } } diff --git a/src/net/xds/server.rs b/src/net/xds/server.rs index 12d75e7944..df4ffe172d 100644 --- a/src/net/xds/server.rs +++ b/src/net/xds/server.rs @@ -584,7 +584,7 @@ impl AggregatedControlPlaneDiscoveryService for ControlPlane { let mut remote_addr = responses .remote_addr() .ok_or_else(|| tonic::Status::invalid_argument("no remote address available"))?; - crate::net::to_canonical(&mut remote_addr); + remote_addr.set_ip(remote_addr.ip().to_canonical()); let mut responses = responses.into_inner(); let Some(identifier) = responses .next()