Skip to content

Commit

Permalink
Update MSRV from 1.36 to 1.47 also in clippy.toml. Fix related clippy…
Browse files Browse the repository at this point in the history
… issues. (#193)
  • Loading branch information
hkBst authored Dec 4, 2024
1 parent 390a6d3 commit 0e1b088
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.36"
msrv = "1.47"
4 changes: 2 additions & 2 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<'a> Bytes<'a> {
}
}

impl<'a> AsRef<[u8]> for Bytes<'a> {
impl AsRef<[u8]> for Bytes<'_> {
#[inline]
fn as_ref(&self) -> &[u8] {
// SAFETY: not moving position at all, so it's safe
Expand All @@ -172,7 +172,7 @@ unsafe fn slice_from_ptr_range<'a>(start: *const u8, end: *const u8) -> &'a [u8]
core::slice::from_raw_parts(start, end as usize - start as usize)
}

impl<'a> Iterator for Bytes<'a> {
impl Iterator for Bytes<'_> {
type Item = u8;

#[inline]
Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//! `-C target_cpu=native` allows the detection to become compile time checks,
//! making it *even* faster.
use core::{fmt, result, str};
use core::{fmt, mem, result, str};
use core::mem::MaybeUninit;

use crate::iter::Bytes;
Expand Down Expand Up @@ -375,7 +375,7 @@ impl ParserConfig {
/// let result = httparse::ParserConfig::default()
/// .allow_space_before_first_header_name(true)
/// .parse_response(&mut response, buf);
///
/// assert_eq!(result, Ok(httparse::Status::Complete(buf.len())));
/// assert_eq!(response.version.unwrap(), 1);
/// assert_eq!(response.code.unwrap(), 200);
Expand Down Expand Up @@ -580,7 +580,7 @@ impl<'h, 'b> Request<'h, 'b> {
}

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

/* SAFETY: see `parse_headers_iter_uninit` guarantees */
unsafe {
Expand Down Expand Up @@ -683,7 +683,7 @@ impl<'h, 'b> Response<'h, 'b> {
}

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

// SAFETY: see guarantees of [`parse_headers_iter_uninit`], which leaves no uninitialized
// headers around. On failure, the original headers are restored.
Expand Down Expand Up @@ -779,7 +779,7 @@ pub struct Header<'a> {
pub value: &'a [u8],
}

impl<'a> fmt::Debug for Header<'a> {
impl fmt::Debug for Header<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut f = f.debug_struct("Header");
f.field("name", &self.name);
Expand Down Expand Up @@ -967,10 +967,10 @@ pub fn parse_uri<'a>(bytes: &mut Bytes<'a>) -> Result<&'a str> {
return Err(Error::Token);
}

return Ok(Status::Complete(
Ok(Status::Complete(
// SAFETY: all bytes up till `i` must have been `is_method_token` and therefore also utf-8.
unsafe { str::from_utf8_unchecked(bytes.slice_skip(1)) },
));
))
} else {
Err(Error::Token)
}
Expand Down Expand Up @@ -1071,9 +1071,9 @@ fn parse_headers_iter_uninit<'a>(
num_headers: usize,
}

impl<'r1, 'r2, 'a> Drop for ShrinkOnDrop<'r1, 'r2, 'a> {
impl Drop for ShrinkOnDrop<'_, '_, '_> {
fn drop(&mut self) {
let headers = core::mem::replace(self.headers, &mut []);
let headers = mem::take(self.headers);

/* SAFETY: num_headers is the number of initialized headers */
let headers = unsafe { headers.get_unchecked_mut(..self.num_headers) };
Expand Down Expand Up @@ -1323,7 +1323,7 @@ pub fn parse_chunk_size(buf: &[u8])
return Err(InvalidChunkSize);
}
count += 1;
if cfg!(debug_assertions) && size > (core::u64::MAX / RADIX) {
if cfg!(debug_assertions) && size > (u64::MAX / RADIX) {
// actually unreachable!(), because count stops the loop at 15 digits before
// we can reach u64::MAX / RADIX == 0xfffffffffffffff, which requires 15 hex
// digits. This stops mirai reporting a false alarm regarding the `size *=
Expand All @@ -1338,7 +1338,7 @@ pub fn parse_chunk_size(buf: &[u8])
return Err(InvalidChunkSize);
}
count += 1;
if cfg!(debug_assertions) && size > (core::u64::MAX / RADIX) {
if cfg!(debug_assertions) && size > (u64::MAX / RADIX) {
return Err(InvalidChunkSize);
}
size *= RADIX;
Expand All @@ -1349,7 +1349,7 @@ pub fn parse_chunk_size(buf: &[u8])
return Err(InvalidChunkSize);
}
count += 1;
if cfg!(debug_assertions) && size > (core::u64::MAX / RADIX) {
if cfg!(debug_assertions) && size > (u64::MAX / RADIX) {
return Err(InvalidChunkSize);
}
size *= RADIX;
Expand Down Expand Up @@ -2057,7 +2057,7 @@ mod tests {
assert_eq!(parse_chunk_size(b"567f8a\rfoo"), Err(crate::InvalidChunkSize));
assert_eq!(parse_chunk_size(b"567f8a\rfoo"), Err(crate::InvalidChunkSize));
assert_eq!(parse_chunk_size(b"567xf8a\r\n"), Err(crate::InvalidChunkSize));
assert_eq!(parse_chunk_size(b"ffffffffffffffff\r\n"), Ok(Status::Complete((18, std::u64::MAX))));
assert_eq!(parse_chunk_size(b"ffffffffffffffff\r\n"), Ok(Status::Complete((18, u64::MAX))));
assert_eq!(parse_chunk_size(b"1ffffffffffffffff\r\n"), Err(crate::InvalidChunkSize));
assert_eq!(parse_chunk_size(b"Affffffffffffffff\r\n"), Err(crate::InvalidChunkSize));
assert_eq!(parse_chunk_size(b"fffffffffffffffff\r\n"), Err(crate::InvalidChunkSize));
Expand Down

0 comments on commit 0e1b088

Please sign in to comment.