Fix clippy warnings

Fix linter warning from clippy about unnecessary borrows - "This expression borrows a reference ... that is immediately dereferenced by the compiler"
This commit is contained in:
Niketh Murali
2021-08-11 03:10:06 +05:30
committed by Martin Algesten
parent eb04d96af8
commit 4665b0aa5a
6 changed files with 15 additions and 15 deletions

View File

@@ -134,7 +134,7 @@ fn copy_chunked<R: Read, W: Write>(reader: &mut R, writer: &mut W) -> io::Result
let header = header_str.as_bytes(); let header = header_str.as_bytes();
assert!(header.len() <= CHUNK_HEADER_MAX_SIZE); assert!(header.len() <= CHUNK_HEADER_MAX_SIZE);
let start_index = CHUNK_HEADER_MAX_SIZE - header.len(); let start_index = CHUNK_HEADER_MAX_SIZE - header.len();
(&mut chunk[start_index..]).write_all(&header).unwrap(); (&mut chunk[start_index..]).write_all(header).unwrap();
// And add the footer // And add the footer
chunk.extend_from_slice(b"\r\n"); chunk.extend_from_slice(b"\r\n");

View File

@@ -113,7 +113,7 @@ impl ConnectionPool {
// Remove the newest matching PoolKey from self.lru. That // Remove the newest matching PoolKey from self.lru. That
// corresponds to the stream we just removed from `recycle`. // corresponds to the stream we just removed from `recycle`.
remove_last_match(&mut inner.lru, &key) remove_last_match(&mut inner.lru, key)
.expect("invariant failed: key in recycle but not in lru"); .expect("invariant failed: key in recycle but not in lru");
debug!("pulling stream from pool: {:?} -> {:?}", key, stream); debug!("pulling stream from pool: {:?} -> {:?}", key, stream);

View File

@@ -134,7 +134,7 @@ impl Response {
/// The HTTP spec allows for non-utf8 status texts. This uses from_utf8_lossy to /// The HTTP spec allows for non-utf8 status texts. This uses from_utf8_lossy to
/// convert such lines to &str. /// convert such lines to &str.
pub fn status_text(&self) -> &str { pub fn status_text(&self) -> &str {
&self.status_line.as_str()[self.index.response_code + 1..].trim() self.status_line.as_str()[self.index.response_code + 1..].trim()
} }
/// The header value for the given name, or None if not found. /// The header value for the given name, or None if not found.

View File

@@ -209,7 +209,7 @@ impl Stream {
match self.inner.get_ref() { match self.inner.get_ref() {
Inner::Http(b) => Some(b), Inner::Http(b) => Some(b),
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
Inner::Https(b) => Some(&b.get_ref()), Inner::Https(b) => Some(b.get_ref()),
_ => None, _ => None,
} }
} }
@@ -365,7 +365,7 @@ pub(crate) fn connect_https(unit: &Unit, hostname: &str) -> Result<Stream, Error
.map(|c| &c.0) .map(|c| &c.0)
.unwrap_or(&*TLS_CONF); .unwrap_or(&*TLS_CONF);
let mut sock = connect_host(unit, hostname, port)?; let mut sock = connect_host(unit, hostname, port)?;
let mut sess = rustls::ClientSession::new(&tls_conf, sni); let mut sess = rustls::ClientSession::new(tls_conf, sni);
sess.complete_io(&mut sock) sess.complete_io(&mut sock)
.map_err(|err| ErrorKind::ConnectionFailed.new().src(err))?; .map_err(|err| ErrorKind::ConnectionFailed.new().src(err))?;
@@ -413,7 +413,7 @@ pub(crate) fn connect_host(unit: &Unit, hostname: &str, port: u16) -> Result<Tcp
// connect with a configured timeout. // connect with a configured timeout.
let stream = if Some(Proto::SOCKS5) == proto { let stream = if Some(Proto::SOCKS5) == proto {
connect_socks5( connect_socks5(
&unit, unit,
proxy.clone().unwrap(), proxy.clone().unwrap(),
connect_deadline, connect_deadline,
sock_addr, sock_addr,

View File

@@ -85,7 +85,7 @@ impl TestHeaders {
if self.0.is_empty() { if self.0.is_empty() {
"" ""
} else { } else {
&self.0[0].split(' ').nth(1).unwrap() self.0[0].split(' ').nth(1).unwrap()
} }
} }

View File

@@ -42,7 +42,7 @@ impl Unit {
) -> Self { ) -> Self {
// //
let (is_transfer_encoding_set, mut is_chunked) = get_header(&headers, "transfer-encoding") let (is_transfer_encoding_set, mut is_chunked) = get_header(headers, "transfer-encoding")
// if the user has set an encoding header, obey that. // if the user has set an encoding header, obey that.
.map(|enc| { .map(|enc| {
let is_transfer_encoding_set = !enc.is_empty(); let is_transfer_encoding_set = !enc.is_empty();
@@ -60,7 +60,7 @@ impl Unit {
// chunking and Content-Length headers are mutually exclusive // chunking and Content-Length headers are mutually exclusive
// also don't write this if the user has set it themselves // also don't write this if the user has set it themselves
if !is_chunked && get_header(&headers, "content-length").is_none() { if !is_chunked && get_header(headers, "content-length").is_none() {
// if the payload is of known size (everything beside an unsized reader), set // if the payload is of known size (everything beside an unsized reader), set
// Content-Length, // Content-Length,
// otherwise, use the chunked Transfer-Encoding (only if no other Transfer-Encoding // otherwise, use the chunked Transfer-Encoding (only if no other Transfer-Encoding
@@ -82,7 +82,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.is_empty() || !password.is_empty()) if (!username.is_empty() || !password.is_empty())
&& get_header(&headers, "authorization").is_none() && 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)));
@@ -236,7 +236,7 @@ fn connect_inner(
let url = &unit.url; let url = &unit.url;
let method = &unit.method; let method = &unit.method;
// open socket // open socket
let (mut stream, is_recycled) = connect_socket(&unit, &host, use_pooled)?; let (mut stream, is_recycled) = connect_socket(unit, host, use_pooled)?;
if is_recycled { if is_recycled {
info!("sending request (reused connection) {} {}", method, url); info!("sending request (reused connection) {} {}", method, url);
@@ -244,7 +244,7 @@ fn connect_inner(
info!("sending request {} {}", method, url); info!("sending request {} {}", method, url);
} }
let send_result = send_prelude(&unit, &mut stream, !previous.is_empty()); let send_result = send_prelude(unit, &mut stream, !previous.is_empty());
if let Err(err) = send_result { if let Err(err) = send_result {
if is_recycled { if is_recycled {
@@ -343,9 +343,9 @@ fn connect_socket(unit: &Unit, hostname: &str, use_pooled: bool) -> Result<(Stre
} }
} }
let stream = match unit.url.scheme() { let stream = match unit.url.scheme() {
"http" => stream::connect_http(&unit, hostname), "http" => stream::connect_http(unit, hostname),
"https" => stream::connect_https(&unit, hostname), "https" => stream::connect_https(unit, hostname),
"test" => connect_test(&unit), "test" => connect_test(unit),
scheme => Err(ErrorKind::UnknownScheme.msg(&format!("unknown scheme {}", scheme))), scheme => Err(ErrorKind::UnknownScheme.msg(&format!("unknown scheme {}", scheme))),
}; };
Ok((stream?, false)) Ok((stream?, false))