Skip to content

Commit b80e89f

Browse files
committed
Fix/ignore clippy warnings
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
1 parent cc59a6b commit b80e89f

File tree

6 files changed

+40
-41
lines changed

6 files changed

+40
-41
lines changed

src/chunked.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ impl<R: Read + Unpin> ChunkedDecoder<R> {
115115
pending: false,
116116
})
117117
}
118-
Poll::Pending => {
119-
return Ok(DecodeResult::Some {
120-
read: 0,
121-
new_state: Some(State::Chunk(new_current, len)),
122-
new_pos,
123-
buffer,
124-
pending: true,
125-
});
126-
}
118+
Poll::Pending => Ok(DecodeResult::Some {
119+
read: 0,
120+
new_state: Some(State::Chunk(new_current, len)),
121+
new_pos,
122+
buffer,
123+
pending: true,
124+
}),
127125
}
128126
}
129127

src/client.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,9 @@ where
207207
}
208208

209209
// Check for Content-Length.
210-
match content_length {
211-
Some(len) => {
212-
let len = len.last().unwrap().as_str().parse::<usize>()?;
213-
res.set_body(Body::from_reader(reader.take(len as u64), Some(len)));
214-
}
215-
None => {}
210+
if let Some(len) = content_length {
211+
let len = len.last().unwrap().as_str().parse::<usize>()?;
212+
res.set_body(Body::from_reader(reader.take(len as u64), Some(len)));
216213
}
217214

218215
// Return the response.
@@ -231,7 +228,7 @@ impl Read for Encoder {
231228
if !self.headers_done {
232229
let len = std::cmp::min(self.headers.len() - self.cursor, buf.len());
233230
let range = self.cursor..self.cursor + len;
234-
buf[0..len].copy_from_slice(&mut self.headers[range]);
231+
buf[0..len].copy_from_slice(&self.headers[range]);
235232
self.cursor += len;
236233
if self.cursor == self.headers.len() {
237234
self.headers_done = true;

src/date.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(crate) fn fmt_http_date(d: SystemTime) -> String {
5151
}
5252

5353
impl HttpDate {
54-
fn is_valid(&self) -> bool {
54+
fn is_valid(self) -> bool {
5555
self.second < 60
5656
&& self.minute < 60
5757
&& self.hour < 24
@@ -160,8 +160,8 @@ fn parse_rfc850_date(s: &[u8]) -> http_types::Result<HttpDate> {
160160
b"-Dec-" => 12,
161161
_ => bail!("Invalid month"),
162162
},
163-
year: year,
164-
week_day: week_day,
163+
year,
164+
week_day,
165165
})
166166
}
167167

@@ -407,7 +407,7 @@ impl PartialOrd for HttpDate {
407407
}
408408

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

413413
#[cfg(test)]

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
#![deny(missing_debug_implementations, nonstandard_style)]
9696
#![warn(missing_docs, missing_doc_code_examples, unreachable_pub)]
9797
#![cfg_attr(test, deny(warnings))]
98+
#![allow(clippy::if_same_then_else)]
99+
#![allow(clippy::len_zero)]
100+
#![allow(clippy::match_bool)]
101+
#![allow(clippy::unreadable_literal)]
98102

99103
/// The maximum amount of headers parsed on the server.
100104
const MAX_HEADERS: usize = 128;

src/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646
let req = match timeout(timeout_duration, decode(addr, io.clone())).await {
4747
Ok(Ok(Some(r))) => r,
4848
Ok(Ok(None)) | Err(TimeoutError { .. }) => break, /* EOF or timeout */
49-
Ok(Err(e)) => return Err(e).into(),
49+
Ok(Err(e)) => return Err(e),
5050
};
5151

5252
// Pass the request to the endpoint and encode the response.

tests/common/mod.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,21 @@ impl TestCase {
3939
) -> TestCase {
4040
let request_fixture = File::open(fixture_path(&request_file_path))
4141
.await
42-
.expect(&format!(
43-
"Could not open request fixture file: {:?}",
44-
&fixture_path(request_file_path)
45-
));
46-
47-
let response_fixture =
48-
File::open(fixture_path(&response_file_path))
49-
.await
50-
.expect(&format!(
42+
.unwrap_or_else(|_| {
43+
panic!(
44+
"Could not open request fixture file: {:?}",
45+
&fixture_path(request_file_path)
46+
)
47+
});
48+
49+
let response_fixture = File::open(fixture_path(&response_file_path))
50+
.await
51+
.unwrap_or_else(|_| {
52+
panic!(
5153
"Could not open response fixture file: {:?}",
5254
&fixture_path(response_file_path)
53-
));
55+
)
56+
});
5457

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

109112
pub(crate) fn munge_date(expected: &mut String, actual: &mut String) {
110-
match expected.find("{DATE}") {
111-
Some(i) => {
112-
println!("{}", expected);
113-
match actual.find("date: ") {
114-
Some(j) => {
115-
let eol = actual[j + 6..].find("\r\n").expect("missing eol");
116-
expected.replace_range(i..i + 6, &actual[j + 6..j + 6 + eol]);
117-
}
118-
None => expected.replace_range(i..i + 6, ""),
113+
if let Some(i) = expected.find("{DATE}") {
114+
println!("{}", expected);
115+
match actual.find("date: ") {
116+
Some(j) => {
117+
let eol = actual[j + 6..].find("\r\n").expect("missing eol");
118+
expected.replace_range(i..i + 6, &actual[j + 6..j + 6 + eol]);
119119
}
120+
None => expected.replace_range(i..i + 6, ""),
120121
}
121-
None => {}
122122
}
123123
}
124124

0 commit comments

Comments
 (0)