Skip to content

Commit 4ea0be0

Browse files
committed
refactor(clippy): reduce clippy warnings
1 parent 12717d1 commit 4ea0be0

24 files changed

+113
-124
lines changed

benches/end_to_end.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn http1_parallel_x10_req_10kb_100_chunks(b: &mut test::Bencher) {
8282
#[bench]
8383
#[ignore]
8484
fn http1_parallel_x10_res_1mb(b: &mut test::Bencher) {
85-
let body = &[b'x'; 1024 * 1024 * 1];
85+
let body = &[b'x'; 1024 * 1024];
8686
opts().parallel(10).response_body(body).bench(b)
8787
}
8888

@@ -177,7 +177,7 @@ fn http2_parallel_x10_req_10kb_100_chunks_max_window(b: &mut test::Bencher) {
177177

178178
#[bench]
179179
fn http2_parallel_x10_res_1mb(b: &mut test::Bencher) {
180-
let body = &[b'x'; 1024 * 1024 * 1];
180+
let body = &[b'x'; 1024 * 1024];
181181
opts()
182182
.http2()
183183
.parallel(10)

benches/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn raw_tcp_throughput_small_payload(b: &mut test::Bencher) {
152152

153153
let mut buf = [0u8; 8192];
154154
while rx.try_recv().is_err() {
155-
sock.read(&mut buf).unwrap();
155+
sock.read_exact(&mut buf).unwrap();
156156
sock.write_all(
157157
b"\
158158
HTTP/1.1 200 OK\r\n\

benches/support/tokiort.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Timer for TokioTimer {
4444

4545
fn reset(&self, sleep: &mut Pin<Box<dyn Sleep>>, new_deadline: Instant) {
4646
if let Some(sleep) = sleep.as_mut().downcast_mut_pin::<TokioSleep>() {
47-
sleep.reset(new_deadline.into())
47+
sleep.reset(new_deadline)
4848
}
4949
}
5050
}

examples/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> {
7171
while let Some(next) = res.frame().await {
7272
let frame = next?;
7373
if let Some(chunk) = frame.data_ref() {
74-
io::stdout().write_all(&chunk).await?;
74+
io::stdout().write_all(chunk).await?;
7575
}
7676
}
7777

examples/gateway.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1515
let in_addr: SocketAddr = ([127, 0, 0, 1], 3001).into();
1616
let out_addr: SocketAddr = ([127, 0, 0, 1], 3000).into();
1717

18-
let out_addr_clone = out_addr.clone();
18+
let out_addr_clone = out_addr;
1919

2020
let listener = TcpListener::bind(in_addr).await?;
2121

examples/http_proxy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async fn proxy(
111111
}
112112

113113
fn host_addr(uri: &http::Uri) -> Option<String> {
114-
uri.authority().and_then(|auth| Some(auth.to_string()))
114+
uri.authority().map(|auth| auth.to_string())
115115
}
116116

117117
fn empty() -> BoxBody<Bytes, hyper::Error> {

examples/single_threaded.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ async fn http1_client(url: hyper::Uri) -> Result<(), Box<dyn std::error::Error>>
207207
while let Some(next) = res.frame().await {
208208
let frame = next?;
209209
if let Some(chunk) = frame.data_ref() {
210-
stdout.write_all(&chunk).await.unwrap();
210+
stdout.write_all(chunk).await.unwrap();
211211
}
212212
}
213213
stdout.write_all(b"\n-----------------\n").await.unwrap();
@@ -308,7 +308,7 @@ async fn http2_client(url: hyper::Uri) -> Result<(), Box<dyn std::error::Error>>
308308
while let Some(next) = res.frame().await {
309309
let frame = next?;
310310
if let Some(chunk) = frame.data_ref() {
311-
stdout.write_all(&chunk).await.unwrap();
311+
stdout.write_all(chunk).await.unwrap();
312312
}
313313
}
314314
stdout.write_all(b"\n-----------------\n").await.unwrap();

examples/upgrades.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ async fn main() {
169169
res = &mut conn => {
170170
if let Err(err) = res {
171171
println!("Error serving connection: {:?}", err);
172-
return;
173172
}
174173
}
175174
// Continue polling the connection after enabling graceful shutdown.
@@ -187,7 +186,7 @@ async fn main() {
187186
});
188187

189188
// Client requests a HTTP connection upgrade.
190-
let request = client_upgrade_request(addr.clone());
189+
let request = client_upgrade_request(addr);
191190
if let Err(e) = request.await {
192191
eprintln!("client error: {}", e);
193192
}

examples/web_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async fn main() -> Result<()> {
117117
let io = TokioIo::new(stream);
118118

119119
tokio::task::spawn(async move {
120-
let service = service_fn(move |req| response_examples(req));
120+
let service = service_fn(response_examples);
121121

122122
if let Err(err) = http1::Builder::new().serve_connection(io, service).await {
123123
println!("Failed to serve connection: {:?}", err);

src/client/conn/http1.rs

+6
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ where
302302

303303
// ===== impl Builder
304304

305+
impl Default for Builder {
306+
fn default() -> Builder {
307+
Builder::new()
308+
}
309+
}
310+
305311
impl Builder {
306312
/// Creates a new connection builder.
307313
#[inline]

src/ext/h1_reason_phrase.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -174,26 +174,26 @@ mod tests {
174174

175175
#[test]
176176
fn basic_valid() {
177-
const PHRASE: &'static [u8] = b"OK";
177+
const PHRASE: &[u8] = b"OK";
178178
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
179179
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
180180
}
181181

182182
#[test]
183183
fn empty_valid() {
184-
const PHRASE: &'static [u8] = b"";
184+
const PHRASE: &[u8] = b"";
185185
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
186186
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
187187
}
188188

189189
#[test]
190190
fn obs_text_valid() {
191-
const PHRASE: &'static [u8] = b"hyp\xe9r";
191+
const PHRASE: &[u8] = b"hyp\xe9r";
192192
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
193193
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
194194
}
195195

196-
const NEWLINE_PHRASE: &'static [u8] = b"hyp\ner";
196+
const NEWLINE_PHRASE: &[u8] = b"hyp\ner";
197197

198198
#[test]
199199
#[should_panic]
@@ -206,7 +206,7 @@ mod tests {
206206
assert!(ReasonPhrase::try_from(NEWLINE_PHRASE).is_err());
207207
}
208208

209-
const CR_PHRASE: &'static [u8] = b"hyp\rer";
209+
const CR_PHRASE: &[u8] = b"hyp\rer";
210210

211211
#[test]
212212
#[should_panic]

src/proto/h1/decode.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ mod tests {
693693
use std::pin::Pin;
694694
use std::time::Duration;
695695

696-
impl<'a> MemRead for &'a [u8] {
696+
impl MemRead for &[u8] {
697697
fn read_mem(&mut self, _: &mut Context<'_>, len: usize) -> Poll<io::Result<Bytes>> {
698698
let n = std::cmp::min(len, self.len());
699699
if n > 0 {
@@ -707,12 +707,12 @@ mod tests {
707707
}
708708
}
709709

710-
impl<'a> MemRead for &'a mut (dyn Read + Unpin) {
710+
impl MemRead for &mut (dyn Read + Unpin) {
711711
fn read_mem(&mut self, cx: &mut Context<'_>, len: usize) -> Poll<io::Result<Bytes>> {
712712
let mut v = vec![0; len];
713713
let mut buf = ReadBuf::new(&mut v);
714714
ready!(Pin::new(self).poll_read(cx, buf.unfilled())?);
715-
Poll::Ready(Ok(Bytes::copy_from_slice(&buf.filled())))
715+
Poll::Ready(Ok(Bytes::copy_from_slice(buf.filled())))
716716
}
717717
}
718718

@@ -761,7 +761,7 @@ mod tests {
761761
})
762762
.await;
763763
let desc = format!("read_size failed for {:?}", s);
764-
state = result.expect(desc.as_str());
764+
state = result.expect(&desc);
765765
if state == ChunkedState::Body || state == ChunkedState::EndCr {
766766
break;
767767
}

src/proto/h1/dispatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl<'a, T> OptGuard<'a, T> {
488488
}
489489
}
490490

491-
impl<'a, T> Drop for OptGuard<'a, T> {
491+
impl<T> Drop for OptGuard<'_, T> {
492492
fn drop(&mut self) {
493493
if self.1 {
494494
self.0.set(None);

src/proto/h1/encode.rs

+28-40
Original file line numberDiff line numberDiff line change
@@ -535,19 +535,16 @@ mod tests {
535535
let trailers = vec![HeaderValue::from_static("chunky-trailer")];
536536
let encoder = encoder.into_chunked_with_trailing_fields(trailers);
537537

538-
let headers = HeaderMap::from_iter(
539-
vec![
540-
(
541-
HeaderName::from_static("chunky-trailer"),
542-
HeaderValue::from_static("header data"),
543-
),
544-
(
545-
HeaderName::from_static("should-not-be-included"),
546-
HeaderValue::from_static("oops"),
547-
),
548-
]
549-
.into_iter(),
550-
);
538+
let headers = HeaderMap::from_iter(vec![
539+
(
540+
HeaderName::from_static("chunky-trailer"),
541+
HeaderValue::from_static("header data"),
542+
),
543+
(
544+
HeaderName::from_static("should-not-be-included"),
545+
HeaderValue::from_static("oops"),
546+
),
547+
]);
551548

552549
let buf1 = encoder.encode_trailers::<&[u8]>(headers, false).unwrap();
553550

@@ -565,19 +562,16 @@ mod tests {
565562
];
566563
let encoder = encoder.into_chunked_with_trailing_fields(trailers);
567564

568-
let headers = HeaderMap::from_iter(
569-
vec![
570-
(
571-
HeaderName::from_static("chunky-trailer"),
572-
HeaderValue::from_static("header data"),
573-
),
574-
(
575-
HeaderName::from_static("chunky-trailer-2"),
576-
HeaderValue::from_static("more header data"),
577-
),
578-
]
579-
.into_iter(),
580-
);
565+
let headers = HeaderMap::from_iter(vec![
566+
(
567+
HeaderName::from_static("chunky-trailer"),
568+
HeaderValue::from_static("header data"),
569+
),
570+
(
571+
HeaderName::from_static("chunky-trailer-2"),
572+
HeaderValue::from_static("more header data"),
573+
),
574+
]);
581575

582576
let buf1 = encoder.encode_trailers::<&[u8]>(headers, false).unwrap();
583577

@@ -593,13 +587,10 @@ mod tests {
593587
fn chunked_with_no_trailer_header() {
594588
let encoder = Encoder::chunked();
595589

596-
let headers = HeaderMap::from_iter(
597-
vec![(
598-
HeaderName::from_static("chunky-trailer"),
599-
HeaderValue::from_static("header data"),
600-
)]
601-
.into_iter(),
602-
);
590+
let headers = HeaderMap::from_iter(vec![(
591+
HeaderName::from_static("chunky-trailer"),
592+
HeaderValue::from_static("header data"),
593+
)]);
603594

604595
assert!(encoder
605596
.encode_trailers::<&[u8]>(headers.clone(), false)
@@ -656,13 +647,10 @@ mod tests {
656647
let trailers = vec![HeaderValue::from_static("chunky-trailer")];
657648
let encoder = encoder.into_chunked_with_trailing_fields(trailers);
658649

659-
let headers = HeaderMap::from_iter(
660-
vec![(
661-
HeaderName::from_static("chunky-trailer"),
662-
HeaderValue::from_static("header data"),
663-
)]
664-
.into_iter(),
665-
);
650+
let headers = HeaderMap::from_iter(vec![(
651+
HeaderName::from_static("chunky-trailer"),
652+
HeaderValue::from_static("header data"),
653+
)]);
666654
let buf1 = encoder.encode_trailers::<&[u8]>(headers, true).unwrap();
667655

668656
let mut dst = Vec::new();

src/proto/h1/io.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ where
320320
}
321321

322322
#[cfg(test)]
323-
fn flush<'a>(&'a mut self) -> impl std::future::Future<Output = io::Result<()>> + 'a {
323+
fn flush(&mut self) -> impl std::future::Future<Output = io::Result<()>> + '_ {
324324
futures_util::future::poll_fn(move |cx| self.poll_flush(cx))
325325
}
326326
}

src/proto/h1/role.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ where
7777
return Ok(None);
7878
}
7979

80-
let _entered = trace_span!("parse_headers");
80+
trace_span!("parse_headers");
8181

8282
if let Some(prev_len) = prev_len {
8383
if !is_complete_fast(bytes, prev_len) {
@@ -100,10 +100,8 @@ fn is_complete_fast(bytes: &[u8], prev_len: usize) -> bool {
100100
if bytes[i + 1..].chunks(3).next() == Some(&b"\n\r\n"[..]) {
101101
return true;
102102
}
103-
} else if b == b'\n' {
104-
if bytes.get(i + 1) == Some(&b'\n') {
105-
return true;
106-
}
103+
} else if b == b'\n' && bytes.get(i + 1) == Some(&b'\n') {
104+
return true;
107105
}
108106
}
109107

@@ -117,7 +115,7 @@ pub(super) fn encode_headers<T>(
117115
where
118116
T: Http1Transaction,
119117
{
120-
let _entered = trace_span!("encode_headers");
118+
trace_span!("encode_headers");
121119
T::encode(enc, dst)
122120
}
123121

@@ -1622,7 +1620,7 @@ fn write_headers_original_case(
16221620
struct FastWrite<'a>(&'a mut Vec<u8>);
16231621

16241622
#[cfg(feature = "client")]
1625-
impl<'a> fmt::Write for FastWrite<'a> {
1623+
impl fmt::Write for FastWrite<'_> {
16261624
#[inline]
16271625
fn write_str(&mut self, s: &str) -> fmt::Result {
16281626
extend(self.0, s.as_bytes());
@@ -1721,7 +1719,7 @@ mod tests {
17211719
Server::parse(&mut raw, ctx).unwrap_err();
17221720
}
17231721

1724-
const H09_RESPONSE: &'static str = "Baguettes are super delicious, don't you agree?";
1722+
const H09_RESPONSE: &str = "Baguettes are super delicious, don't you agree?";
17251723

17261724
#[test]
17271725
fn test_parse_response_h09_allowed() {
@@ -1766,7 +1764,7 @@ mod tests {
17661764
assert_eq!(raw, H09_RESPONSE);
17671765
}
17681766

1769-
const RESPONSE_WITH_WHITESPACE_BETWEEN_HEADER_NAME_AND_COLON: &'static str =
1767+
const RESPONSE_WITH_WHITESPACE_BETWEEN_HEADER_NAME_AND_COLON: &str =
17701768
"HTTP/1.1 200 OK\r\nAccess-Control-Allow-Credentials : true\r\n\r\n";
17711769

17721770
#[test]
@@ -1842,14 +1840,12 @@ mod tests {
18421840
assert_eq!(
18431841
orig_headers
18441842
.get_all_internal(&HeaderName::from_static("host"))
1845-
.into_iter()
18461843
.collect::<Vec<_>>(),
18471844
vec![&Bytes::from("Host")]
18481845
);
18491846
assert_eq!(
18501847
orig_headers
18511848
.get_all_internal(&HeaderName::from_static("x-bread"))
1852-
.into_iter()
18531849
.collect::<Vec<_>>(),
18541850
vec![&Bytes::from("X-BREAD")]
18551851
);

0 commit comments

Comments
 (0)