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 {
|
pub fn kind(&self) -> ErrorKind {
|
||||||
match self {
|
match self {
|
||||||
Error::Status(_, _) => ErrorKind::HTTP,
|
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 = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
|
// tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
|
||||||
// "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
|
// "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
|
||||||
fn valid_name(name: &str) -> bool {
|
fn valid_name(name: &str) -> bool {
|
||||||
name.len() > 0 && name.bytes().all(is_tchar)
|
!name.is_empty() && name.bytes().all(is_tchar)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -279,19 +279,19 @@ pub fn is_test(is: bool) -> bool {
|
|||||||
IS_TEST.store(true, Ordering::SeqCst);
|
IS_TEST.store(true, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
let x = IS_TEST.load(Ordering::SeqCst);
|
let x = IS_TEST.load(Ordering::SeqCst);
|
||||||
return x;
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Agents are used to hold configuration and keep state between requests.
|
/// Agents are used to hold configuration and keep state between requests.
|
||||||
pub fn agent() -> Agent {
|
pub fn agent() -> Agent {
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
if is_test(false) {
|
if is_test(false) {
|
||||||
return testserver::test_agent();
|
testserver::test_agent()
|
||||||
} else {
|
} else {
|
||||||
return AgentBuilder::new().build();
|
AgentBuilder::new().build()
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
return testserver::test_agent();
|
testserver::test_agent()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make a request with the HTTP verb as a parameter.
|
/// Make a request with the HTTP verb as a parameter.
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ impl ConnectionPool {
|
|||||||
let stream = streams.pop_back();
|
let stream = streams.pop_back();
|
||||||
let stream = stream.expect("invariant failed: empty VecDeque in `recycle`");
|
let stream = stream.expect("invariant failed: empty VecDeque in `recycle`");
|
||||||
|
|
||||||
if streams.len() == 0 {
|
if streams.is_empty() {
|
||||||
occupied_entry.remove();
|
occupied_entry.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ impl ConnectionPool {
|
|||||||
.pop_front()
|
.pop_front()
|
||||||
.expect("invariant failed: key existed in recycle but no streams available");
|
.expect("invariant failed: key existed in recycle but no streams available");
|
||||||
debug!("dropping oldest stream in pool: {:?}", stream);
|
debug!("dropping oldest stream in pool: {:?}", stream);
|
||||||
if streams.len() == 0 {
|
if streams.is_empty() {
|
||||||
occupied_entry.remove();
|
occupied_entry.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,7 @@ impl PoolKey {
|
|||||||
scheme: url.scheme().to_string(),
|
scheme: url.scheme().to_string(),
|
||||||
hostname: url.host_str().unwrap_or("").to_string(),
|
hostname: url.host_str().unwrap_or("").to_string(),
|
||||||
port,
|
port,
|
||||||
proxy: proxy,
|
proxy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -414,7 +414,7 @@ impl Response {
|
|||||||
//
|
//
|
||||||
// HTTP/1.1 200 OK\r\n
|
// HTTP/1.1 200 OK\r\n
|
||||||
let mut stream =
|
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 status_line = read_next_line(&mut stream)?;
|
||||||
|
|
||||||
let (index, status) = parse_status_line(status_line.as_str())?;
|
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();
|
self.response = response.previous.as_deref();
|
||||||
return Some(response);
|
Some(response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,10 +82,10 @@ pub struct TestHeaders(Vec<String>);
|
|||||||
impl TestHeaders {
|
impl TestHeaders {
|
||||||
// Return the path for a request, e.g. /foo from "GET /foo HTTP/1.1"
|
// Return the path for a request, e.g. /foo from "GET /foo HTTP/1.1"
|
||||||
pub fn path(&self) -> &str {
|
pub fn path(&self) -> &str {
|
||||||
if self.0.len() == 0 {
|
if self.0.is_empty() {
|
||||||
""
|
""
|
||||||
} else {
|
} 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);
|
eprintln!("testserver: in read_request: {}", e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(line) if line == "" => break,
|
Ok(line) if line.is_empty() => break,
|
||||||
Ok(line) => results.push(line),
|
Ok(line) => results.push(line),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ impl Unit {
|
|||||||
|
|
||||||
let username = url.username();
|
let username = url.username();
|
||||||
let password = url.password().unwrap_or("");
|
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));
|
let encoded = base64::encode(&format!("{}:{}", username, password));
|
||||||
extra.push(Header::new("Authorization", &format!("Basic {}", encoded)));
|
extra.push(Header::new("Authorization", &format!("Basic {}", encoded)));
|
||||||
|
|||||||
Reference in New Issue
Block a user