From 9dc5525072572fce1a076744d6cfd4e986ab1efe Mon Sep 17 00:00:00 2001 From: Yihai Lin Date: Tue, 3 Dec 2024 16:05:44 +0800 Subject: [PATCH] refactor(clippy): reduce clippy warnings --- benches/end_to_end.rs | 4 +-- benches/server.rs | 2 +- benches/support/tokiort.rs | 2 +- examples/client.rs | 2 +- examples/gateway.rs | 2 +- examples/http_proxy.rs | 2 +- examples/single_threaded.rs | 4 +-- examples/upgrades.rs | 3 +- examples/web_api.rs | 2 +- src/client/conn/http1.rs | 6 ++++ src/ext/h1_reason_phrase.rs | 10 +++--- src/proto/h1/decode.rs | 8 ++--- src/proto/h1/dispatch.rs | 2 +- src/proto/h1/encode.rs | 68 +++++++++++++++---------------------- src/proto/h1/io.rs | 2 +- src/proto/h1/role.rs | 18 ++++------ src/proto/h2/ping.rs | 12 +++---- src/proto/h2/server.rs | 4 +-- src/rt/io.rs | 4 +-- src/server/conn/http1.rs | 6 ++++ src/service/service.rs | 2 +- tests/client.rs | 8 ++--- tests/server.rs | 60 +++++++++++++++----------------- tests/support/mod.rs | 4 +-- 24 files changed, 113 insertions(+), 124 deletions(-) diff --git a/benches/end_to_end.rs b/benches/end_to_end.rs index a277688d92..07f08c186b 100644 --- a/benches/end_to_end.rs +++ b/benches/end_to_end.rs @@ -82,7 +82,7 @@ fn http1_parallel_x10_req_10kb_100_chunks(b: &mut test::Bencher) { #[bench] #[ignore] fn http1_parallel_x10_res_1mb(b: &mut test::Bencher) { - let body = &[b'x'; 1024 * 1024 * 1]; + let body = &[b'x'; 1024 * 1024]; opts().parallel(10).response_body(body).bench(b) } @@ -177,7 +177,7 @@ fn http2_parallel_x10_req_10kb_100_chunks_max_window(b: &mut test::Bencher) { #[bench] fn http2_parallel_x10_res_1mb(b: &mut test::Bencher) { - let body = &[b'x'; 1024 * 1024 * 1]; + let body = &[b'x'; 1024 * 1024]; opts() .http2() .parallel(10) diff --git a/benches/server.rs b/benches/server.rs index 6e9d3742cf..6ecabcd72c 100644 --- a/benches/server.rs +++ b/benches/server.rs @@ -152,7 +152,7 @@ fn raw_tcp_throughput_small_payload(b: &mut test::Bencher) { let mut buf = [0u8; 8192]; while rx.try_recv().is_err() { - sock.read(&mut buf).unwrap(); + let _ = sock.read(&mut buf).unwrap(); sock.write_all( b"\ HTTP/1.1 200 OK\r\n\ diff --git a/benches/support/tokiort.rs b/benches/support/tokiort.rs index 0beea038cd..8ab7aa9502 100644 --- a/benches/support/tokiort.rs +++ b/benches/support/tokiort.rs @@ -44,7 +44,7 @@ impl Timer for TokioTimer { fn reset(&self, sleep: &mut Pin>, new_deadline: Instant) { if let Some(sleep) = sleep.as_mut().downcast_mut_pin::() { - sleep.reset(new_deadline.into()) + sleep.reset(new_deadline) } } } diff --git a/examples/client.rs b/examples/client.rs index a64c35273b..75b103d099 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -71,7 +71,7 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> { while let Some(next) = res.frame().await { let frame = next?; if let Some(chunk) = frame.data_ref() { - io::stdout().write_all(&chunk).await?; + io::stdout().write_all(chunk).await?; } } diff --git a/examples/gateway.rs b/examples/gateway.rs index e0e3e053d0..ed9f526ab6 100644 --- a/examples/gateway.rs +++ b/examples/gateway.rs @@ -15,7 +15,7 @@ async fn main() -> Result<(), Box> { let in_addr: SocketAddr = ([127, 0, 0, 1], 3001).into(); let out_addr: SocketAddr = ([127, 0, 0, 1], 3000).into(); - let out_addr_clone = out_addr.clone(); + let out_addr_clone = out_addr; let listener = TcpListener::bind(in_addr).await?; diff --git a/examples/http_proxy.rs b/examples/http_proxy.rs index 2dbc5c9ac7..acdd3127f6 100644 --- a/examples/http_proxy.rs +++ b/examples/http_proxy.rs @@ -111,7 +111,7 @@ async fn proxy( } fn host_addr(uri: &http::Uri) -> Option { - uri.authority().and_then(|auth| Some(auth.to_string())) + uri.authority().map(|auth| auth.to_string()) } fn empty() -> BoxBody { diff --git a/examples/single_threaded.rs b/examples/single_threaded.rs index f297814c92..7dbf7104f7 100644 --- a/examples/single_threaded.rs +++ b/examples/single_threaded.rs @@ -207,7 +207,7 @@ async fn http1_client(url: hyper::Uri) -> Result<(), Box> while let Some(next) = res.frame().await { let frame = next?; if let Some(chunk) = frame.data_ref() { - stdout.write_all(&chunk).await.unwrap(); + stdout.write_all(chunk).await.unwrap(); } } stdout.write_all(b"\n-----------------\n").await.unwrap(); @@ -308,7 +308,7 @@ async fn http2_client(url: hyper::Uri) -> Result<(), Box> while let Some(next) = res.frame().await { let frame = next?; if let Some(chunk) = frame.data_ref() { - stdout.write_all(&chunk).await.unwrap(); + stdout.write_all(chunk).await.unwrap(); } } stdout.write_all(b"\n-----------------\n").await.unwrap(); diff --git a/examples/upgrades.rs b/examples/upgrades.rs index ba02c15aca..b94a8b9c42 100644 --- a/examples/upgrades.rs +++ b/examples/upgrades.rs @@ -169,7 +169,6 @@ async fn main() { res = &mut conn => { if let Err(err) = res { println!("Error serving connection: {:?}", err); - return; } } // Continue polling the connection after enabling graceful shutdown. @@ -187,7 +186,7 @@ async fn main() { }); // Client requests a HTTP connection upgrade. - let request = client_upgrade_request(addr.clone()); + let request = client_upgrade_request(addr); if let Err(e) = request.await { eprintln!("client error: {}", e); } diff --git a/examples/web_api.rs b/examples/web_api.rs index 91d9e9b72f..ffc62ba89b 100644 --- a/examples/web_api.rs +++ b/examples/web_api.rs @@ -117,7 +117,7 @@ async fn main() -> Result<()> { let io = TokioIo::new(stream); tokio::task::spawn(async move { - let service = service_fn(move |req| response_examples(req)); + let service = service_fn(response_examples); if let Err(err) = http1::Builder::new().serve_connection(io, service).await { println!("Failed to serve connection: {:?}", err); diff --git a/src/client/conn/http1.rs b/src/client/conn/http1.rs index ecfe6eb8fb..4e80bd9b8b 100644 --- a/src/client/conn/http1.rs +++ b/src/client/conn/http1.rs @@ -302,6 +302,12 @@ where // ===== impl Builder +impl Default for Builder { + fn default() -> Builder { + Builder::new() + } +} + impl Builder { /// Creates a new connection builder. #[inline] diff --git a/src/ext/h1_reason_phrase.rs b/src/ext/h1_reason_phrase.rs index c6f5233345..adb4363689 100644 --- a/src/ext/h1_reason_phrase.rs +++ b/src/ext/h1_reason_phrase.rs @@ -174,26 +174,26 @@ mod tests { #[test] fn basic_valid() { - const PHRASE: &'static [u8] = b"OK"; + const PHRASE: &[u8] = b"OK"; assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE); assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE); } #[test] fn empty_valid() { - const PHRASE: &'static [u8] = b""; + const PHRASE: &[u8] = b""; assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE); assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE); } #[test] fn obs_text_valid() { - const PHRASE: &'static [u8] = b"hyp\xe9r"; + const PHRASE: &[u8] = b"hyp\xe9r"; assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE); assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE); } - const NEWLINE_PHRASE: &'static [u8] = b"hyp\ner"; + const NEWLINE_PHRASE: &[u8] = b"hyp\ner"; #[test] #[should_panic] @@ -206,7 +206,7 @@ mod tests { assert!(ReasonPhrase::try_from(NEWLINE_PHRASE).is_err()); } - const CR_PHRASE: &'static [u8] = b"hyp\rer"; + const CR_PHRASE: &[u8] = b"hyp\rer"; #[test] #[should_panic] diff --git a/src/proto/h1/decode.rs b/src/proto/h1/decode.rs index 2e196c36a5..dd293e1228 100644 --- a/src/proto/h1/decode.rs +++ b/src/proto/h1/decode.rs @@ -693,7 +693,7 @@ mod tests { use std::pin::Pin; use std::time::Duration; - impl<'a> MemRead for &'a [u8] { + impl MemRead for &[u8] { fn read_mem(&mut self, _: &mut Context<'_>, len: usize) -> Poll> { let n = std::cmp::min(len, self.len()); if n > 0 { @@ -707,12 +707,12 @@ mod tests { } } - impl<'a> MemRead for &'a mut (dyn Read + Unpin) { + impl MemRead for &mut (dyn Read + Unpin) { fn read_mem(&mut self, cx: &mut Context<'_>, len: usize) -> Poll> { let mut v = vec![0; len]; let mut buf = ReadBuf::new(&mut v); ready!(Pin::new(self).poll_read(cx, buf.unfilled())?); - Poll::Ready(Ok(Bytes::copy_from_slice(&buf.filled()))) + Poll::Ready(Ok(Bytes::copy_from_slice(buf.filled()))) } } @@ -761,7 +761,7 @@ mod tests { }) .await; let desc = format!("read_size failed for {:?}", s); - state = result.expect(desc.as_str()); + state = result.expect(&desc); if state == ChunkedState::Body || state == ChunkedState::EndCr { break; } diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index 79ea48be9f..4d921a3b83 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -488,7 +488,7 @@ impl<'a, T> OptGuard<'a, T> { } } -impl<'a, T> Drop for OptGuard<'a, T> { +impl Drop for OptGuard<'_, T> { fn drop(&mut self) { if self.1 { self.0.set(None); diff --git a/src/proto/h1/encode.rs b/src/proto/h1/encode.rs index 8a5e840722..2df0c396b7 100644 --- a/src/proto/h1/encode.rs +++ b/src/proto/h1/encode.rs @@ -535,19 +535,16 @@ mod tests { let trailers = vec![HeaderValue::from_static("chunky-trailer")]; let encoder = encoder.into_chunked_with_trailing_fields(trailers); - let headers = HeaderMap::from_iter( - vec![ - ( - HeaderName::from_static("chunky-trailer"), - HeaderValue::from_static("header data"), - ), - ( - HeaderName::from_static("should-not-be-included"), - HeaderValue::from_static("oops"), - ), - ] - .into_iter(), - ); + let headers = HeaderMap::from_iter(vec![ + ( + HeaderName::from_static("chunky-trailer"), + HeaderValue::from_static("header data"), + ), + ( + HeaderName::from_static("should-not-be-included"), + HeaderValue::from_static("oops"), + ), + ]); let buf1 = encoder.encode_trailers::<&[u8]>(headers, false).unwrap(); @@ -565,19 +562,16 @@ mod tests { ]; let encoder = encoder.into_chunked_with_trailing_fields(trailers); - let headers = HeaderMap::from_iter( - vec![ - ( - HeaderName::from_static("chunky-trailer"), - HeaderValue::from_static("header data"), - ), - ( - HeaderName::from_static("chunky-trailer-2"), - HeaderValue::from_static("more header data"), - ), - ] - .into_iter(), - ); + let headers = HeaderMap::from_iter(vec![ + ( + HeaderName::from_static("chunky-trailer"), + HeaderValue::from_static("header data"), + ), + ( + HeaderName::from_static("chunky-trailer-2"), + HeaderValue::from_static("more header data"), + ), + ]); let buf1 = encoder.encode_trailers::<&[u8]>(headers, false).unwrap(); @@ -593,13 +587,10 @@ mod tests { fn chunked_with_no_trailer_header() { let encoder = Encoder::chunked(); - let headers = HeaderMap::from_iter( - vec![( - HeaderName::from_static("chunky-trailer"), - HeaderValue::from_static("header data"), - )] - .into_iter(), - ); + let headers = HeaderMap::from_iter(vec![( + HeaderName::from_static("chunky-trailer"), + HeaderValue::from_static("header data"), + )]); assert!(encoder .encode_trailers::<&[u8]>(headers.clone(), false) @@ -656,13 +647,10 @@ mod tests { let trailers = vec![HeaderValue::from_static("chunky-trailer")]; let encoder = encoder.into_chunked_with_trailing_fields(trailers); - let headers = HeaderMap::from_iter( - vec![( - HeaderName::from_static("chunky-trailer"), - HeaderValue::from_static("header data"), - )] - .into_iter(), - ); + let headers = HeaderMap::from_iter(vec![( + HeaderName::from_static("chunky-trailer"), + HeaderValue::from_static("header data"), + )]); let buf1 = encoder.encode_trailers::<&[u8]>(headers, true).unwrap(); let mut dst = Vec::new(); diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs index 5f7b836d5d..4f8b58eced 100644 --- a/src/proto/h1/io.rs +++ b/src/proto/h1/io.rs @@ -320,7 +320,7 @@ where } #[cfg(test)] - fn flush<'a>(&'a mut self) -> impl std::future::Future> + 'a { + fn flush(&mut self) -> impl std::future::Future> + '_ { futures_util::future::poll_fn(move |cx| self.poll_flush(cx)) } } diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index e9c799fca5..756c774f18 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -77,7 +77,7 @@ where return Ok(None); } - let _entered = trace_span!("parse_headers"); + trace_span!("parse_headers"); if let Some(prev_len) = prev_len { if !is_complete_fast(bytes, prev_len) { @@ -100,10 +100,8 @@ fn is_complete_fast(bytes: &[u8], prev_len: usize) -> bool { if bytes[i + 1..].chunks(3).next() == Some(&b"\n\r\n"[..]) { return true; } - } else if b == b'\n' { - if bytes.get(i + 1) == Some(&b'\n') { - return true; - } + } else if b == b'\n' && bytes.get(i + 1) == Some(&b'\n') { + return true; } } @@ -117,7 +115,7 @@ pub(super) fn encode_headers( where T: Http1Transaction, { - let _entered = trace_span!("encode_headers"); + trace_span!("encode_headers"); T::encode(enc, dst) } @@ -1622,7 +1620,7 @@ fn write_headers_original_case( struct FastWrite<'a>(&'a mut Vec); #[cfg(feature = "client")] -impl<'a> fmt::Write for FastWrite<'a> { +impl fmt::Write for FastWrite<'_> { #[inline] fn write_str(&mut self, s: &str) -> fmt::Result { extend(self.0, s.as_bytes()); @@ -1721,7 +1719,7 @@ mod tests { Server::parse(&mut raw, ctx).unwrap_err(); } - const H09_RESPONSE: &'static str = "Baguettes are super delicious, don't you agree?"; + const H09_RESPONSE: &str = "Baguettes are super delicious, don't you agree?"; #[test] fn test_parse_response_h09_allowed() { @@ -1766,7 +1764,7 @@ mod tests { assert_eq!(raw, H09_RESPONSE); } - const RESPONSE_WITH_WHITESPACE_BETWEEN_HEADER_NAME_AND_COLON: &'static str = + const RESPONSE_WITH_WHITESPACE_BETWEEN_HEADER_NAME_AND_COLON: &str = "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Credentials : true\r\n\r\n"; #[test] @@ -1842,14 +1840,12 @@ mod tests { assert_eq!( orig_headers .get_all_internal(&HeaderName::from_static("host")) - .into_iter() .collect::>(), vec![&Bytes::from("Host")] ); assert_eq!( orig_headers .get_all_internal(&HeaderName::from_static("x-bread")) - .into_iter() .collect::>(), vec![&Bytes::from("X-BREAD")] ); diff --git a/src/proto/h2/ping.rs b/src/proto/h2/ping.rs index ea2bbb36ad..749cf1b7c0 100644 --- a/src/proto/h2/ping.rs +++ b/src/proto/h2/ping.rs @@ -10,14 +10,14 @@ /// # BDP Algorithm /// /// 1. When receiving a DATA frame, if a BDP ping isn't outstanding: -/// 1a. Record current time. -/// 1b. Send a BDP ping. +/// 1a. Record current time. +/// 1b. Send a BDP ping. /// 2. Increment the number of received bytes. /// 3. When the BDP ping ack is received: -/// 3a. Record duration from sent time. -/// 3b. Merge RTT with a running average. -/// 3c. Calculate bdp as bytes/rtt. -/// 3d. If bdp is over 2/3 max, set new max to bdp and update windows. +/// 3a. Record duration from sent time. +/// 3b. Merge RTT with a running average. +/// 3c. Calculate bdp as bytes/rtt. +/// 3d. If bdp is over 2/3 max, set new max to bdp and update windows. use std::fmt; use std::future::Future; use std::pin::Pin; diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index fbeb02ee4d..a8a20dd68e 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -181,13 +181,11 @@ where match self.state { State::Handshaking { .. } => { self.close_pending = true; - return; } State::Serving(ref mut srv) => { if srv.closing.is_none() { srv.conn.graceful_shutdown(); } - return; } } } @@ -227,7 +225,7 @@ where } State::Serving(ref mut srv) => { // graceful_shutdown was called before handshaking finished, - if true == me.close_pending && srv.closing.is_none() { + if me.close_pending && srv.closing.is_none() { srv.conn.graceful_shutdown(); } ready!(srv.poll_server(cx, &mut me.service, &mut me.exec))?; diff --git a/src/rt/io.rs b/src/rt/io.rs index e8f6ed9994..ed4af0929f 100644 --- a/src/rt/io.rs +++ b/src/rt/io.rs @@ -211,7 +211,7 @@ impl<'data> ReadBuf<'data> { } } -impl<'data> fmt::Debug for ReadBuf<'data> { +impl fmt::Debug for ReadBuf<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ReadBuf") .field("filled", &self.filled) @@ -221,7 +221,7 @@ impl<'data> fmt::Debug for ReadBuf<'data> { } } -impl<'data> ReadBufCursor<'data> { +impl ReadBufCursor<'_> { /// Access the unfilled part of the buffer. /// /// # Safety diff --git a/src/server/conn/http1.rs b/src/server/conn/http1.rs index 097497bf41..f70068a630 100644 --- a/src/server/conn/http1.rs +++ b/src/server/conn/http1.rs @@ -227,6 +227,12 @@ where // ===== impl Builder ===== +impl Default for Builder { + fn default() -> Self { + Self::new() + } +} + impl Builder { /// Create a new connection builder. pub fn new() -> Self { diff --git a/src/service/service.rs b/src/service/service.rs index 44d945ebb0..42c18e727f 100644 --- a/src/service/service.rs +++ b/src/service/service.rs @@ -40,7 +40,7 @@ pub trait Service { /// - It's clearer that Services can likely be cloned /// - To share state across clones, you generally need `Arc>` /// That means you're not really using the `&mut self` and could do with a `&self`. - /// The discussion on this is here: + /// The discussion on this is here: fn call(&self, req: Request) -> Self::Future; } diff --git a/tests/client.rs b/tests/client.rs index 4bdbecb4bd..9199cfe212 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -1156,7 +1156,7 @@ test! { \r\n\ ", reply: { - let long_header = std::iter::repeat("A").take(500_000).collect::(); + let long_header = "A".repeat(500_000); format!("\ HTTP/1.1 200 OK\r\n\ {}: {}\r\n\ @@ -1827,7 +1827,7 @@ mod conn { sock.set_write_timeout(Some(Duration::from_secs(5))) .unwrap(); let mut buf = [0; 4096]; - sock.read(&mut buf).expect("read 1"); + let _ = sock.read(&mut buf).expect("read 1"); sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n") .unwrap(); @@ -1879,7 +1879,7 @@ mod conn { sock.set_write_timeout(Some(Duration::from_secs(5))) .unwrap(); let mut buf = [0; 4096]; - sock.read(&mut buf).expect("read 1"); + let _ = sock.read(&mut buf).expect("read 1"); sock.write_all( b"\ HTTP/1.1 101 Switching Protocols\r\n\ @@ -1964,7 +1964,7 @@ mod conn { sock.set_write_timeout(Some(Duration::from_secs(5))) .unwrap(); let mut buf = [0; 4096]; - sock.read(&mut buf).expect("read 1"); + let _ = sock.read(&mut buf).expect("read 1"); sock.write_all( b"\ HTTP/1.1 200 OK\r\n\ diff --git a/tests/server.rs b/tests/server.rs index f72cf62702..395f472334 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -50,7 +50,7 @@ fn get_should_ignore_body() { ", ) .unwrap(); - req.read(&mut [0; 256]).unwrap(); + let _ = req.read(&mut [0; 256]).unwrap(); assert_eq!(server.body(), b""); } @@ -69,7 +69,7 @@ fn get_with_body() { ", ) .unwrap(); - req.read(&mut [0; 256]).unwrap(); + let _ = req.read(&mut [0; 256]).unwrap(); // note: doesn't include trailing \r\n, cause Content-Length wasn't 21 assert_eq!(server.body(), b"I'm a good request."); @@ -156,7 +156,7 @@ mod response_body_lengths { let n = body.find("\r\n\r\n").unwrap() + 4; if case.expects_chunked { - if body_str.len() > 0 { + if !body_str.is_empty() { let len = body.len(); assert_eq!( &body[n + 1..n + 3], @@ -469,7 +469,7 @@ fn post_with_content_length_body() { ", ) .unwrap(); - req.read(&mut [0; 256]).unwrap(); + let _ = req.read(&mut [0; 256]).unwrap(); assert_eq!(server.body(), b"hello"); } @@ -515,7 +515,7 @@ fn post_with_chunked_body() { ", ) .unwrap(); - req.read(&mut [0; 256]).unwrap(); + let _ = req.read(&mut [0; 256]).unwrap(); assert_eq!(server.body(), b"qwert"); } @@ -540,7 +540,7 @@ fn post_with_chunked_overflow() { ", ) .unwrap(); - req.read(&mut [0; 256]).unwrap(); + let _ = req.read(&mut [0; 256]).unwrap(); let err = server.body_err().source().unwrap().to_string(); assert!( @@ -569,7 +569,7 @@ fn post_with_incomplete_body() { server.body_err(); - req.read(&mut [0; 256]).expect("read"); + let _ = req.read(&mut [0; 256]).expect("read"); } #[test] @@ -592,7 +592,7 @@ fn post_with_chunked_missing_final_digit() { server.body_err(); - req.read(&mut [0; 256]).expect("read"); + let _ = req.read(&mut [0; 256]).expect("read"); } #[test] @@ -1090,13 +1090,10 @@ fn pipeline_disabled() { // TODO: add in a delay to the `ServeReply` interface, to allow this // delay to prevent the 2 writes from happening before this test thread // can read from the socket. - match req.read(&mut buf) { - Ok(n) => { - // won't be 0, because we didn't say to close, and so socket - // will be open until `server` drops - assert_ne!(n, 0); - } - Err(_) => (), + if let Ok(n) = req.read(&mut buf) { + // won't be 0, because we didn't say to close, and so socket + // will be open until `server` drops + assert_ne!(n, 0); } } @@ -1305,11 +1302,11 @@ async fn http1_graceful_shutdown_after_upgrade() { ) .expect("write 1"); let mut buf = [0; 256]; - tcp.read(&mut buf).expect("read 1"); + let _ = tcp.read(&mut buf).expect("read 1"); let response = s(&buf); assert!(response.starts_with("HTTP/1.1 101 Switching Protocols\r\n")); - assert!(!has_header(&response, "content-length")); + assert!(!has_header(response, "content-length")); let _ = read_101_tx.send(()); }); @@ -1391,7 +1388,7 @@ async fn http1_allow_half_close() { tcp.shutdown(::std::net::Shutdown::Write).expect("SHDN_WR"); let mut buf = [0; 256]; - tcp.read(&mut buf).unwrap(); + let _ = tcp.read(&mut buf).unwrap(); let expected = "HTTP/1.1 200 OK\r\n"; assert_eq!(s(&buf[..expected.len()]), expected); }); @@ -1450,7 +1447,7 @@ async fn returning_1xx_response_is_error() { let mut tcp = connect(&addr); tcp.write_all(b"GET / HTTP/1.1\r\n\r\n").unwrap(); let mut buf = [0; 256]; - tcp.read(&mut buf).unwrap(); + tcp.read_exact(&mut buf).unwrap(); let expected = "HTTP/1.1 500 "; assert_eq!(s(&buf[..expected.len()]), expected); @@ -1481,9 +1478,8 @@ fn header_name_too_long() { let mut req = connect(server.addr()); let mut write = Vec::with_capacity(1024 * 66); write.extend_from_slice(b"GET / HTTP/1.1\r\n"); - for _ in 0..(1024 * 65) { - write.push(b'x'); - } + write.extend_from_slice(vec![b'x'; 1024 * 64].as_slice()); + write.extend_from_slice(b": foo\r\n\r\n"); req.write_all(&write).unwrap(); @@ -1654,7 +1650,7 @@ async fn upgrades() { ) .expect("write 1"); let mut buf = [0; 256]; - tcp.read(&mut buf).expect("read 1"); + let _ = tcp.read(&mut buf).expect("read 1"); let expected = "HTTP/1.1 101 Switching Protocols\r\n"; assert_eq!(s(&buf[..expected.len()]), expected); @@ -1708,7 +1704,7 @@ async fn http_connect() { ) .expect("write 1"); let mut buf = [0; 256]; - tcp.read(&mut buf).expect("read 1"); + let _ = tcp.read(&mut buf).expect("read 1"); let expected = "HTTP/1.1 200 OK\r\n"; assert_eq!(s(&buf[..expected.len()]), expected); @@ -1765,11 +1761,11 @@ async fn upgrades_new() { ) .expect("write 1"); let mut buf = [0; 256]; - tcp.read(&mut buf).expect("read 1"); + let _ = tcp.read(&mut buf).expect("read 1"); let response = s(&buf); assert!(response.starts_with("HTTP/1.1 101 Switching Protocols\r\n")); - assert!(!has_header(&response, "content-length")); + assert!(!has_header(response, "content-length")); let _ = read_101_tx.send(()); let n = tcp.read(&mut buf).expect("read 2"); @@ -1873,7 +1869,7 @@ async fn http_connect_new() { ) .expect("write 1"); let mut buf = [0; 256]; - tcp.read(&mut buf).expect("read 1"); + let _ = tcp.read(&mut buf).expect("read 1"); let expected = "HTTP/1.1 200 OK\r\n"; assert_eq!(s(&buf[..expected.len()]), expected); @@ -2247,7 +2243,7 @@ async fn parse_errors_send_4xx_response() { let mut tcp = connect(&addr); tcp.write_all(b"GE T / HTTP/1.1\r\n\r\n").unwrap(); let mut buf = [0; 256]; - tcp.read(&mut buf).unwrap(); + tcp.read_exact(&mut buf).unwrap(); let expected = "HTTP/1.1 400 "; assert_eq!(s(&buf[..expected.len()]), expected); @@ -2270,7 +2266,7 @@ async fn illegal_request_length_returns_400_response() { tcp.write_all(b"POST / HTTP/1.1\r\nContent-Length: foo\r\n\r\n") .unwrap(); let mut buf = [0; 256]; - tcp.read(&mut buf).unwrap(); + let _ = tcp.read(&mut buf).unwrap(); let expected = "HTTP/1.1 400 "; assert_eq!(s(&buf[..expected.len()]), expected); @@ -2311,7 +2307,7 @@ async fn max_buf_size() { tcp.write_all(b"POST /").expect("write 1"); tcp.write_all(&[b'a'; MAX]).expect("write 2"); let mut buf = [0; 256]; - tcp.read(&mut buf).expect("read 1"); + let _ = tcp.read(&mut buf).expect("read 1"); let expected = "HTTP/1.1 431 "; assert_eq!(s(&buf[..expected.len()]), expected); @@ -2918,7 +2914,7 @@ struct ReplyBuilder<'a> { tx: &'a Mutex>, } -impl<'a> ReplyBuilder<'a> { +impl ReplyBuilder<'_> { fn status(self, status: hyper::StatusCode) -> Self { self.tx.lock().unwrap().send(Reply::Status(status)).unwrap(); self @@ -2994,7 +2990,7 @@ impl<'a> ReplyBuilder<'a> { } } -impl<'a> Drop for ReplyBuilder<'a> { +impl Drop for ReplyBuilder<'_> { fn drop(&mut self) { if let Ok(mut tx) = self.tx.lock() { let _ = tx.send(Reply::End); diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 1de834532d..cf3f1bc366 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -371,7 +371,7 @@ async fn async_test(cfg: __TestConfig) { assert_eq!(req.method(), &sreq.method, "client method"); assert_eq!(req.version(), version, "client version"); for func in &sreq.headers { - func(&req.headers()); + func(req.headers()); } let sbody = sreq.body; req.collect().map_ok(move |collected| { @@ -460,7 +460,7 @@ async fn async_test(cfg: __TestConfig) { assert_eq!(res.status(), cstatus, "server status"); assert_eq!(res.version(), version, "server version"); for func in &cheaders { - func(&res.headers()); + func(res.headers()); } let body = res.collect().await.unwrap().to_bytes();