Skip to content

Commit

Permalink
Fix/ignore clippy warnings
Browse files Browse the repository at this point in the history
Clippy has some warnings for us.  For some of them, fixing the code
improves things.  For others, making clippy happy would make the code
worse (or in one case, even break compilation [1]).  Let's fix the
ones worth fixing, and for the others, let's tell clippy to ignore
them.

[1] rust-lang/rust-clippy#3807
  • Loading branch information
traviscross committed Mar 25, 2020
1 parent cc59a6b commit b80e89f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 41 deletions.
16 changes: 7 additions & 9 deletions src/chunked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,13 @@ impl<R: Read + Unpin> ChunkedDecoder<R> {
pending: false,
})
}
Poll::Pending => {
return Ok(DecodeResult::Some {
read: 0,
new_state: Some(State::Chunk(new_current, len)),
new_pos,
buffer,
pending: true,
});
}
Poll::Pending => Ok(DecodeResult::Some {
read: 0,
new_state: Some(State::Chunk(new_current, len)),
new_pos,
buffer,
pending: true,
}),
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,9 @@ where
}

// Check for Content-Length.
match content_length {
Some(len) => {
let len = len.last().unwrap().as_str().parse::<usize>()?;
res.set_body(Body::from_reader(reader.take(len as u64), Some(len)));
}
None => {}
if let Some(len) = content_length {
let len = len.last().unwrap().as_str().parse::<usize>()?;
res.set_body(Body::from_reader(reader.take(len as u64), Some(len)));
}

// Return the response.
Expand All @@ -231,7 +228,7 @@ impl Read for Encoder {
if !self.headers_done {
let len = std::cmp::min(self.headers.len() - self.cursor, buf.len());
let range = self.cursor..self.cursor + len;
buf[0..len].copy_from_slice(&mut self.headers[range]);
buf[0..len].copy_from_slice(&self.headers[range]);
self.cursor += len;
if self.cursor == self.headers.len() {
self.headers_done = true;
Expand Down
8 changes: 4 additions & 4 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) fn fmt_http_date(d: SystemTime) -> String {
}

impl HttpDate {
fn is_valid(&self) -> bool {
fn is_valid(self) -> bool {
self.second < 60
&& self.minute < 60
&& self.hour < 24
Expand Down Expand Up @@ -160,8 +160,8 @@ fn parse_rfc850_date(s: &[u8]) -> http_types::Result<HttpDate> {
b"-Dec-" => 12,
_ => bail!("Invalid month"),
},
year: year,
week_day: week_day,
year,
week_day,
})
}

Expand Down Expand Up @@ -407,7 +407,7 @@ impl PartialOrd for HttpDate {
}

fn is_leap_year(year: u16) -> bool {
year % 4 == 0 && (!(year % 100 == 0) || year % 400 == 0)
year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
#![deny(missing_debug_implementations, nonstandard_style)]
#![warn(missing_docs, missing_doc_code_examples, unreachable_pub)]
#![cfg_attr(test, deny(warnings))]
#![allow(clippy::if_same_then_else)]
#![allow(clippy::len_zero)]
#![allow(clippy::match_bool)]
#![allow(clippy::unreadable_literal)]

/// The maximum amount of headers parsed on the server.
const MAX_HEADERS: usize = 128;
Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
let req = match timeout(timeout_duration, decode(addr, io.clone())).await {
Ok(Ok(Some(r))) => r,
Ok(Ok(None)) | Err(TimeoutError { .. }) => break, /* EOF or timeout */
Ok(Err(e)) => return Err(e).into(),
Ok(Err(e)) => return Err(e),
};

// Pass the request to the endpoint and encode the response.
Expand Down
40 changes: 20 additions & 20 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ impl TestCase {
) -> TestCase {
let request_fixture = File::open(fixture_path(&request_file_path))
.await
.expect(&format!(
"Could not open request fixture file: {:?}",
&fixture_path(request_file_path)
));

let response_fixture =
File::open(fixture_path(&response_file_path))
.await
.expect(&format!(
.unwrap_or_else(|_| {
panic!(
"Could not open request fixture file: {:?}",
&fixture_path(request_file_path)
)
});

let response_fixture = File::open(fixture_path(&response_file_path))
.await
.unwrap_or_else(|_| {
panic!(
"Could not open response fixture file: {:?}",
&fixture_path(response_file_path)
));
)
});

let temp = tempfile::tempfile().expect("Failed to create tempfile");
let result = Arc::new(Mutex::new(temp.into()));
Expand Down Expand Up @@ -107,18 +110,15 @@ pub(crate) fn fixture_path(relative_path: &str) -> PathBuf {
}

pub(crate) fn munge_date(expected: &mut String, actual: &mut String) {
match expected.find("{DATE}") {
Some(i) => {
println!("{}", expected);
match actual.find("date: ") {
Some(j) => {
let eol = actual[j + 6..].find("\r\n").expect("missing eol");
expected.replace_range(i..i + 6, &actual[j + 6..j + 6 + eol]);
}
None => expected.replace_range(i..i + 6, ""),
if let Some(i) = expected.find("{DATE}") {
println!("{}", expected);
match actual.find("date: ") {
Some(j) => {
let eol = actual[j + 6..].find("\r\n").expect("missing eol");
expected.replace_range(i..i + 6, &actual[j + 6..j + 6 + eol]);
}
None => expected.replace_range(i..i + 6, ""),
}
None => {}
}
}

Expand Down

0 comments on commit b80e89f

Please sign in to comment.