From d707a31b376d2d28a6604687a1afacfd098d380e Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 2 Nov 2026 12:13:43 -0800 Subject: [PATCH] style(lib): enforce clippy::needless_pass_by_value see https://github.com/hyperium/hyper/issues/4071. --- Cargo.toml | 1 - src/body/incoming.rs | 8 ++++---- src/proto/h1/conn.rs | 2 +- src/proto/h1/io.rs | 6 +++--- src/proto/h1/role.rs | 10 +++++----- src/proto/h2/client.rs | 7 +++++-- src/proto/h2/mod.rs | 2 +- src/proto/h2/ping.rs | 2 +- src/proto/h2/server.rs | 4 ++-- 9 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ed5e00c770..079ffd2b97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -123,7 +123,6 @@ indexing_slicing = "allow" match_wild_err_arm = "allow" multiple_inherent_impl = "allow" multiple_unsafe_ops_per_block = "allow" -needless_pass_by_value = "allow" pattern_type_mismatch = "allow" redundant_else = "allow" struct_excessive_bools = "allow" # TODO: bogus lint? diff --git a/src/body/incoming.rs b/src/body/incoming.rs index b026a24d6b..c7c40b736f 100644 --- a/src/body/incoming.rs +++ b/src/body/incoming.rs @@ -393,18 +393,18 @@ mod tests { #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] #[test] fn size_hint() { - fn eq(body: Incoming, b: SizeHint, note: &str) { + fn eq(body: &Incoming, b: SizeHint, note: &str) { let a = body.size_hint(); assert_eq!(a.lower(), b.lower(), "lower for {:?}", note); assert_eq!(a.upper(), b.upper(), "upper for {:?}", note); } - eq(Incoming::empty(), SizeHint::with_exact(0), "empty"); + eq(&Incoming::empty(), SizeHint::with_exact(0), "empty"); - eq(Incoming::channel().1, SizeHint::new(), "channel"); + eq(&Incoming::channel().1, SizeHint::new(), "channel"); eq( - Incoming::new_channel(DecodedLength::new(4), /*wanter =*/ false).1, + &Incoming::new_channel(DecodedLength::new(4), /*wanter =*/ false).1, SizeHint::with_exact(4), "channel with length", ); diff --git a/src/proto/h1/conn.rs b/src/proto/h1/conn.rs index 1c00f6f774..7a68fe919b 100644 --- a/src/proto/h1/conn.rs +++ b/src/proto/h1/conn.rs @@ -241,7 +241,7 @@ where let msg = match self.io.parse::( cx, - ParseContext { + &mut ParseContext { cached_headers: &mut self.state.cached_headers, req_method: &mut self.state.method, h1_parser_config: self.state.h1_parser_config.clone(), diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs index bcd0204d2f..e5052b0b62 100644 --- a/src/proto/h1/io.rs +++ b/src/proto/h1/io.rs @@ -174,7 +174,7 @@ where pub(super) fn parse( &mut self, cx: &mut Context<'_>, - parse_ctx: ParseContext<'_>, + parse_ctx: &mut ParseContext<'_>, ) -> Poll>> where S: Http1Transaction, @@ -699,7 +699,7 @@ mod tests { // We expect a `parse` to be not ready, and so can't await it directly. // Rather, this `poll_fn` will wrap the `Poll` result. futures_util::future::poll_fn(|cx| { - let parse_ctx = ParseContext { + let mut parse_ctx = ParseContext { cached_headers: &mut None, req_method: &mut None, h1_parser_config: Default::default(), @@ -713,7 +713,7 @@ mod tests { on_informational: &mut None, }; assert!(buffered - .parse::(cx, parse_ctx) + .parse::(cx, &mut parse_ctx) .is_pending()); Poll::Ready(()) }) diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index e976931c76..42a82cc5ef 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -476,7 +476,7 @@ impl Http1Transaction for Server { }; let encoder = if let Some(orig_headers) = orig_headers { Self::encode_headers_with_original_case( - msg, + &mut msg, dst, is_last, orig_len, @@ -484,7 +484,7 @@ impl Http1Transaction for Server { orig_headers, )? } else { - Self::encode_headers_with_lower_case(msg, dst, is_last, orig_len, wrote_len)? + Self::encode_headers_with_lower_case(&mut msg, dst, is_last, orig_len, wrote_len)? }; ret.map(|()| encoder) @@ -548,7 +548,7 @@ impl Server { } fn encode_headers_with_lower_case( - msg: Encode<'_, StatusCode>, + msg: &mut Encode<'_, StatusCode>, dst: &mut Vec, is_last: bool, orig_len: usize, @@ -589,7 +589,7 @@ impl Server { #[cold] #[inline(never)] fn encode_headers_with_original_case( - msg: Encode<'_, StatusCode>, + msg: &mut Encode<'_, StatusCode>, dst: &mut Vec, is_last: bool, orig_len: usize, @@ -659,7 +659,7 @@ impl Server { #[inline] fn encode_headers( - msg: Encode<'_, StatusCode>, + msg: &mut Encode<'_, StatusCode>, dst: &mut Vec, mut is_last: bool, orig_len: usize, diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index eb768baa76..247432a26b 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -177,7 +177,7 @@ where let (conn, ping) = if ping_config.is_enabled() { let pp = conn.ping_pong().expect("conn.ping_pong"); - let (recorder, ponger) = ping::channel(pp, ping_config, timer); + let (recorder, ponger) = ping::channel(pp, &ping_config, timer); let conn: Conn<_, B> = Conn::new(ponger, conn); (Either::left(conn), recorder) @@ -706,7 +706,10 @@ where } let (head, body) = req.into_parts(); let mut req = ::http::Request::from_parts(head, ()); - super::strip_connection_headers(req.headers_mut(), super::MessageKind::Request); + super::strip_connection_headers( + req.headers_mut(), + &super::MessageKind::Request, + ); if let Some(len) = body.size_hint().exact() { if len != 0 || headers::method_has_defined_payload_semantics(req.method()) { headers::set_content_length_if_missing(req.headers_mut(), len); diff --git a/src/proto/h2/mod.rs b/src/proto/h2/mod.rs index 393d4179ab..b2d993e60e 100644 --- a/src/proto/h2/mod.rs +++ b/src/proto/h2/mod.rs @@ -47,7 +47,7 @@ enum MessageKind { Response, } -fn strip_connection_headers(headers: &mut HeaderMap, kind: MessageKind) { +fn strip_connection_headers(headers: &mut HeaderMap, kind: &MessageKind) { for header in &CONNECTION_HEADERS { if headers.remove(header).is_some() { warn!("Connection header illegal in HTTP/2: {}", header.as_str()); diff --git a/src/proto/h2/ping.rs b/src/proto/h2/ping.rs index 33016a28d4..f582a389b2 100644 --- a/src/proto/h2/ping.rs +++ b/src/proto/h2/ping.rs @@ -38,7 +38,7 @@ pub(super) fn disabled() -> Recorder { Recorder { shared: None } } -pub(super) fn channel(ping_pong: PingPong, config: Config, timer: Time) -> (Recorder, Ponger) { +pub(super) fn channel(ping_pong: PingPong, config: &Config, timer: Time) -> (Recorder, Ponger) { debug_assert!( config.is_enabled(), "ping channel requires bdp or keep-alive config", diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index 2098758d9e..b57350f8c4 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -215,7 +215,7 @@ where let mut conn = ready!(Pin::new(hs).poll(cx).map_err(crate::Error::new_h2))?; let ping = if ping_config.is_enabled() { let pp = conn.ping_pong().expect("conn.ping_pong"); - Some(ping::channel(pp, ping_config.clone(), me.timer.clone())) + Some(ping::channel(pp, ping_config, me.timer.clone())) } else { None }; @@ -471,7 +471,7 @@ where let mut res = ::http::Response::from_parts(head, ()); super::strip_connection_headers( res.headers_mut(), - super::MessageKind::Response, + &super::MessageKind::Response, ); // set Date header if it isn't already set if instructed