From 4969f72a76f4867f40ff9bd4345357e124babc1c Mon Sep 17 00:00:00 2001 From: tottoto Date: Mon, 24 Nov 2025 09:37:35 +0900 Subject: [PATCH 1/6] refactor(lib): remove needless lifetime parameter --- src/header/map.rs | 16 ++++++++-------- src/header/name.rs | 4 ++-- src/header/value.rs | 8 ++++---- src/method.rs | 4 ++-- src/uri/authority.rs | 4 ++-- src/uri/mod.rs | 2 +- src/uri/path.rs | 4 ++-- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/header/map.rs b/src/header/map.rs index af6b623b..59faf676 100644 --- a/src/header/map.rs +++ b/src/header/map.rs @@ -3758,7 +3758,7 @@ mod into_header_name { impl IntoHeaderName for HeaderName {} - impl<'a> Sealed for &'a HeaderName { + impl Sealed for &HeaderName { #[inline] fn try_insert( self, @@ -3778,7 +3778,7 @@ mod into_header_name { } } - impl<'a> IntoHeaderName for &'a HeaderName {} + impl IntoHeaderName for &HeaderName {} impl Sealed for &'static str { #[inline] @@ -3868,7 +3868,7 @@ mod as_header_name { impl AsHeaderName for HeaderName {} - impl<'a> Sealed for &'a HeaderName { + impl Sealed for &HeaderName { #[inline] fn try_entry(self, map: &mut HeaderMap) -> Result, TryEntryError> { Ok(map.try_entry2(self)?) @@ -3884,9 +3884,9 @@ mod as_header_name { } } - impl<'a> AsHeaderName for &'a HeaderName {} + impl AsHeaderName for &HeaderName {} - impl<'a> Sealed for &'a str { + impl Sealed for &str { #[inline] fn try_entry(self, map: &mut HeaderMap) -> Result, TryEntryError> { Ok(HdrName::from_bytes(self.as_bytes(), move |hdr| { @@ -3904,7 +3904,7 @@ mod as_header_name { } } - impl<'a> AsHeaderName for &'a str {} + impl AsHeaderName for &str {} impl Sealed for String { #[inline] @@ -3924,7 +3924,7 @@ mod as_header_name { impl AsHeaderName for String {} - impl<'a> Sealed for &'a String { + impl Sealed for &String { #[inline] fn try_entry(self, map: &mut HeaderMap) -> Result, TryEntryError> { self.as_str().try_entry(map) @@ -3940,7 +3940,7 @@ mod as_header_name { } } - impl<'a> AsHeaderName for &'a String {} + impl AsHeaderName for &String {} } #[test] diff --git a/src/header/name.rs b/src/header/name.rs index 1b4a39d6..f2436e45 100644 --- a/src/header/name.rs +++ b/src/header/name.rs @@ -1412,7 +1412,7 @@ impl<'a> PartialEq<&'a HeaderName> for HeaderName { } } -impl<'a> PartialEq for &'a HeaderName { +impl PartialEq for &HeaderName { #[inline] fn eq(&self, other: &HeaderName) -> bool { *other == *self @@ -1466,7 +1466,7 @@ impl<'a> PartialEq<&'a str> for HeaderName { } } -impl<'a> PartialEq for &'a str { +impl PartialEq for &str { /// Performs a case-insensitive comparison of the string against the header /// name #[inline] diff --git a/src/header/value.rs b/src/header/value.rs index 48308cb4..fdadc62b 100644 --- a/src/header/value.rs +++ b/src/header/value.rs @@ -697,14 +697,14 @@ impl PartialOrd for String { } } -impl<'a> PartialEq for &'a HeaderValue { +impl PartialEq for &HeaderValue { #[inline] fn eq(&self, other: &HeaderValue) -> bool { **self == *other } } -impl<'a> PartialOrd for &'a HeaderValue { +impl PartialOrd for &HeaderValue { #[inline] fn partial_cmp(&self, other: &HeaderValue) -> Option { (**self).partial_cmp(other) @@ -731,14 +731,14 @@ where } } -impl<'a> PartialEq for &'a str { +impl PartialEq for &str { #[inline] fn eq(&self, other: &HeaderValue) -> bool { *other == *self } } -impl<'a> PartialOrd for &'a str { +impl PartialOrd for &str { #[inline] fn partial_cmp(&self, other: &HeaderValue) -> Option { self.as_bytes().partial_cmp(other.as_bytes()) diff --git a/src/method.rs b/src/method.rs index 7b4584ab..2567b739 100644 --- a/src/method.rs +++ b/src/method.rs @@ -194,7 +194,7 @@ impl<'a> PartialEq<&'a Method> for Method { } } -impl<'a> PartialEq for &'a Method { +impl PartialEq for &Method { #[inline] fn eq(&self, other: &Method) -> bool { *self == other @@ -222,7 +222,7 @@ impl<'a> PartialEq<&'a str> for Method { } } -impl<'a> PartialEq for &'a str { +impl PartialEq for &str { #[inline] fn eq(&self, other: &Method) -> bool { *self == other.as_ref() diff --git a/src/uri/authority.rs b/src/uri/authority.rs index 67754e45..ddeb33c2 100644 --- a/src/uri/authority.rs +++ b/src/uri/authority.rs @@ -244,7 +244,7 @@ impl PartialEq for str { } } -impl<'a> PartialEq for &'a str { +impl PartialEq for &str { fn eq(&self, other: &Authority) -> bool { self.eq_ignore_ascii_case(other.as_str()) } @@ -302,7 +302,7 @@ impl PartialOrd for str { } } -impl<'a> PartialOrd for &'a str { +impl PartialOrd for &str { fn partial_cmp(&self, other: &Authority) -> Option { let left = self.as_bytes().iter().map(|b| b.to_ascii_lowercase()); let right = other.data.as_bytes().iter().map(|b| b.to_ascii_lowercase()); diff --git a/src/uri/mod.rs b/src/uri/mod.rs index 767f0743..ff9908e9 100644 --- a/src/uri/mod.rs +++ b/src/uri/mod.rs @@ -1001,7 +1001,7 @@ impl<'a> PartialEq<&'a str> for Uri { } } -impl<'a> PartialEq for &'a str { +impl PartialEq for &str { fn eq(&self, uri: &Uri) -> bool { uri == *self } diff --git a/src/uri/path.rs b/src/uri/path.rs index 8f9356e8..5d06ea80 100644 --- a/src/uri/path.rs +++ b/src/uri/path.rs @@ -395,7 +395,7 @@ impl PartialEq for PathAndQuery { } } -impl<'a> PartialEq for &'a str { +impl PartialEq for &str { #[inline] fn eq(&self, other: &PathAndQuery) -> bool { self == &other.as_str() @@ -458,7 +458,7 @@ impl<'a> PartialOrd<&'a str> for PathAndQuery { } } -impl<'a> PartialOrd for &'a str { +impl PartialOrd for &str { #[inline] fn partial_cmp(&self, other: &PathAndQuery) -> Option { self.partial_cmp(&other.as_str()) From f53cb5e16ac226f9f62c3188781486abb1311965 Mon Sep 17 00:00:00 2001 From: tottoto Date: Mon, 24 Nov 2025 09:39:55 +0900 Subject: [PATCH 2/6] refactor(header): remove needless maybe sized bound --- src/header/map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/header/map.rs b/src/header/map.rs index 59faf676..24b307dc 100644 --- a/src/header/map.rs +++ b/src/header/map.rs @@ -1497,7 +1497,7 @@ impl HeaderMap { #[inline] fn find(&self, key: &K) -> Option<(usize, usize)> where - K: Hash + Into + ?Sized, + K: Hash + Into, HeaderName: PartialEq, { if self.entries.is_empty() { From 07da81ccbf1d3b5ef721a35e31fe01efca086506 Mon Sep 17 00:00:00 2001 From: tottoto Date: Mon, 24 Nov 2025 09:43:07 +0900 Subject: [PATCH 3/6] refactor(tests): replace deprecated numeric api with primitive one --- src/header/value.rs | 2 +- tests/header_map.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/header/value.rs b/src/header/value.rs index fdadc62b..934e4756 100644 --- a/src/header/value.rs +++ b/src/header/value.rs @@ -411,7 +411,7 @@ macro_rules! from_integers { let val = HeaderValue::from(n); assert_eq!(val, &n.to_string()); - let n = ::std::$t::MAX; + let n = $t::MAX; let val = HeaderValue::from(n); assert_eq!(val, &n.to_string()); } diff --git a/tests/header_map.rs b/tests/header_map.rs index 9a9d7e12..3dfbf25d 100644 --- a/tests/header_map.rs +++ b/tests/header_map.rs @@ -60,7 +60,7 @@ fn with_capacity_overflow() { fn reserve_overflow() { // See https://github.com/hyperium/http/issues/352 let mut headers = HeaderMap::::with_capacity(0); - headers.reserve(std::usize::MAX); // next_power_of_two overflows + headers.reserve(usize::MAX); // next_power_of_two overflows } #[test] From 04c9805f75d252703891a99232124d30ff3d113a Mon Sep 17 00:00:00 2001 From: tottoto Date: Mon, 24 Nov 2025 09:47:00 +0900 Subject: [PATCH 4/6] refactor(tests): remove unnecessary converting to string --- src/uri/authority.rs | 8 ++++---- src/uri/path.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/uri/authority.rs b/src/uri/authority.rs index ddeb33c2..4ca07e23 100644 --- a/src/uri/authority.rs +++ b/src/uri/authority.rs @@ -660,10 +660,10 @@ mod tests { #[test] fn compares_with_a_string() { let authority: Authority = "def.com".parse().unwrap(); - assert!(authority < "ghi.com".to_string()); - assert!("ghi.com".to_string() > authority); - assert!(authority > "abc.com".to_string()); - assert!("abc.com".to_string() < authority); + assert!(authority < "ghi.com"); + assert!("ghi.com" > authority); + assert!(authority > "abc.com"); + assert!("abc.com" < authority); } #[test] diff --git a/src/uri/path.rs b/src/uri/path.rs index 5d06ea80..4a8b2bdb 100644 --- a/src/uri/path.rs +++ b/src/uri/path.rs @@ -620,10 +620,10 @@ mod tests { #[test] fn compares_with_a_string() { let path_and_query: PathAndQuery = "/b/world&foo=bar".parse().unwrap(); - assert!(path_and_query < "/c/world&foo=bar".to_string()); - assert!("/c/world&foo=bar".to_string() > path_and_query); - assert!(path_and_query > "/a/world&foo=bar".to_string()); - assert!("/a/world&foo=bar".to_string() < path_and_query); + assert!(path_and_query < "/c/world&foo=bar"); + assert!("/c/world&foo=bar" > path_and_query); + assert!(path_and_query > "/a/world&foo=bar"); + assert!("/a/world&foo=bar" < path_and_query); } #[test] From 3dfb7cd3e5fce1ca5cd57d8cde0dbb7ea36110f0 Mon Sep 17 00:00:00 2001 From: tottoto Date: Mon, 24 Nov 2025 09:52:24 +0900 Subject: [PATCH 5/6] refactor(tests): use infallible api to get HeaderValue from HeaderName --- src/header/value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/header/value.rs b/src/header/value.rs index 934e4756..9e751a6a 100644 --- a/src/header/value.rs +++ b/src/header/value.rs @@ -543,7 +543,7 @@ mod try_from_header_name_tests { #[test] fn it_converts_using_try_from() { assert_eq!( - HeaderValue::try_from(name::UPGRADE).unwrap(), + HeaderValue::from(name::UPGRADE), HeaderValue::from_bytes(b"upgrade").unwrap() ); } From 03514a606f3afc0c8782f75d8f9aaa19387554c4 Mon Sep 17 00:00:00 2001 From: tottoto Date: Mon, 24 Nov 2025 09:58:22 +0900 Subject: [PATCH 6/6] refactor(tests): use lazy evaluation on error message --- src/uri/path.rs | 2 +- src/uri/scheme.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uri/path.rs b/src/uri/path.rs index 4a8b2bdb..39a0db14 100644 --- a/src/uri/path.rs +++ b/src/uri/path.rs @@ -671,6 +671,6 @@ mod tests { } fn pq(s: &str) -> PathAndQuery { - s.parse().expect(&format!("parsing {}", s)) + s.parse().unwrap_or_else(|_| panic!("parsing {s}")) } } diff --git a/src/uri/scheme.rs b/src/uri/scheme.rs index dbcc8c3f..47a8bb1c 100644 --- a/src/uri/scheme.rs +++ b/src/uri/scheme.rs @@ -356,6 +356,6 @@ mod test { } fn scheme(s: &str) -> Scheme { - s.parse().expect(&format!("Invalid scheme: {}", s)) + s.parse().unwrap_or_else(|_| panic!("Invalid scheme: {s}")) } }