Skip to content
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

refactor(clippy): Reduce some Clippy warnings #3805

Merged
merged 1 commit into from
Dec 6, 2024
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
4 changes: 2 additions & 2 deletions benches/end_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion benches/support/tokiort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Timer for TokioTimer {

fn reset(&self, sleep: &mut Pin<Box<dyn Sleep>>, new_deadline: Instant) {
if let Some(sleep) = sleep.as_mut().downcast_mut_pin::<TokioSleep>() {
sleep.reset(new_deadline.into())
sleep.reset(new_deadline)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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?;

Expand Down
2 changes: 1 addition & 1 deletion examples/http_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn proxy(
}

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

fn empty() -> BoxBody<Bytes, hyper::Error> {
Expand Down
4 changes: 2 additions & 2 deletions examples/single_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async fn http1_client(url: hyper::Uri) -> Result<(), Box<dyn std::error::Error>>
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();
Expand Down Expand Up @@ -308,7 +308,7 @@ async fn http2_client(url: hyper::Uri) -> Result<(), Box<dyn std::error::Error>>
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();
Expand Down
3 changes: 1 addition & 2 deletions examples/upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/web_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/ext/h1_reason_phrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/proto/h1/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<io::Result<Bytes>> {
let n = std::cmp::min(len, self.len());
if n > 0 {
Expand All @@ -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<io::Result<Bytes>> {
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())))
}
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ impl<'a, T> OptGuard<'a, T> {
}
}

impl<'a, T> Drop for OptGuard<'a, T> {
impl<T> Drop for OptGuard<'_, T> {
fn drop(&mut self) {
if self.1 {
self.0.set(None);
Expand Down
68 changes: 28 additions & 40 deletions src/proto/h1/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/proto/h1/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ where
}

#[cfg(test)]
fn flush<'a>(&'a mut self) -> impl std::future::Future<Output = io::Result<()>> + 'a {
fn flush(&mut self) -> impl std::future::Future<Output = io::Result<()>> + '_ {
futures_util::future::poll_fn(move |cx| self.poll_flush(cx))
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/proto/h1/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

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

#[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());
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -1842,14 +1840,12 @@ mod tests {
assert_eq!(
orig_headers
.get_all_internal(&HeaderName::from_static("host"))
.into_iter()
.collect::<Vec<_>>(),
vec![&Bytes::from("Host")]
);
assert_eq!(
orig_headers
.get_all_internal(&HeaderName::from_static("x-bread"))
.into_iter()
.collect::<Vec<_>>(),
vec![&Bytes::from("X-BREAD")]
);
Expand Down
12 changes: 6 additions & 6 deletions src/proto/h2/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/proto/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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))?;
Expand Down
Loading
Loading