From f0245aad23b64da830b172751902d2b4e5e5927b Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 3 Jan 2021 23:10:43 -0500 Subject: [PATCH] Fix some clippy lints (#292) This commit can be replicated with `cargo +nightly clippy --fix -Z unstable-options`, plus an edit to fix another `return` missed by clippy. --- src/error.rs | 2 +- src/header.rs | 2 +- src/lib.rs | 8 ++++---- src/pool.rs | 6 +++--- src/response.rs | 4 ++-- src/testserver.rs | 6 +++--- src/unit.rs | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/error.rs b/src/error.rs index 3317e44..5d1ab2c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -182,7 +182,7 @@ impl Error { pub fn kind(&self) -> ErrorKind { match self { Error::Status(_, _) => ErrorKind::HTTP, - Error::Transport(Transport { kind: k, .. }) => k.clone(), + Error::Transport(Transport { kind: k, .. }) => *k, } } diff --git a/src/header.rs b/src/header.rs index 038a0b0..74cdde1 100644 --- a/src/header.rs +++ b/src/header.rs @@ -85,7 +85,7 @@ pub fn add_header(headers: &mut Vec
, header: Header) { // tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / // "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA fn valid_name(name: &str) -> bool { - name.len() > 0 && name.bytes().all(is_tchar) + !name.is_empty() && name.bytes().all(is_tchar) } #[inline] diff --git a/src/lib.rs b/src/lib.rs index 16850d6..570cfb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -279,19 +279,19 @@ pub fn is_test(is: bool) -> bool { IS_TEST.store(true, Ordering::SeqCst); } let x = IS_TEST.load(Ordering::SeqCst); - return x; + x } /// Agents are used to hold configuration and keep state between requests. pub fn agent() -> Agent { #[cfg(not(test))] if is_test(false) { - return testserver::test_agent(); + testserver::test_agent() } else { - return AgentBuilder::new().build(); + AgentBuilder::new().build() } #[cfg(test)] - return testserver::test_agent(); + testserver::test_agent() } /// Make a request with the HTTP verb as a parameter. diff --git a/src/pool.rs b/src/pool.rs index f1311ce..bc20475 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -107,7 +107,7 @@ impl ConnectionPool { let stream = streams.pop_back(); let stream = stream.expect("invariant failed: empty VecDeque in `recycle`"); - if streams.len() == 0 { + if streams.is_empty() { occupied_entry.remove(); } @@ -172,7 +172,7 @@ impl ConnectionPool { .pop_front() .expect("invariant failed: key existed in recycle but no streams available"); debug!("dropping oldest stream in pool: {:?}", stream); - if streams.len() == 0 { + if streams.is_empty() { occupied_entry.remove(); } } @@ -214,7 +214,7 @@ impl PoolKey { scheme: url.scheme().to_string(), hostname: url.host_str().unwrap_or("").to_string(), port, - proxy: proxy, + proxy, } } } diff --git a/src/response.rs b/src/response.rs index 227f5b4..07df455 100644 --- a/src/response.rs +++ b/src/response.rs @@ -414,7 +414,7 @@ impl Response { // // HTTP/1.1 200 OK\r\n let mut stream = - stream::DeadlineStream::new(stream, unit.as_ref().and_then(|u| u.deadline.clone())); + stream::DeadlineStream::new(stream, unit.as_ref().and_then(|u| u.deadline)); let status_line = read_next_line(&mut stream)?; let (index, status) = parse_status_line(status_line.as_str())?; @@ -559,7 +559,7 @@ impl<'a> Iterator for Hist<'a> { }; self.response = response.previous.as_deref(); - return Some(response); + Some(response) } } diff --git a/src/testserver.rs b/src/testserver.rs index d1f3d37..8261fd8 100644 --- a/src/testserver.rs +++ b/src/testserver.rs @@ -82,10 +82,10 @@ pub struct TestHeaders(Vec); impl TestHeaders { // Return the path for a request, e.g. /foo from "GET /foo HTTP/1.1" pub fn path(&self) -> &str { - if self.0.len() == 0 { + if self.0.is_empty() { "" } else { - &self.0[0].split(" ").nth(1).unwrap() + &self.0[0].split(' ').nth(1).unwrap() } } @@ -105,7 +105,7 @@ pub fn read_request(stream: &TcpStream) -> TestHeaders { eprintln!("testserver: in read_request: {}", e); break; } - Ok(line) if line == "" => break, + Ok(line) if line.is_empty() => break, Ok(line) => results.push(line), }; } diff --git a/src/unit.rs b/src/unit.rs index 22e6ce3..2fa1fa2 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -83,7 +83,7 @@ impl Unit { let username = url.username(); let password = url.password().unwrap_or(""); - if (username != "" || password != "") && get_header(&headers, "authorization").is_none() + if (!username.is_empty() || !password.is_empty()) && get_header(&headers, "authorization").is_none() { let encoded = base64::encode(&format!("{}:{}", username, password)); extra.push(Header::new("Authorization", &format!("Basic {}", encoded)));