From 521c4105dc1af0300b6793c15ebb2454ba25a18a Mon Sep 17 00:00:00 2001 From: dox4 Date: Fri, 28 Aug 2026 14:40:16 +0800 Subject: [PATCH 1/3] style: replace single-character lifetime names with descriptive names --- Cargo.toml | 1 - src/client/dispatch.rs | 2 +- src/common/buf.rs | 2 +- src/ext/informational.rs | 2 +- src/ext/mod.rs | 10 +++++----- src/ffi/task.rs | 4 ++-- src/proto/h1/decode.rs | 12 ++++++------ src/proto/h1/dispatch.rs | 6 +++--- src/proto/h1/encode.rs | 2 +- src/proto/h1/io.rs | 2 +- src/proto/h1/mod.rs | 14 +++++++------- src/proto/h1/role.rs | 2 +- src/proto/h2/mod.rs | 2 +- src/rt/io.rs | 8 ++++---- tests/server.rs | 4 ++-- 15 files changed, 36 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d9e081d506..b50b8d6c13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -139,7 +139,6 @@ panic = "allow" pattern_type_mismatch = "allow" redundant_closure_for_method_calls = "allow" redundant_else = "allow" -single_char_lifetime_names = "allow" struct_excessive_bools = "allow" # TODO: bogus lint? trivially_copy_pass_by_ref = "allow" unnecessary_trailing_comma = "allow" diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 69c9b8cdaa..d107804f22 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -408,7 +408,7 @@ mod tests { } /// Helper to check if the future is ready after polling once. - struct PollOnce<'a, F>(&'a mut F); + struct PollOnce<'func, F>(&'func mut F); impl Future for PollOnce<'_, F> where diff --git a/src/common/buf.rs b/src/common/buf.rs index d00071551b..0bf02497f4 100644 --- a/src/common/buf.rs +++ b/src/common/buf.rs @@ -56,7 +56,7 @@ impl Buf for BufList { } #[inline] - fn chunks_vectored<'t>(&'t self, dst: &mut [IoSlice<'t>]) -> usize { + fn chunks_vectored<'data>(&'data self, dst: &mut [IoSlice<'data>]) -> usize { if dst.is_empty() { return 0; } diff --git a/src/ext/informational.rs b/src/ext/informational.rs index e728580fa5..6c86b4974e 100644 --- a/src/ext/informational.rs +++ b/src/ext/informational.rs @@ -66,7 +66,7 @@ where // being either a real reference, or moving the http::Response into the closure, // in a backwards-compatible change in the future. #[derive(Debug)] -pub struct Response<'a>(&'a http::Response<()>); +pub struct Response<'resp>(&'resp http::Response<()>); impl Response<'_> { #[inline] diff --git a/src/ext/mod.rs b/src/ext/mod.rs index 0fccb5ffec..82f7cd7d07 100644 --- a/src/ext/mod.rs +++ b/src/ext/mod.rs @@ -113,8 +113,8 @@ impl Protocol { } #[cfg(feature = "http2")] -impl<'a> From<&'a str> for Protocol { - fn from(value: &'a str) -> Self { +impl<'proto> From<&'proto str> for Protocol { + fn from(value: &'proto str) -> Self { Self { inner: h2::ext::Protocol::from(value), } @@ -165,10 +165,10 @@ impl HeaderCaseMap { /// Returns a view of all spellings associated with that header name, /// in the order they were found. #[cfg(feature = "client")] - pub(crate) fn get_all<'a>( - &'a self, + pub(crate) fn get_all<'hdr>( + &'hdr self, name: &HeaderName, - ) -> impl Iterator + 'a> + 'a { + ) -> impl Iterator + 'hdr> + 'hdr { self.get_all_internal(name) } diff --git a/src/ffi/task.rs b/src/ffi/task.rs index 9c7fba6a26..296cd9507e 100644 --- a/src/ffi/task.rs +++ b/src/ffi/task.rs @@ -128,7 +128,7 @@ struct TaskFuture { /// its only purpose is to provide access to the waker. See `hyper_waker`. /// /// Corresponding Rust type: -pub struct hyper_context<'a>(Context<'a>); +pub struct hyper_context<'ctx>(Context<'ctx>); /// A waker that is saved and used to waken a pending task. /// @@ -511,7 +511,7 @@ where // ===== impl hyper_context ===== impl hyper_context<'_> { - pub(crate) fn wrap<'a, 'b>(cx: &'a mut Context<'b>) -> &'a mut hyper_context<'b> { + pub(crate) fn wrap<'borrow, 'ctx>(cx: &'borrow mut Context<'ctx>) -> &'borrow mut hyper_context<'ctx> { // A struct with only one field has the same layout as that field. unsafe { std::mem::transmute::<&mut Context<'_>, &mut hyper_context<'_>>(cx) } } diff --git a/src/proto/h1/decode.rs b/src/proto/h1/decode.rs index bdfdf79abf..65adaa784b 100644 --- a/src/proto/h1/decode.rs +++ b/src/proto/h1/decode.rs @@ -286,12 +286,12 @@ macro_rules! put_u8 { }; } -struct StepArgs<'a> { - chunk_size: &'a mut u64, - chunk_buf: &'a mut Option, - extensions_cnt: &'a mut u64, - trailers_buf: &'a mut Option, - trailers_cnt: &'a mut usize, +struct StepArgs<'args> { + chunk_size: &'args mut u64, + chunk_buf: &'args mut Option, + extensions_cnt: &'args mut u64, + trailers_buf: &'args mut Option, + trailers_cnt: &'args mut usize, max_headers_cnt: usize, max_headers_bytes: usize, } diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index f250f55863..d98aebcf1f 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -509,10 +509,10 @@ where /// A drop guard to allow a mutable borrow of an Option while being able to /// set whether the `Option` should be cleared on drop. -struct OptGuard<'a, T>(Pin<&'a mut Option>, bool); +struct OptGuard<'opt, T>(Pin<&'opt mut Option>, bool); -impl<'a, T> OptGuard<'a, T> { - fn new(pin: Pin<&'a mut Option>) -> Self { +impl<'opt, T> OptGuard<'opt, T> { + fn new(pin: Pin<&'opt mut Option>) -> Self { OptGuard(pin, false) } diff --git a/src/proto/h1/encode.rs b/src/proto/h1/encode.rs index a1eebafa12..266b4dd6dd 100644 --- a/src/proto/h1/encode.rs +++ b/src/proto/h1/encode.rs @@ -317,7 +317,7 @@ where } #[inline] - fn chunks_vectored<'t>(&'t self, dst: &mut [IoSlice<'t>]) -> usize { + fn chunks_vectored<'data>(&'data self, dst: &mut [IoSlice<'data>]) -> usize { match &self.kind { BufKind::Exact(b) => b.chunks_vectored(dst), BufKind::Limited(b) => b.chunks_vectored(dst), diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs index 6b3f10fbae..b49e48e5c8 100644 --- a/src/proto/h1/io.rs +++ b/src/proto/h1/io.rs @@ -637,7 +637,7 @@ impl Buf for WriteBuf { } #[inline] - fn chunks_vectored<'t>(&'t self, dst: &mut [IoSlice<'t>]) -> usize { + fn chunks_vectored<'data>(&'data self, dst: &mut [IoSlice<'data>]) -> usize { let n = self.headers.chunks_vectored(dst); self.queue.chunks_vectored(&mut dst[n..]) + n } diff --git a/src/proto/h1/mod.rs b/src/proto/h1/mod.rs index 0a442c4c7e..a17dbae83c 100644 --- a/src/proto/h1/mod.rs +++ b/src/proto/h1/mod.rs @@ -68,9 +68,9 @@ pub(crate) struct ParsedMessage { wants_upgrade: bool, } -pub(crate) struct ParseContext<'a> { - cached_headers: &'a mut Option, - req_method: &'a mut Option, +pub(crate) struct ParseContext<'ctx> { + cached_headers: &'ctx mut Option, + req_method: &'ctx mut Option, h1_parser_config: ParserConfig, h1_max_headers: Option, preserve_header_case: bool, @@ -78,16 +78,16 @@ pub(crate) struct ParseContext<'a> { preserve_header_order: bool, h09_responses: bool, #[cfg(feature = "client")] - on_informational: &'a mut Option, + on_informational: &'ctx mut Option, } /// Passed to `Http1Transaction::encode`. -pub(crate) struct Encode<'a, T> { - head: &'a mut MessageHead, +pub(crate) struct Encode<'encode, T> { + head: &'encode mut MessageHead, body: Option, #[cfg(feature = "server")] keep_alive: bool, - req_method: &'a mut Option, + req_method: &'encode mut Option, title_case_headers: bool, #[cfg(feature = "server")] date_header: bool, diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index 29bcd44b0d..d083d2a912 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -1652,7 +1652,7 @@ fn write_headers_original_case( } #[cfg(feature = "client")] -struct FastWrite<'a>(&'a mut Vec); +struct FastWrite<'data>(&'data mut Vec); #[cfg(feature = "client")] impl fmt::Write for FastWrite<'_> { diff --git a/src/proto/h2/mod.rs b/src/proto/h2/mod.rs index f0db9b64eb..393d4179ab 100644 --- a/src/proto/h2/mod.rs +++ b/src/proto/h2/mod.rs @@ -319,7 +319,7 @@ impl Buf for SendBuf { } } - fn chunks_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize { + fn chunks_vectored<'data>(&'data self, dst: &mut [IoSlice<'data>]) -> usize { match self { Self::Buf(b) => b.chunks_vectored(dst), Self::Cursor(c) => c.chunks_vectored(dst), diff --git a/src/rt/io.rs b/src/rt/io.rs index 447774c6c0..9e633e69e8 100644 --- a/src/rt/io.rs +++ b/src/rt/io.rs @@ -164,8 +164,8 @@ pub trait Write { /// It is undefined behavior to de-initialize any bytes from the uninitialized /// region, since it is merely unknown whether this region is uninitialized or /// not, and if part of it turns out to be initialized, it must stay initialized. -pub struct ReadBuf<'a> { - raw: &'a mut [MaybeUninit], +pub struct ReadBuf<'data> { + raw: &'data mut [MaybeUninit], filled: usize, init: usize, } @@ -227,8 +227,8 @@ pub struct ReadBuf<'a> { /// assert_eq!(read_buf.filled(), b"hello"); /// ``` #[derive(Debug)] -pub struct ReadBufCursor<'a> { - buf: &'a mut ReadBuf<'a>, +pub struct ReadBufCursor<'buf> { + buf: &'buf mut ReadBuf<'buf>, } impl<'data> ReadBuf<'data> { diff --git a/tests/server.rs b/tests/server.rs index 1843610e88..098ed7a6ee 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -3542,8 +3542,8 @@ impl Serve { type BoxError = Box; type BoxFuture = Pin, BoxError>> + Send>>; -struct ReplyBuilder<'a> { - tx: &'a Mutex>, +struct ReplyBuilder<'mtx> { + tx: &'mtx Mutex>, } impl ReplyBuilder<'_> { From 36e2d786a7f9217a2a707e88cff9e0468b74a2f5 Mon Sep 17 00:00:00 2001 From: dox4 <61588545+dox4@users.noreply.github.com> Date: Sat, 29 Aug 2026 01:47:20 +0800 Subject: [PATCH 2/3] Update src/client/dispatch.rs Co-authored-by: katelyn martin --- src/client/dispatch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index d107804f22..a9375f627a 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -408,7 +408,7 @@ mod tests { } /// Helper to check if the future is ready after polling once. - struct PollOnce<'func, F>(&'func mut F); + struct PollOnce<'fut, F>(&'fut mut F); impl Future for PollOnce<'_, F> where From 98b4bd190295484eb9830b9e963680174427b406 Mon Sep 17 00:00:00 2001 From: dox4 Date: Sat, 29 Aug 2026 07:54:52 +0800 Subject: [PATCH 3/3] style: run rustfmt --edition 2021 --- src/ffi/task.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ffi/task.rs b/src/ffi/task.rs index 296cd9507e..b02de525ac 100644 --- a/src/ffi/task.rs +++ b/src/ffi/task.rs @@ -511,7 +511,9 @@ where // ===== impl hyper_context ===== impl hyper_context<'_> { - pub(crate) fn wrap<'borrow, 'ctx>(cx: &'borrow mut Context<'ctx>) -> &'borrow mut hyper_context<'ctx> { + pub(crate) fn wrap<'borrow, 'ctx>( + cx: &'borrow mut Context<'ctx>, + ) -> &'borrow mut hyper_context<'ctx> { // A struct with only one field has the same layout as that field. unsafe { std::mem::transmute::<&mut Context<'_>, &mut hyper_context<'_>>(cx) } }