From 7d5b71d6dd3460f93d7e9c9a9097f618c62970eb Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 4 May 2024 11:26:18 +0900 Subject: [PATCH 1/5] refactor(lib): replace deprecated numeric api with primitive one --- src/header/map.rs | 2 +- src/uri/mod.rs | 2 +- src/uri/path.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/header/map.rs b/src/header/map.rs index e1960a0c..86255777 100644 --- a/src/header/map.rs +++ b/src/header/map.rs @@ -1066,7 +1066,7 @@ impl HeaderMap { } else { ValueIter { map: self, - index: ::std::usize::MAX, + index: usize::MAX, front: None, back: None, } diff --git a/src/uri/mod.rs b/src/uri/mod.rs index 6ef2dc8e..767f0743 100644 --- a/src/uri/mod.rs +++ b/src/uri/mod.rs @@ -28,9 +28,9 @@ use std::convert::TryFrom; use bytes::Bytes; use std::error::Error; +use std::fmt; use std::hash::{Hash, Hasher}; use std::str::{self, FromStr}; -use std::{fmt, u16, u8}; use self::scheme::Scheme2; diff --git a/src/uri/path.rs b/src/uri/path.rs index 341ba2e6..6a2f1e1e 100644 --- a/src/uri/path.rs +++ b/src/uri/path.rs @@ -14,7 +14,7 @@ pub struct PathAndQuery { pub(super) query: u16, } -const NONE: u16 = ::std::u16::MAX; +const NONE: u16 = u16::MAX; impl PathAndQuery { // Not public while `bytes` is unstable. From 21d861feed7a3721b1e4927b497e6531f0c3309d Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 4 May 2024 11:27:59 +0900 Subject: [PATCH 2/5] refactor(header): refactor redundant closure style --- src/header/map.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/header/map.rs b/src/header/map.rs index 86255777..ee989ffe 100644 --- a/src/header/map.rs +++ b/src/header/map.rs @@ -705,12 +705,12 @@ impl HeaderMap { .entries .len() .checked_add(additional) - .ok_or_else(|| MaxSizeReached::new())?; + .ok_or_else(MaxSizeReached::new)?; if cap > self.indices.len() { let cap = cap .checked_next_power_of_two() - .ok_or_else(|| MaxSizeReached::new())?; + .ok_or_else(MaxSizeReached::new)?; if cap > MAX_SIZE { return Err(MaxSizeReached::new()); } From 9d319b1ea955929a025e735a931cc972fb649ef1 Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 4 May 2024 11:29:15 +0900 Subject: [PATCH 3/5] refactor(header): remove redundant result handling --- 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 ee989ffe..0b5beb3d 100644 --- a/src/header/map.rs +++ b/src/header/map.rs @@ -3838,7 +3838,7 @@ mod as_header_name { impl Sealed for String { #[inline] fn try_entry(self, map: &mut HeaderMap) -> Result, TryEntryError> { - Ok(self.as_str().try_entry(map)?) + self.as_str().try_entry(map) } #[inline] From d9dc9b374e21d9394857ef45a97f70796557197d Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 4 May 2024 11:31:26 +0900 Subject: [PATCH 4/5] refactor(header): remove multiple bound location --- src/header/map.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/header/map.rs b/src/header/map.rs index 0b5beb3d..a668b311 100644 --- a/src/header/map.rs +++ b/src/header/map.rs @@ -1449,9 +1449,9 @@ impl HeaderMap { } #[inline] - fn find(&self, key: &K) -> Option<(usize, usize)> + fn find(&self, key: &K) -> Option<(usize, usize)> where - K: Hash + Into, + K: Hash + Into + ?Sized, HeaderName: PartialEq, { if self.entries.is_empty() { @@ -3603,9 +3603,9 @@ fn probe_distance(mask: Size, hash: HashValue, current: usize) -> usize { current.wrapping_sub(desired_pos(mask, hash)) & mask as usize } -fn hash_elem_using(danger: &Danger, k: &K) -> HashValue +fn hash_elem_using(danger: &Danger, k: &K) -> HashValue where - K: Hash, + K: Hash + ?Sized, { use fnv::FnvHasher; From 038c483339e11232e3d6b05900da24978f8b84fa Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 4 May 2024 11:34:01 +0900 Subject: [PATCH 5/5] refactor(header): allow clippy::out_of_bounds_indexing to panic in const context workaround --- src/header/name.rs | 2 +- src/header/value.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/header/name.rs b/src/header/name.rs index 64a276ae..41320262 100644 --- a/src/header/name.rs +++ b/src/header/name.rs @@ -1274,7 +1274,7 @@ impl HeaderName { // https://blog.rust-lang.org/2021/12/02/Rust-1.57.0.html#panic-in-const-contexts // // See the panics section of this method's document for details. - #[allow(clippy::no_effect)] + #[allow(clippy::no_effect, clippy::out_of_bounds_indexing)] ([] as [u8; 0])[0]; // Invalid header name } diff --git a/src/header/value.rs b/src/header/value.rs index b7978cac..4813f6fd 100644 --- a/src/header/value.rs +++ b/src/header/value.rs @@ -91,7 +91,7 @@ impl HeaderValue { // https://blog.rust-lang.org/2021/12/02/Rust-1.57.0.html#panic-in-const-contexts // // See the panics section of this method's document for details. - #[allow(clippy::no_effect)] + #[allow(clippy::no_effect, clippy::out_of_bounds_indexing)] ([] as [u8; 0])[0]; // Invalid header value } i += 1;