From 4cafe25fcdb0fb06d657da3767ee900a6cdab929 Mon Sep 17 00:00:00 2001 From: Lee Bradley Date: Sun, 27 Feb 2022 23:04:09 -0600 Subject: [PATCH] Fix clippy warnings for Rust 1.59 --- src/iter.rs | 8 ++++---- src/lib.rs | 11 +++++++---- src/simd/avx2.rs | 6 +++--- src/simd/sse42.rs | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/iter.rs b/src/iter.rs index d4c7e1c..14bc519 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -9,7 +9,7 @@ impl<'a> Bytes<'a> { #[inline] pub fn new(slice: &'a [u8]) -> Bytes<'a> { Bytes { - slice: slice, + slice, pos: 0 } } @@ -26,7 +26,7 @@ impl<'a> Bytes<'a> { #[inline] pub unsafe fn bump(&mut self) { - debug_assert!(self.pos + 1 <= self.slice.len(), "overflow"); + debug_assert!(self.pos < self.slice.len(), "overflow"); self.pos += 1; } @@ -56,7 +56,7 @@ impl<'a> Bytes<'a> { let head_pos = self.pos - skip; let ptr = self.slice.as_ptr(); let head = slice::from_raw_parts(ptr, head_pos); - let tail = slice::from_raw_parts(ptr.offset(self.pos as isize), self.slice.len() - self.pos); + let tail = slice::from_raw_parts(ptr.add(self.pos), self.slice.len() - self.pos); self.pos = 0; self.slice = tail; head @@ -137,7 +137,7 @@ impl<'a, 'b: 'a> Bytes8<'a, 'b> { #[inline] fn new(bytes: &'a mut Bytes<'b>) -> Bytes8<'a, 'b> { Bytes8 { - bytes: bytes, + bytes, pos: 0, } } diff --git a/src/lib.rs b/src/lib.rs index 1057e20..cf41f07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -358,7 +358,7 @@ impl<'h, 'b> Request<'h, 'b> { method: None, path: None, version: None, - headers: headers, + headers, } } @@ -395,6 +395,7 @@ impl<'h, 'b> Request<'h, 'b> { /// /// Returns byte offset in `buf` to start of HTTP body. pub fn parse(&mut self, buf: &'b [u8]) -> Result { + #[allow(clippy::mem_replace_with_default)] let headers = mem::replace(&mut self.headers, &mut []); /* SAFETY: see `parse_headers_iter_uninit` guarantees */ @@ -461,7 +462,7 @@ impl<'h, 'b> Response<'h, 'b> { version: None, code: None, reason: None, - headers: headers, + headers, } } @@ -471,6 +472,7 @@ impl<'h, 'b> Response<'h, 'b> { } fn parse_with_config(&mut self, buf: &'b [u8], config: &ParserConfig) -> Result { + #[allow(clippy::mem_replace_with_default)] let headers = mem::replace(&mut self.headers, &mut []); unsafe { @@ -650,7 +652,7 @@ fn parse_reason<'a>(bytes: &mut Bytes<'a>) -> Result<&'a str> { "" } })); - } else if !(b == 0x09 || b == b' ' || (b >= 0x21 && b <= 0x7E) || b >= 0x80) { + } else if !(b == 0x09 || b == b' ' || (0x21..=0x7E).contains(&b) || b >= 0x80) { return Err(Error::Status); } else if b >= 0x80 { seen_obs_text = true; @@ -748,7 +750,7 @@ unsafe fn deinit_slice_mut<'a, 'b, T>(s: &'a mut &'b mut [T]) -> &'a mut &'b mut let s = s as *mut &mut [MaybeUninit]; &mut *s } -unsafe fn assume_init_slice<'a, T>(s: &'a mut [MaybeUninit]) -> &'a mut [T] { +unsafe fn assume_init_slice(s: &mut [MaybeUninit]) -> &mut [T] { let s: *mut [MaybeUninit] = s; let s = s as *mut [T]; &mut *s @@ -780,6 +782,7 @@ fn parse_headers_iter_uninit<'a, 'b>( impl<'r1, 'r2, 'a> Drop for ShrinkOnDrop<'r1, 'r2, 'a> { fn drop(&mut self) { + #[allow(clippy::mem_replace_with_default)] let headers = mem::replace(self.headers, &mut []); /* SAFETY: num_headers is the number of initialized headers */ diff --git a/src/simd/avx2.rs b/src/simd/avx2.rs index 89b76ba..ddf3ec8 100644 --- a/src/simd/avx2.rs +++ b/src/simd/avx2.rs @@ -8,7 +8,7 @@ pub enum Scan { } -pub unsafe fn parse_uri_batch_32<'a>(bytes: &mut Bytes<'a>) -> Scan { +pub unsafe fn parse_uri_batch_32(bytes: &mut Bytes) -> Scan { while bytes.as_ref().len() >= 32 { let advance = match_url_char_32_avx(bytes.as_ref()); bytes.advance(advance); @@ -59,7 +59,7 @@ unsafe fn match_url_char_32_avx(buf: &[u8]) -> usize { let bits = _mm256_and_si256(_mm256_shuffle_epi8(ARF, cols), rbms); let v = _mm256_cmpeq_epi8(bits, _mm256_setzero_si256()); - let r = 0xffffffff_00000000 | _mm256_movemask_epi8(v) as u64; + let r = 0xffff_ffff_0000_0000 | _mm256_movemask_epi8(v) as u64; _tzcnt_u64(r) as usize } @@ -109,7 +109,7 @@ unsafe fn match_header_value_char_32_avx(buf: &[u8]) -> usize { let del = _mm256_cmpeq_epi8(dat, DEL); let bit = _mm256_andnot_si256(del, _mm256_or_si256(low, tab)); let rev = _mm256_cmpeq_epi8(bit, _mm256_setzero_si256()); - let res = 0xffffffff_00000000 | _mm256_movemask_epi8(rev) as u64; + let res = 0xffff_ffff_0000_0000 | _mm256_movemask_epi8(rev) as u64; _tzcnt_u64(res) as usize } diff --git a/src/simd/sse42.rs b/src/simd/sse42.rs index d50eebe..284dc1b 100644 --- a/src/simd/sse42.rs +++ b/src/simd/sse42.rs @@ -1,6 +1,6 @@ use ::iter::Bytes; -pub unsafe fn parse_uri_batch_16<'a>(bytes: &mut Bytes<'a>) { +pub unsafe fn parse_uri_batch_16(bytes: &mut Bytes) { while bytes.as_ref().len() >= 16 { let advance = match_url_char_16_sse(bytes.as_ref()); bytes.advance(advance);