Skip to content

Commit

Permalink
Fix clippy warnings for Rust 1.59
Browse files Browse the repository at this point in the history
  • Loading branch information
ameliabradley authored and Lee Bradley committed Feb 28, 2022
1 parent 284923a commit 4cafe25
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl<'a> Bytes<'a> {
#[inline]
pub fn new(slice: &'a [u8]) -> Bytes<'a> {
Bytes {
slice: slice,
slice,
pos: 0
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl<'h, 'b> Request<'h, 'b> {
method: None,
path: None,
version: None,
headers: headers,
headers,
}
}

Expand Down Expand Up @@ -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<usize> {
#[allow(clippy::mem_replace_with_default)]
let headers = mem::replace(&mut self.headers, &mut []);

/* SAFETY: see `parse_headers_iter_uninit` guarantees */
Expand Down Expand Up @@ -461,7 +462,7 @@ impl<'h, 'b> Response<'h, 'b> {
version: None,
code: None,
reason: None,
headers: headers,
headers,
}
}

Expand All @@ -471,6 +472,7 @@ impl<'h, 'b> Response<'h, 'b> {
}

fn parse_with_config(&mut self, buf: &'b [u8], config: &ParserConfig) -> Result<usize> {
#[allow(clippy::mem_replace_with_default)]
let headers = mem::replace(&mut self.headers, &mut []);

unsafe {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<T>];
&mut *s
}
unsafe fn assume_init_slice<'a, T>(s: &'a mut [MaybeUninit<T>]) -> &'a mut [T] {
unsafe fn assume_init_slice<T>(s: &mut [MaybeUninit<T>]) -> &mut [T] {
let s: *mut [MaybeUninit<T>] = s;
let s = s as *mut [T];
&mut *s
Expand Down Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions src/simd/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/simd/sse42.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 4cafe25

Please sign in to comment.