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.
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ pub fn add_header(headers: &mut Vec<Header>, 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]
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,10 +82,10 @@ pub struct TestHeaders(Vec<String>);
|
||||
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),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
|
||||
Reference in New Issue
Block a user