Skip to content

Fix some clippy lints #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/client/legacy/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ where
// it returns an error, there's not much else to retry
.map_err(TrySendError::Nope)?;

req.extensions_mut()
.get_mut::<CaptureConnectionExtension>()
.map(|conn| conn.set(&pooled.conn_info));
if let Some(conn) = req.extensions_mut().get_mut::<CaptureConnectionExtension>() {
conn.set(&pooled.conn_info);
}

if pooled.is_http1() {
if req.version() == Version::HTTP_2 {
Expand All @@ -301,7 +301,7 @@ where
req.headers_mut().entry(HOST).or_insert_with(|| {
let hostname = uri.host().expect("authority implies host");
if let Some(port) = get_non_default_port(&uri) {
let s = format!("{}:{}", hostname, port);
let s = format!("{hostname}:{port}");
HeaderValue::from_str(&s)
} else {
HeaderValue::from_str(hostname)
Expand Down
42 changes: 18 additions & 24 deletions src/client/legacy/connect/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,18 @@ mod test {
"connection has not been set"
);
tx.set(&Connected::new().proxy(true));
assert_eq!(
rx.connection_metadata()
.as_ref()
.expect("connected should be set")
.is_proxied(),
true
);
assert!(rx
.connection_metadata()
.as_ref()
.expect("connected should be set")
.is_proxied());

// ensure it can be called multiple times
assert_eq!(
rx.connection_metadata()
.as_ref()
.expect("connected should be set")
.is_proxied(),
true
);
assert!(rx
.connection_metadata()
.as_ref()
.expect("connected should be set")
.is_proxied());
}

#[tokio::test]
Expand All @@ -157,24 +153,22 @@ mod test {
"connection has not been set"
);
let test_task = tokio::spawn(async move {
assert_eq!(
rx.wait_for_connection_metadata()
.await
.as_ref()
.expect("connection should be set")
.is_proxied(),
true
);
assert!(rx
.wait_for_connection_metadata()
.await
.as_ref()
.expect("connection should be set")
.is_proxied());
// can be awaited multiple times
assert!(
rx.wait_for_connection_metadata().await.is_some(),
"should be awaitable multiple times"
);

assert_eq!(rx.connection_metadata().is_some(), true);
assert!(rx.connection_metadata().is_some());
});
// can't be finished, we haven't set the connection yet
assert_eq!(test_task.is_finished(), false);
assert!(!test_task.is_finished());
tx.set(&Connected::new().proxy(true));

assert!(test_task.await.is_ok());
Expand Down
2 changes: 1 addition & 1 deletion src/client/legacy/connect/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Future for GaiFuture {
if join_err.is_cancelled() {
Err(io::Error::new(io::ErrorKind::Interrupted, join_err))
} else {
panic!("gai background task failed: {:?}", join_err)
panic!("gai background task failed: {join_err:?}")
}
}
})
Expand Down
36 changes: 21 additions & 15 deletions src/client/legacy/connect/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ impl fmt::Display for ConnectError {
f.write_str(&self.msg)?;

if let Some(ref cause) = self.cause {
write!(f, ": {}", cause)?;
write!(f, ": {cause}")?;
}

Ok(())
Expand Down Expand Up @@ -1100,7 +1100,7 @@ mod tests {
let (bind_ip_v4, bind_ip_v6) = get_local_ips();
let server4 = TcpListener::bind("127.0.0.1:0").unwrap();
let port = server4.local_addr().unwrap().port();
let server6 = TcpListener::bind(&format!("[::1]:{}", port)).unwrap();
let server6 = TcpListener::bind(format!("[::1]:{port}")).unwrap();

let assert_client_ip = |dst: String, server: TcpListener, expected_ip: IpAddr| async move {
let mut connector = HttpConnector::new();
Expand All @@ -1120,11 +1120,11 @@ mod tests {
};

if let Some(ip) = bind_ip_v4 {
assert_client_ip(format!("http://127.0.0.1:{}", port), server4, ip.into()).await;
assert_client_ip(format!("http://127.0.0.1:{port}"), server4, ip.into()).await;
}

if let Some(ip) = bind_ip_v6 {
assert_client_ip(format!("http://[::1]:{}", port), server6, ip.into()).await;
assert_client_ip(format!("http://[::1]:{port}"), server6, ip.into()).await;
}
}

Expand All @@ -1141,7 +1141,7 @@ mod tests {
let server4 = TcpListener::bind("127.0.0.1:0").unwrap();
let port = server4.local_addr().unwrap().port();

let server6 = TcpListener::bind(&format!("[::1]:{}", port)).unwrap();
let server6 = TcpListener::bind(format!("[::1]:{port}")).unwrap();

let assert_interface_name =
|dst: String,
Expand All @@ -1164,14 +1164,14 @@ mod tests {
};

assert_interface_name(
format!("http://127.0.0.1:{}", port),
format!("http://127.0.0.1:{port}"),
server4,
interface.clone(),
interface.clone(),
)
.await;
assert_interface_name(
format!("http://[::1]:{}", port),
format!("http://[::1]:{port}"),
server6,
interface.clone(),
interface.clone(),
Expand All @@ -1191,7 +1191,7 @@ mod tests {

let server4 = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = server4.local_addr().unwrap();
let _server6 = TcpListener::bind(&format!("[::1]:{}", addr.port())).unwrap();
let _server6 = TcpListener::bind(format!("[::1]:{}", addr.port())).unwrap();
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
Expand Down Expand Up @@ -1295,7 +1295,7 @@ mod tests {
.block_on(async move {
let addrs = hosts
.iter()
.map(|host| (host.clone(), addr.port()).into())
.map(|host| (*host, addr.port()).into())
.collect();
let cfg = Config {
local_address_ipv4: None,
Expand Down Expand Up @@ -1402,8 +1402,10 @@ mod tests {

#[test]
fn tcp_keepalive_time_config() {
let mut kac = TcpKeepaliveConfig::default();
kac.time = Some(Duration::from_secs(60));
let kac = TcpKeepaliveConfig {
time: Some(Duration::from_secs(60)),
..Default::default()
};
if let Some(tcp_keepalive) = kac.into_tcpkeepalive() {
assert!(format!("{tcp_keepalive:?}").contains("time: Some(60s)"));
} else {
Expand All @@ -1414,8 +1416,10 @@ mod tests {
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "solaris")))]
#[test]
fn tcp_keepalive_interval_config() {
let mut kac = TcpKeepaliveConfig::default();
kac.interval = Some(Duration::from_secs(1));
let kac = TcpKeepaliveConfig {
interval: Some(Duration::from_secs(1)),
..Default::default()
};
if let Some(tcp_keepalive) = kac.into_tcpkeepalive() {
assert!(format!("{tcp_keepalive:?}").contains("interval: Some(1s)"));
} else {
Expand All @@ -1431,8 +1435,10 @@ mod tests {
)))]
#[test]
fn tcp_keepalive_retries_config() {
let mut kac = TcpKeepaliveConfig::default();
kac.retries = Some(3);
let kac = TcpKeepaliveConfig {
retries: Some(3),
..Default::default()
};
if let Some(tcp_keepalive) = kac.into_tcpkeepalive() {
assert!(format!("{tcp_keepalive:?}").contains("retries: Some(3)"));
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/client/legacy/connect/proxy/socks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where
match M::try_from(buf) {
Err(ParsingError::Incomplete) => {
if n == 0 {
if buf.spare_capacity_mut().len() == 0 {
if buf.spare_capacity_mut().is_empty() {
return Err(SocksError::Parsing(ParsingError::WouldOverflow));
} else {
return Err(std::io::Error::new(
Expand Down
2 changes: 1 addition & 1 deletion src/client/legacy/connect/proxy/socks/v4/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl TryFrom<&mut BytesMut> for Response {
SocketAddrV4::new(ip.into(), port)
};

return Ok(Self(status));
Ok(Self(status))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/legacy/connect/proxy/socks/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl SocksConfig {
{
let address = match host.parse::<IpAddr>() {
Ok(IpAddr::V6(_)) => return Err(SocksV4Error::IpV6.into()),
Ok(IpAddr::V4(ip)) => Address::Socket(SocketAddrV4::new(ip.into(), port)),
Ok(IpAddr::V4(ip)) => Address::Socket(SocketAddrV4::new(ip, port)),
Err(_) => {
if self.local_dns {
(host, port)
Expand Down
10 changes: 4 additions & 6 deletions src/client/legacy/connect/proxy/socks/v5/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,16 @@ impl SocksConfig {
} else {
state = State::ReadingProxyRes;
}
} else if res.0 == AuthMethod::UserPass {
state = State::SendingAuthReq;
} else {
if res.0 == AuthMethod::UserPass {
state = State::SendingAuthReq;
} else {
state = State::SendingProxyReq;
}
state = State::SendingProxyReq;
}
}

State::SendingAuthReq => {
let (user, pass) = self.proxy_auth.as_ref().unwrap();
let req = AuthenticationReq(&user, &pass);
let req = AuthenticationReq(user, pass);

let start = send_buf.len();
req.write_to_buf(&mut send_buf)?;
Expand Down
10 changes: 5 additions & 5 deletions src/client/legacy/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ mod tests {
}

fn pool_no_timer<T, K: Key>() -> Pool<T, K> {
pool_max_idle_no_timer(::std::usize::MAX)
pool_max_idle_no_timer(usize::MAX)
}

fn pool_max_idle_no_timer<T, K: Key>(max_idle: usize) -> Pool<T, K> {
Expand Down Expand Up @@ -959,7 +959,7 @@ mod tests {
let poll_once = PollOnce(&mut checkout);
// checkout.await should clean out the expired
poll_once.await;
assert!(pool.locked().idle.get(&key).is_none());
assert!(!pool.locked().idle.contains_key(&key));
}

#[test]
Expand All @@ -983,7 +983,7 @@ mod tests {
let pool = Pool::new(
super::Config {
idle_timeout: Some(Duration::from_millis(10)),
max_idle_per_host: std::usize::MAX,
max_idle_per_host: usize::MAX,
},
TokioExecutor::new(),
Some(TokioTimer::new()),
Expand All @@ -1005,7 +1005,7 @@ mod tests {
// Yield so the Interval can reap...
tokio::task::yield_now().await;

assert!(pool.locked().idle.get(&key).is_none());
assert!(!pool.locked().idle.contains_key(&key));
}

#[tokio::test]
Expand Down Expand Up @@ -1052,7 +1052,7 @@ mod tests {
assert_eq!(pool.locked().waiters.get(&key).unwrap().len(), 1);

drop(checkout2);
assert!(pool.locked().waiters.get(&key).is_none());
assert!(!pool.locked().waiters.contains_key(&key));
}

#[derive(Debug)]
Expand Down
14 changes: 7 additions & 7 deletions src/client/proxy/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ impl Builder {
/// The rules are as follows:
/// * Entries are expected to be comma-separated (whitespace between entries is ignored)
/// * IP addresses (both IPv4 and IPv6) are allowed, as are optional subnet masks (by adding /size,
/// for example "`192.168.1.0/24`").
/// for example "`192.168.1.0/24`").
/// * An entry "`*`" matches all hostnames (this is the only wildcard allowed)
/// * Any other entry is considered a domain name (and may contain a leading dot, for example `google.com`
/// and `.google.com` are equivalent) and would match both that domain AND all subdomains.
/// and `.google.com` are equivalent) and would match both that domain AND all subdomains.
///
/// For example, if `"NO_PROXY=google.com, 192.168.1.0/24"` was set, all of the following would match
/// (and therefore would bypass the proxy):
Expand Down Expand Up @@ -422,10 +422,10 @@ impl NoProxy {
/// * If neither environment variable is set, `None` is returned
/// * Entries are expected to be comma-separated (whitespace between entries is ignored)
/// * IP addresses (both IPv4 and IPv6) are allowed, as are optional subnet masks (by adding /size,
/// for example "`192.168.1.0/24`").
/// for example "`192.168.1.0/24`").
/// * An entry "`*`" matches all hostnames (this is the only wildcard allowed)
/// * Any other entry is considered a domain name (and may contain a leading dot, for example `google.com`
/// and `.google.com` are equivalent) and would match both that domain AND all subdomains.
/// and `.google.com` are equivalent) and would match both that domain AND all subdomains.
///
/// For example, if `"NO_PROXY=google.com, 192.168.1.0/24"` was set, all of the following would match
/// (and therefore would bypass the proxy):
Expand Down Expand Up @@ -729,7 +729,7 @@ mod tests {
];

for host in &should_not_match {
assert!(!no_proxy.contains(host), "should not contain {:?}", host);
assert!(!no_proxy.contains(host), "should not contain {host:?}");
}

let should_match = [
Expand All @@ -752,7 +752,7 @@ mod tests {
];

for host in &should_match {
assert!(no_proxy.contains(host), "should contain {:?}", host);
assert!(no_proxy.contains(host), "should contain {host:?}");
}
}

Expand All @@ -763,7 +763,7 @@ mod tests {
}.build()});
}

fn intercept<'a>(p: &'a Matcher, u: &str) -> Intercept {
fn intercept(p: &Matcher, u: &str) -> Intercept {
p.intercept(&u.parse().unwrap()).unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion src/service/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where
let this = self.as_mut().project();
match this {
OneshotProj::NotReady { svc, req } => {
let _ = ready!(svc.poll_ready(cx))?;
ready!(svc.poll_ready(cx))?;
let fut = svc.call(req.take().expect("already called"));
self.set(Oneshot::Called { fut });
}
Expand Down
Loading