Skip to content

Commit 9b7e2bd

Browse files
authored
Apply clippy to all targets, including tests (#779)
There are some lints that are obfuscated by macros, so the integration tests have some blanket allows.
1 parent 3fc1cb0 commit 9b7e2bd

File tree

16 files changed

+42
-48
lines changed

16 files changed

+42
-48
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fmt:
9090

9191
.PHONY: lint
9292
lint:
93-
$(CARGO_CLIPPY)
93+
$(CARGO_CLIPPY) --all-targets
9494

9595

9696
.PHONY: shellcheck

hyper-balance/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ mod tests {
438438
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
439439
let mut this = self.as_mut();
440440
assert!(this.0.is_empty());
441-
Poll::Ready(Ok(this.1.take().into()))
441+
Poll::Ready(Ok(this.1.take()))
442442
}
443443
}
444444

linkerd/app/integration/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#![deny(warnings, rust_2018_idioms)]
44
#![recursion_limit = "256"]
55
#![type_length_limit = "16289823"]
6+
// It's not clear where this originates.
7+
#![allow(clippy::eval_order_dependence)]
68

79
mod test_env;
810

linkerd/app/integration/src/tests/discovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ macro_rules! generate_tests {
182182

183183
let srv = $make_server().route("/", "hello").run().await;
184184

185-
const NAME: &'static str = "unresolvable.svc.cluster.local";
185+
const NAME: &str = "unresolvable.svc.cluster.local";
186186
let ctrl = controller::new();
187187
let profile = ctrl.profile_tx(&srv.addr.to_string());
188188
profile.send_err(grpc::Status::new(

linkerd/app/integration/src/tests/identity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ async fn refresh() {
234234

235235
tokio::time::sleep(how_long).await;
236236

237-
assert_eventually!(refreshed.load(Ordering::SeqCst) == true);
237+
assert_eventually!(refreshed.load(Ordering::SeqCst));
238238
}
239239

240240
mod require_id_header {

linkerd/app/integration/src/tests/shutdown.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ async fn tcp_waits_for_proxies_to_close() {
113113
assert_eq!(&vec[..n], msg1.as_bytes());
114114
sock.write_all(msg2.as_bytes()).await
115115
}
116-
.map(|res| match res {
117-
Err(e) => panic!("tcp server error: {}", e),
118-
Ok(_) => {}
119-
})
116+
.map(|res| res.expect("TCP server must not error"))
120117
})
121118
.run()
122119
.await;

linkerd/app/integration/src/tests/telemetry.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ mod response_classification {
191191
use crate::*;
192192
use tracing::info;
193193

194-
const REQ_STATUS_HEADER: &'static str = "x-test-status-requested";
195-
const REQ_GRPC_STATUS_HEADER: &'static str = "x-test-grpc-status-requested";
194+
const REQ_STATUS_HEADER: &str = "x-test-status-requested";
195+
const REQ_GRPC_STATUS_HEADER: &str = "x-test-grpc-status-requested";
196196

197197
const STATUSES: [http::StatusCode; 6] = [
198198
http::StatusCode::OK,
@@ -1000,7 +1000,7 @@ mod transport {
10001000
}
10011001

10021002
#[tokio::test]
1003-
#[cfg(macos)]
1003+
#[cfg(target_os = "macos")]
10041004
async fn inbound_tcp_connect_err() {
10051005
let _trace = trace_init();
10061006
let srv = tcp::server()
@@ -1031,7 +1031,7 @@ mod transport {
10311031
}
10321032

10331033
#[test]
1034-
#[cfg(macos)]
1034+
#[cfg(target_os = "macos")]
10351035
fn outbound_tcp_connect_err() {
10361036
let _trace = trace_init();
10371037
let srv = tcp::server()
@@ -1498,10 +1498,9 @@ async fn metrics_compression() {
14981498
body.copy_to_bytes(body.remaining()),
14991499
));
15001500
let mut scrape = String::new();
1501-
decoder.read_to_string(&mut scrape).expect(&format!(
1502-
"decode gzip (requested Accept-Encoding: {})",
1503-
encoding
1504-
));
1501+
decoder.read_to_string(&mut scrape).unwrap_or_else(|_| {
1502+
panic!("decode gzip (requested Accept-Encoding: {})", encoding)
1503+
});
15051504
scrape
15061505
}
15071506
};

linkerd/app/integration/src/tests/transparency.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// It's not clear where this originates.
2+
#![allow(clippy::redundant_closure_call)]
3+
14
use crate::*;
25
use std::error::Error as _;
36
use tokio::sync::mpsc;
@@ -212,12 +215,9 @@ async fn test_server_speaks_first(env: TestEnv) {
212215
let n = sock.read(&mut vec).await?;
213216
assert_eq!(s(&vec[..n]), msg2);
214217
tx.send(()).await.unwrap();
215-
Ok(())
218+
Ok::<(), io::Error>(())
216219
}
217-
.map(|res: std::io::Result<()>| match res {
218-
Err(e) => panic!("tcp server error: {}", e),
219-
Ok(()) => {}
220-
})
220+
.map(|res| res.expect("TCP server must not fail"))
221221
})
222222
.run()
223223
.await;
@@ -313,12 +313,9 @@ async fn tcp_connections_close_if_client_closes() {
313313
assert_eq!(n, 0);
314314
panic!("lol");
315315
tx.send(()).await.unwrap();
316-
Ok(())
316+
Ok::<(), io::Error>(())
317317
}
318-
.map(|res: std::io::Result<()>| match res {
319-
Err(e) => panic!("tcp server error: {}", e),
320-
Ok(()) => {}
321-
})
318+
.map(|res| res.expect("TCP server must not fail"))
322319
})
323320
.run()
324321
.await;
@@ -519,10 +516,7 @@ macro_rules! http1_tests {
519516
// Some processing... and then write back in chatproto...
520517
sock.write_all(chatproto_res.as_bytes()).await
521518
}
522-
.map(|res: std::io::Result<()>| match res {
523-
Ok(()) => {}
524-
Err(e) => panic!("tcp server error: {}", e),
525-
})
519+
.map(|res| res.expect("TCP server must not fail"))
526520
})
527521
.run()
528522
.await;

linkerd/app/src/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,12 +1081,12 @@ mod tests {
10811081

10821082
#[test]
10831083
fn parse_duration_unit_ms() {
1084-
test_unit("ms", |v| Duration::from_millis(v));
1084+
test_unit("ms", Duration::from_millis);
10851085
}
10861086

10871087
#[test]
10881088
fn parse_duration_unit_s() {
1089-
test_unit("s", |v| Duration::from_secs(v));
1089+
test_unit("s", Duration::from_secs);
10901090
}
10911091

10921092
#[test]

linkerd/dns/name/src/name.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl AsRef<str> for Name {
7676
#[cfg(test)]
7777
mod tests {
7878
use super::*;
79+
use std::str::FromStr;
7980

8081
#[test]
8182
fn test_is_localhost() {
@@ -102,16 +103,16 @@ mod tests {
102103
("web.svc.local.", "web.svc.local"),
103104
];
104105
for (host, expected_result) in cases {
105-
let dns_name =
106-
Name::try_from(host.as_bytes()).expect(&format!("'{}' was invalid", host));
106+
let dns_name = Name::try_from(host.as_bytes())
107+
.unwrap_or_else(|_| panic!("'{}' was invalid", host));
107108
assert_eq!(
108109
dns_name.without_trailing_dot(),
109110
*expected_result,
110111
"{:?}",
111112
dns_name
112113
)
113114
}
114-
assert!(Name::try_from(".".as_bytes()).is_err());
115-
assert!(Name::try_from("".as_bytes()).is_err());
115+
assert!(Name::from_str(".").is_err());
116+
assert!(Name::from_str("").is_err());
116117
}
117118
}

0 commit comments

Comments
 (0)