Skip to content

Commit 3a971c9

Browse files
authored
Fix some clippy lints (#196)
1 parent 2b2c352 commit 3a971c9

File tree

13 files changed

+91
-102
lines changed

13 files changed

+91
-102
lines changed

src/client/legacy/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ where
284284
// it returns an error, there's not much else to retry
285285
.map_err(TrySendError::Nope)?;
286286

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

291291
if pooled.is_http1() {
292292
if req.version() == Version::HTTP_2 {
@@ -301,7 +301,7 @@ where
301301
req.headers_mut().entry(HOST).or_insert_with(|| {
302302
let hostname = uri.host().expect("authority implies host");
303303
if let Some(port) = get_non_default_port(&uri) {
304-
let s = format!("{}:{}", hostname, port);
304+
let s = format!("{hostname}:{port}");
305305
HeaderValue::from_str(&s)
306306
} else {
307307
HeaderValue::from_str(hostname)

src/client/legacy/connect/capture.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,18 @@ mod test {
131131
"connection has not been set"
132132
);
133133
tx.set(&Connected::new().proxy(true));
134-
assert_eq!(
135-
rx.connection_metadata()
136-
.as_ref()
137-
.expect("connected should be set")
138-
.is_proxied(),
139-
true
140-
);
134+
assert!(rx
135+
.connection_metadata()
136+
.as_ref()
137+
.expect("connected should be set")
138+
.is_proxied());
141139

142140
// ensure it can be called multiple times
143-
assert_eq!(
144-
rx.connection_metadata()
145-
.as_ref()
146-
.expect("connected should be set")
147-
.is_proxied(),
148-
true
149-
);
141+
assert!(rx
142+
.connection_metadata()
143+
.as_ref()
144+
.expect("connected should be set")
145+
.is_proxied());
150146
}
151147

152148
#[tokio::test]
@@ -157,24 +153,22 @@ mod test {
157153
"connection has not been set"
158154
);
159155
let test_task = tokio::spawn(async move {
160-
assert_eq!(
161-
rx.wait_for_connection_metadata()
162-
.await
163-
.as_ref()
164-
.expect("connection should be set")
165-
.is_proxied(),
166-
true
167-
);
156+
assert!(rx
157+
.wait_for_connection_metadata()
158+
.await
159+
.as_ref()
160+
.expect("connection should be set")
161+
.is_proxied());
168162
// can be awaited multiple times
169163
assert!(
170164
rx.wait_for_connection_metadata().await.is_some(),
171165
"should be awaitable multiple times"
172166
);
173167

174-
assert_eq!(rx.connection_metadata().is_some(), true);
168+
assert!(rx.connection_metadata().is_some());
175169
});
176170
// can't be finished, we haven't set the connection yet
177-
assert_eq!(test_task.is_finished(), false);
171+
assert!(!test_task.is_finished());
178172
tx.set(&Connected::new().proxy(true));
179173

180174
assert!(test_task.await.is_ok());

src/client/legacy/connect/dns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl Future for GaiFuture {
143143
if join_err.is_cancelled() {
144144
Err(io::Error::new(io::ErrorKind::Interrupted, join_err))
145145
} else {
146-
panic!("gai background task failed: {:?}", join_err)
146+
panic!("gai background task failed: {join_err:?}")
147147
}
148148
}
149149
})

src/client/legacy/connect/http.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ impl fmt::Display for ConnectError {
692692
f.write_str(&self.msg)?;
693693

694694
if let Some(ref cause) = self.cause {
695-
write!(f, ": {}", cause)?;
695+
write!(f, ": {cause}")?;
696696
}
697697

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

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

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

11261126
if let Some(ip) = bind_ip_v6 {
1127-
assert_client_ip(format!("http://[::1]:{}", port), server6, ip.into()).await;
1127+
assert_client_ip(format!("http://[::1]:{port}"), server6, ip.into()).await;
11281128
}
11291129
}
11301130

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

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

11461146
let assert_interface_name =
11471147
|dst: String,
@@ -1164,14 +1164,14 @@ mod tests {
11641164
};
11651165

11661166
assert_interface_name(
1167-
format!("http://127.0.0.1:{}", port),
1167+
format!("http://127.0.0.1:{port}"),
11681168
server4,
11691169
interface.clone(),
11701170
interface.clone(),
11711171
)
11721172
.await;
11731173
assert_interface_name(
1174-
format!("http://[::1]:{}", port),
1174+
format!("http://[::1]:{port}"),
11751175
server6,
11761176
interface.clone(),
11771177
interface.clone(),
@@ -1191,7 +1191,7 @@ mod tests {
11911191

11921192
let server4 = TcpListener::bind("127.0.0.1:0").unwrap();
11931193
let addr = server4.local_addr().unwrap();
1194-
let _server6 = TcpListener::bind(&format!("[::1]:{}", addr.port())).unwrap();
1194+
let _server6 = TcpListener::bind(format!("[::1]:{}", addr.port())).unwrap();
11951195
let rt = tokio::runtime::Builder::new_current_thread()
11961196
.enable_all()
11971197
.build()
@@ -1295,7 +1295,7 @@ mod tests {
12951295
.block_on(async move {
12961296
let addrs = hosts
12971297
.iter()
1298-
.map(|host| (host.clone(), addr.port()).into())
1298+
.map(|host| (*host, addr.port()).into())
12991299
.collect();
13001300
let cfg = Config {
13011301
local_address_ipv4: None,
@@ -1402,8 +1402,10 @@ mod tests {
14021402

14031403
#[test]
14041404
fn tcp_keepalive_time_config() {
1405-
let mut kac = TcpKeepaliveConfig::default();
1406-
kac.time = Some(Duration::from_secs(60));
1405+
let kac = TcpKeepaliveConfig {
1406+
time: Some(Duration::from_secs(60)),
1407+
..Default::default()
1408+
};
14071409
if let Some(tcp_keepalive) = kac.into_tcpkeepalive() {
14081410
assert!(format!("{tcp_keepalive:?}").contains("time: Some(60s)"));
14091411
} else {
@@ -1414,8 +1416,10 @@ mod tests {
14141416
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "solaris")))]
14151417
#[test]
14161418
fn tcp_keepalive_interval_config() {
1417-
let mut kac = TcpKeepaliveConfig::default();
1418-
kac.interval = Some(Duration::from_secs(1));
1419+
let kac = TcpKeepaliveConfig {
1420+
interval: Some(Duration::from_secs(1)),
1421+
..Default::default()
1422+
};
14191423
if let Some(tcp_keepalive) = kac.into_tcpkeepalive() {
14201424
assert!(format!("{tcp_keepalive:?}").contains("interval: Some(1s)"));
14211425
} else {
@@ -1431,8 +1435,10 @@ mod tests {
14311435
)))]
14321436
#[test]
14331437
fn tcp_keepalive_retries_config() {
1434-
let mut kac = TcpKeepaliveConfig::default();
1435-
kac.retries = Some(3);
1438+
let kac = TcpKeepaliveConfig {
1439+
retries: Some(3),
1440+
..Default::default()
1441+
};
14361442
if let Some(tcp_keepalive) = kac.into_tcpkeepalive() {
14371443
assert!(format!("{tcp_keepalive:?}").contains("retries: Some(3)"));
14381444
} else {

src/client/legacy/connect/proxy/socks/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ where
5050
match M::try_from(buf) {
5151
Err(ParsingError::Incomplete) => {
5252
if n == 0 {
53-
if buf.spare_capacity_mut().len() == 0 {
53+
if buf.spare_capacity_mut().is_empty() {
5454
return Err(SocksError::Parsing(ParsingError::WouldOverflow));
5555
} else {
5656
return Err(std::io::Error::new(

src/client/legacy/connect/proxy/socks/v4/messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl TryFrom<&mut BytesMut> for Response {
101101
SocketAddrV4::new(ip.into(), port)
102102
};
103103

104-
return Ok(Self(status));
104+
Ok(Self(status))
105105
}
106106
}
107107

src/client/legacy/connect/proxy/socks/v4/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl SocksConfig {
9797
{
9898
let address = match host.parse::<IpAddr>() {
9999
Ok(IpAddr::V6(_)) => return Err(SocksV4Error::IpV6.into()),
100-
Ok(IpAddr::V4(ip)) => Address::Socket(SocketAddrV4::new(ip.into(), port)),
100+
Ok(IpAddr::V4(ip)) => Address::Socket(SocketAddrV4::new(ip, port)),
101101
Err(_) => {
102102
if self.local_dns {
103103
(host, port)

src/client/legacy/connect/proxy/socks/v5/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,16 @@ impl SocksConfig {
199199
} else {
200200
state = State::ReadingProxyRes;
201201
}
202+
} else if res.0 == AuthMethod::UserPass {
203+
state = State::SendingAuthReq;
202204
} else {
203-
if res.0 == AuthMethod::UserPass {
204-
state = State::SendingAuthReq;
205-
} else {
206-
state = State::SendingProxyReq;
207-
}
205+
state = State::SendingProxyReq;
208206
}
209207
}
210208

211209
State::SendingAuthReq => {
212210
let (user, pass) = self.proxy_auth.as_ref().unwrap();
213-
let req = AuthenticationReq(&user, &pass);
211+
let req = AuthenticationReq(user, pass);
214212

215213
let start = send_buf.len();
216214
req.write_to_buf(&mut send_buf)?;

src/client/legacy/pool.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ mod tests {
878878
}
879879

880880
fn pool_no_timer<T, K: Key>() -> Pool<T, K> {
881-
pool_max_idle_no_timer(::std::usize::MAX)
881+
pool_max_idle_no_timer(usize::MAX)
882882
}
883883

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

965965
#[test]
@@ -983,7 +983,7 @@ mod tests {
983983
let pool = Pool::new(
984984
super::Config {
985985
idle_timeout: Some(Duration::from_millis(10)),
986-
max_idle_per_host: std::usize::MAX,
986+
max_idle_per_host: usize::MAX,
987987
},
988988
TokioExecutor::new(),
989989
Some(TokioTimer::new()),
@@ -1005,7 +1005,7 @@ mod tests {
10051005
// Yield so the Interval can reap...
10061006
tokio::task::yield_now().await;
10071007

1008-
assert!(pool.locked().idle.get(&key).is_none());
1008+
assert!(!pool.locked().idle.contains_key(&key));
10091009
}
10101010

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

10541054
drop(checkout2);
1055-
assert!(pool.locked().waiters.get(&key).is_none());
1055+
assert!(!pool.locked().waiters.contains_key(&key));
10561056
}
10571057

10581058
#[derive(Debug)]

src/client/proxy/matcher.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,10 @@ impl Builder {
280280
/// The rules are as follows:
281281
/// * Entries are expected to be comma-separated (whitespace between entries is ignored)
282282
/// * IP addresses (both IPv4 and IPv6) are allowed, as are optional subnet masks (by adding /size,
283-
/// for example "`192.168.1.0/24`").
283+
/// for example "`192.168.1.0/24`").
284284
/// * An entry "`*`" matches all hostnames (this is the only wildcard allowed)
285285
/// * Any other entry is considered a domain name (and may contain a leading dot, for example `google.com`
286-
/// and `.google.com` are equivalent) and would match both that domain AND all subdomains.
286+
/// and `.google.com` are equivalent) and would match both that domain AND all subdomains.
287287
///
288288
/// For example, if `"NO_PROXY=google.com, 192.168.1.0/24"` was set, all of the following would match
289289
/// (and therefore would bypass the proxy):
@@ -422,10 +422,10 @@ impl NoProxy {
422422
/// * If neither environment variable is set, `None` is returned
423423
/// * Entries are expected to be comma-separated (whitespace between entries is ignored)
424424
/// * IP addresses (both IPv4 and IPv6) are allowed, as are optional subnet masks (by adding /size,
425-
/// for example "`192.168.1.0/24`").
425+
/// for example "`192.168.1.0/24`").
426426
/// * An entry "`*`" matches all hostnames (this is the only wildcard allowed)
427427
/// * Any other entry is considered a domain name (and may contain a leading dot, for example `google.com`
428-
/// and `.google.com` are equivalent) and would match both that domain AND all subdomains.
428+
/// and `.google.com` are equivalent) and would match both that domain AND all subdomains.
429429
///
430430
/// For example, if `"NO_PROXY=google.com, 192.168.1.0/24"` was set, all of the following would match
431431
/// (and therefore would bypass the proxy):
@@ -729,7 +729,7 @@ mod tests {
729729
];
730730

731731
for host in &should_not_match {
732-
assert!(!no_proxy.contains(host), "should not contain {:?}", host);
732+
assert!(!no_proxy.contains(host), "should not contain {host:?}");
733733
}
734734

735735
let should_match = [
@@ -752,7 +752,7 @@ mod tests {
752752
];
753753

754754
for host in &should_match {
755-
assert!(no_proxy.contains(host), "should contain {:?}", host);
755+
assert!(no_proxy.contains(host), "should contain {host:?}");
756756
}
757757
}
758758

@@ -763,7 +763,7 @@ mod tests {
763763
}.build()});
764764
}
765765

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

src/service/oneshot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ where
4747
let this = self.as_mut().project();
4848
match this {
4949
OneshotProj::NotReady { svc, req } => {
50-
let _ = ready!(svc.poll_ready(cx))?;
50+
ready!(svc.poll_ready(cx))?;
5151
let fut = svc.call(req.take().expect("already called"));
5252
self.set(Oneshot::Called { fut });
5353
}

0 commit comments

Comments
 (0)