Skip to content

Commit

Permalink
apply clippy suggestions for nightly
Browse files Browse the repository at this point in the history
Co-Authored-By: Eloi DEMOLIS <[email protected]>
  • Loading branch information
Keksoj and Wonshtrum committed Mar 1, 2024
1 parent 0c57bd9 commit a9d4c3b
Show file tree
Hide file tree
Showing 22 changed files with 30 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl CommandManager {
}

let query_domain = QueryClusterByDomain {
hostname: splitted.get(0).ok_or(CtlError::NeedClusterDomain)?.clone(),
hostname: splitted.first().ok_or(CtlError::NeedClusterDomain)?.clone(),
path: splitted.get(1).cloned().map(|path| format!("/{path}")), // We add the / again because of the splitn removing it
};

Expand Down
2 changes: 1 addition & 1 deletion bin/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
process::Command,
};

use libc::{self, pid_t};
use libc::pid_t;
use mio::net::UnixStream;
use nix::{
errno::Errno,
Expand Down
1 change: 0 additions & 1 deletion bin/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use nix::{
errno::Errno,
fcntl::{fcntl, FcntlArg, FdFlag},
};
use thiserror;

use sozu_command_lib::config::Config;
use sozu_lib::metrics::{self, MetricError};
Expand Down
3 changes: 1 addition & 2 deletions bin/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ use std::{

#[cfg(target_os = "macos")]
use libc::c_char;
use libc::{self, pid_t};
use libc::pid_t;
#[cfg(target_os = "freebsd")]
use libc::{sysctl, CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, PATH_MAX};
use mio::net::UnixStream;
use nix::{
self,
errno::Errno,
unistd::{fork, ForkResult},
};
Expand Down
1 change: 0 additions & 1 deletion command/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{
cmp::min,
fmt::Debug,
io::{self, ErrorKind, Read, Write},
iter::Iterator,
marker::PhantomData,
os::unix::{
io::{AsRawFd, FromRawFd, IntoRawFd, RawFd},
Expand Down
4 changes: 1 addition & 3 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ use std::{
path::PathBuf,
};

use toml;

use crate::{
certificate::split_certificate_chain,
logging::AccessLogFormat,
Expand Down Expand Up @@ -517,7 +515,7 @@ impl ListenerBuilder {
.ok()
})
.map(split_certificate_chain)
.unwrap_or_else(Vec::new);
.unwrap_or_default();

let (answer_404, answer_503) = self.get_404_503_answers()?;

Expand Down
3 changes: 1 addition & 2 deletions command/src/logging/logs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
cell::RefCell,
cmp::{self, Ord},
cmp,
env,
fmt::Arguments,
fs::{File, OpenOptions},
Expand All @@ -11,7 +11,6 @@ use std::{
str::FromStr,
};

use libc;
use mio::net::UnixDatagram;
use prost::{encoding::encoded_len_varint, Message};
use rand::{distributions::Alphanumeric, thread_rng, Rng};
Expand Down
1 change: 0 additions & 1 deletion command/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use nom::{
self,
bytes::streaming::is_not,
character::complete::char,
combinator::map_res,
Expand Down
2 changes: 1 addition & 1 deletion command/src/response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cmp::Ordering, collections::BTreeMap, default::Default, fmt, net::SocketAddr};
use std::{cmp::Ordering, collections::BTreeMap, fmt, net::SocketAddr};

use crate::{
proto::command::{
Expand Down
2 changes: 1 addition & 1 deletion command/src/scm_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl Listeners {
}
}

fn parse_addresses(addresses: &Vec<String>) -> Result<Vec<SocketAddr>, ScmSocketError> {
fn parse_addresses(addresses: &[String]) -> Result<Vec<SocketAddr>, ScmSocketError> {
let mut parsed_addresses = Vec::new();
for address in addresses {
parsed_addresses.push(address.parse::<SocketAddr>().map_err(|error| {
Expand Down
8 changes: 4 additions & 4 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
fs::File,
hash::{Hash, Hasher},
io::Write,
iter::{repeat, FromIterator},
iter::repeat,
net::SocketAddr,
};

Expand Down Expand Up @@ -382,7 +382,7 @@ impl ConfigState {
let entry = self
.certificates
.entry(add.address.clone().into())
.or_insert_with(HashMap::new);
.or_default();

let mut add = add.clone();
add.certificate
Expand Down Expand Up @@ -464,7 +464,7 @@ impl ConfigState {
let tcp_frontends = self
.tcp_fronts
.entry(front.cluster_id.clone())
.or_insert_with(Vec::new);
.or_default();

let tcp_frontend = TcpFrontend {
cluster_id: front.cluster_id.clone(),
Expand Down Expand Up @@ -514,7 +514,7 @@ impl ConfigState {
let backends = self
.backends
.entry(backend.cluster_id.clone())
.or_insert_with(Vec::new);
.or_default();

// we might be modifying the sticky id or load balancing parameters
backends.retain(|b| b.backend_id != backend.backend_id || b.address != backend.address);
Expand Down
1 change: 0 additions & 1 deletion e2e/src/mock/https_client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{sync::Arc, time::SystemTime};

use hyper::{
self,
client::{connect::dns::GaiResolver, HttpConnector, ResponseFuture},
StatusCode,
};
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/mock/sync_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Backend {
let timeout = Duration::from_millis(100);
let timeout = libc::timeval {
tv_sec: 0,
tv_usec: timeout.subsec_micros().try_into().unwrap(),
tv_usec: timeout.subsec_micros().into(),
};
let listener = unsafe {
let fd = listener.into_raw_fd();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl BackendMap {
pub fn add_backend(&mut self, cluster_id: &str, backend: Backend) {
self.backends
.entry(cluster_id.to_string())
.or_insert_with(BackendList::new)
.or_default()
.add_backend(backend);
}

Expand Down Expand Up @@ -351,7 +351,7 @@ impl BackendMap {
pub fn get_or_create_backend_list_for_cluster(&mut self, cluster_id: &str) -> &mut BackendList {
self.backends
.entry(cluster_id.to_string())
.or_insert_with(BackendList::new)
.or_default()
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl HttpProxy {
}

pub fn get_listener(&self, token: &Token) -> Option<Rc<RefCell<HttpListener>>> {
self.listeners.get(token).map(Clone::clone)
self.listeners.get(token).cloned()
}

pub fn remove_listener(&mut self, remove: RemoveListener) -> Result<(), ProxyError> {
Expand Down Expand Up @@ -869,7 +869,7 @@ impl ProxyConfiguration for HttpProxy {
let listener = self
.listeners
.get(&Token(listener_token.0))
.map(Clone::clone)
.cloned()
.ok_or(AcceptError::IoError)?;

if let Err(e) = frontend_sock.set_nodelay(true) {
Expand Down
23 changes: 11 additions & 12 deletions lib/src/metrics/local_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ enum MetricMeta {
pub struct LocalClusterMetrics {
/// metric_name -> metric value
cluster: BTreeMap<String, AggregatedMetric>,
///
backends: Vec<LocalBackendMetrics>,
}

impl LocalClusterMetrics {
fn to_filtered_metrics(
&self,
metric_names: &Vec<String>,
metric_names: &[String],
) -> Result<ClusterMetrics, MetricError> {
let cluster = self
.cluster
Expand Down Expand Up @@ -182,7 +181,7 @@ pub struct LocalBackendMetrics {
impl LocalBackendMetrics {
fn to_filtered_metrics(
&self,
metric_names: &Vec<String>,
metric_names: &[String],
) -> Result<BackendMetrics, MetricError> {
let filtered_backend_metrics = self
.metrics
Expand Down Expand Up @@ -306,7 +305,7 @@ impl LocalDrain {

pub fn dump_all_metrics(
&mut self,
metric_names: &Vec<String>,
metric_names: &[String],
) -> Result<WorkerMetrics, MetricError> {
Ok(WorkerMetrics {
proxy: self.dump_proxy_metrics(metric_names),
Expand All @@ -316,7 +315,7 @@ impl LocalDrain {

pub fn dump_proxy_metrics(
&mut self,
metric_names: &Vec<String>,
metric_names: &[String],
) -> BTreeMap<String, FilteredMetrics> {
self.proxy_metrics
.iter()
Expand All @@ -333,7 +332,7 @@ impl LocalDrain {

pub fn dump_cluster_metrics(
&mut self,
metric_names: &Vec<String>,
metric_names: &[String],
) -> Result<BTreeMap<String, ClusterMetrics>, MetricError> {
let mut cluster_data = BTreeMap::new();

Expand All @@ -348,7 +347,7 @@ impl LocalDrain {
fn metrics_of_one_cluster(
&self,
cluster_id: &str,
metric_names: &Vec<String>,
metric_names: &[String],
) -> Result<ClusterMetrics, MetricError> {
let aggregated = self
.cluster_metrics
Expand All @@ -363,7 +362,7 @@ impl LocalDrain {
fn metrics_of_one_backend(
&self,
backend_id: &str,
metric_names: &Vec<String>,
metric_names: &[String],
) -> Result<BackendMetrics, MetricError> {
for cluster_metrics in self.cluster_metrics.values() {
if let Some(backend_metrics) = cluster_metrics
Expand All @@ -383,8 +382,8 @@ impl LocalDrain {

fn query_clusters(
&mut self,
cluster_ids: &Vec<String>,
metric_names: &Vec<String>,
cluster_ids: &[String],
metric_names: &[String],
) -> Result<WorkerMetrics, MetricError> {
debug!("Querying cluster with ids: {:?}", cluster_ids);
let mut clusters: BTreeMap<String, ClusterMetrics> = BTreeMap::new();
Expand All @@ -405,8 +404,8 @@ impl LocalDrain {

fn query_backends(
&mut self,
backend_ids: &Vec<String>,
metric_names: &Vec<String>,
backend_ids: &[String],
metric_names: &[String],
) -> Result<WorkerMetrics, MetricError> {
let mut clusters: BTreeMap<String, ClusterMetrics> = BTreeMap::new();

Expand Down
2 changes: 0 additions & 2 deletions lib/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use std::{
sync::atomic::{AtomicUsize, Ordering},
};

use poule;

static BUFFER_COUNT: AtomicUsize = AtomicUsize::new(0);

pub struct Pool {
Expand Down
5 changes: 1 addition & 4 deletions lib/src/protocol/proxy_protocol/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
convert::From,
net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6},
};
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6};

use nom::{
bytes::streaming::{tag, take},
Expand Down
2 changes: 1 addition & 1 deletion lib/src/retry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cmp, fmt::Debug, time};

use rand::{self, Rng};
use rand::Rng;

#[derive(Debug, PartialEq, Eq)]
pub enum RetryAction {
Expand Down
1 change: 0 additions & 1 deletion lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::{
cell::RefCell,
collections::{HashSet, VecDeque},
convert::TryFrom,
io::Error as IoError,
os::unix::io::{AsRawFd, FromRawFd},
rc::Rc,
Expand Down
1 change: 0 additions & 1 deletion lib/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::server::TIMER;

// Conversion utilities
mod convert {
use std::convert::TryFrom;
use time::Duration;

/// Convert a `Duration` to milliseconds, rounding up and saturating at
Expand Down
4 changes: 1 addition & 3 deletions lib/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
//! [`CertifiedKey` format](https://docs.rs/rustls/latest/rustls/sign/struct.CertifiedKey.html),
//! exposes them to the HTTPS listener for TLS handshakes.
use std::{
borrow::ToOwned,
collections::{HashMap, HashSet},
convert::From,
fmt,
io::BufReader,
str::FromStr,
Expand Down Expand Up @@ -184,7 +182,7 @@ impl CertificateResolver {

self.name_fingerprint_idx
.entry(new_name.to_owned())
.or_insert_with(HashSet::new)
.or_default()
.insert(cert_to_add.fingerprint.to_owned());
}

Expand Down

0 comments on commit a9d4c3b

Please sign in to comment.