seanmonstar / httparse

A push parser for the HTTP 1.x protocol in Rust.
https://docs.rs/httparse
Apache License 2.0
569 stars 110 forks source link

Fix clippy warnings for Rust 1.59 #108

Closed ameliabradley closed 2 years ago

ameliabradley commented 2 years ago

For reference, this was the clippy output:

warning: redundant field names in struct initialization
  --> src/iter.rs:12:13
   |
12 |             slice: slice,
   |             ^^^^^^^^^^^^ help: replace it with: `slice`
   |
   = note: `#[warn(clippy::redundant_field_names)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names

warning: unnecessary `>= y + 1` or `x - 1 >=`
  --> src/iter.rs:29:23
   |
29 |         debug_assert!(self.pos + 1 <= self.slice.len(), "overflow");
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change it to: `self.pos < self.slice.len()`
   |
   = note: `#[warn(clippy::int_plus_one)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one

warning: redundant field names in struct initialization
   --> src/iter.rs:140:13
    |
140 |             bytes: bytes,
    |             ^^^^^^^^^^^^ help: replace it with: `bytes`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names

warning: digits of hex or binary literal not grouped by four
  --> src/simd/avx2.rs:62:13
   |
62 |     let r = 0xffffffff_00000000 | _mm256_movemask_epi8(v) as u64;
   |             ^^^^^^^^^^^^^^^^^^^ help: consider: `0xffff_ffff_0000_0000`
   |
   = note: `#[warn(clippy::unusual_byte_groupings)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings

warning: digits of hex or binary literal not grouped by four
   --> src/simd/avx2.rs:112:15
    |
112 |     let res = 0xffffffff_00000000 | _mm256_movemask_epi8(rev) as u64;
    |               ^^^^^^^^^^^^^^^^^^^ help: consider: `0xffff_ffff_0000_0000`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings

warning: redundant field names in struct initialization
   --> src/lib.rs:361:13
    |
361 |             headers: headers,
    |             ^^^^^^^^^^^^^^^^ help: replace it with: `headers`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names

warning: redundant field names in struct initialization
   --> src/lib.rs:464:13
    |
464 |             headers: headers,
    |             ^^^^^^^^^^^^^^^^ help: replace it with: `headers`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names

warning: use of `offset` with a `usize` casted to an `isize`
  --> src/iter.rs:59:42
   |
59 |         let tail = slice::from_raw_parts(ptr.offset(self.pos as isize), self.slice.len() - self.pos);
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(self.pos)`
   |
   = note: `#[warn(clippy::ptr_offset_with_cast)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast

warning: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
 --> src/simd/sse42.rs:3:1
  |
3 | pub unsafe fn parse_uri_batch_16<'a>(bytes: &mut Bytes<'a>) {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(clippy::needless_lifetimes)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes

warning: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
  --> src/simd/avx2.rs:11:1
   |
11 | pub unsafe fn parse_uri_batch_32<'a>(bytes: &mut Bytes<'a>) -> Scan {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes

warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
   --> src/lib.rs:398:23
    |
398 |         let headers = mem::replace(&mut self.headers, &mut []);
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut self.headers)`
    |
    = note: `#[warn(clippy::mem_replace_with_default)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default

warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
   --> src/lib.rs:474:23
    |
474 |         let headers = mem::replace(&mut self.headers, &mut []);
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut self.headers)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default

warning: manual `RangeInclusive::contains` implementation
   --> src/lib.rs:653:47
    |
653 |         } else if !(b == 0x09 || b == b' ' || (b >= 0x21 && b <= 0x7E) || b >= 0x80) {
    |                                               ^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(0x21..=0x7E).contains(&b)`
    |
    = note: `#[warn(clippy::manual_range_contains)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains

warning: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
   --> src/lib.rs:751:1
    |
751 | unsafe fn assume_init_slice<'a, T>(s: &'a mut [MaybeUninit<T>]) -> &'a mut [T] {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes

warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
   --> src/lib.rs:783:27
    |
783 |             let headers = mem::replace(self.headers, &mut []);
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(self.headers)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default

warning: `httparse` (lib) generated 15 warnings
seanmonstar commented 2 years ago

Hey, thanks for making these fixes! It looks like some of the things clippy suggests to do can't be done without requiring a newer rustc version. Hence, the Minimum Supported Rust Version (MSRV) test fails.

ameliabradley commented 2 years ago

@seanmonstar Ah, I didn't see the minimum supported Rust version. That makes sense. Updated the changes to tell clippy to ignore those lines. Let me know if you'd like this addressed in some other manner.

seanmonstar commented 2 years ago

This is just my personal preference, but I prefer that code doesn't include attributes mentioning clippy. The rest of the cleanups look great, though!

ameliabradley commented 2 years ago

@seanmonstar Cool! I've removed the clippy attributes.