From 0eaf304644a396895a4ce1f0146e596640bb666a Mon Sep 17 00:00:00 2001
From: danieleades <33452915+danieleades@users.noreply.github.com>
Date: Fri, 3 Jan 2020 17:40:32 +0000
Subject: [PATCH] style(lib): address most clippy lints
---
benches/end_to_end.rs | 4 +-
benches/server.rs | 4 +-
examples/multi_server.rs | 4 +-
examples/send_file.rs | 2 +-
examples/tower_server.rs | 2 +-
src/body/body.rs | 14 ++----
src/body/payload.rs | 3 +-
src/client/conn.rs | 10 ++---
src/client/connect/http.rs | 16 +++----
src/client/dispatch.rs | 9 ++--
src/client/mod.rs | 10 ++---
src/client/pool.rs | 6 +--
src/common/buf.rs | 5 +--
src/common/io/rewind.rs | 4 +-
src/common/lazy.rs | 5 +--
src/headers.rs | 2 +-
src/proto/h1/conn.rs | 56 +++++++++++-------------
src/proto/h1/dispatch.rs | 12 +++---
src/proto/h1/encode.rs | 4 +-
src/proto/h1/io.rs | 88 +++++++++++++++++---------------------
src/proto/h1/role.rs | 13 +++---
src/proto/h2/client.rs | 7 +--
src/proto/h2/mod.rs | 34 +++++++--------
src/proto/h2/server.rs | 6 +--
src/server/conn.rs | 6 +--
src/server/tcp.rs | 2 +-
tests/client.rs | 12 +++---
tests/server.rs | 18 ++++----
tests/support/mod.rs | 4 +-
29 files changed, 162 insertions(+), 200 deletions(-)
diff --git a/benches/end_to_end.rs b/benches/end_to_end.rs
index 281852d8..a122cfce 100644
--- a/benches/end_to_end.rs
+++ b/benches/end_to_end.rs
@@ -292,7 +292,7 @@ impl Opts {
} else {
self.request_body
.map(Body::from)
- .unwrap_or_else(|| Body::empty())
+ .unwrap_or_else(Body::empty)
};
let mut req = Request::new(body);
*req.method_mut() = self.request_method.clone();
@@ -355,5 +355,5 @@ fn spawn_server(rt: &mut tokio::runtime::Runtime, opts: &Opts) -> SocketAddr {
panic!("server error: {}", err);
}
});
- return addr;
+ addr
}
diff --git a/benches/server.rs b/benches/server.rs
index 44e23deb..d524ecdd 100644
--- a/benches/server.rs
+++ b/benches/server.rs
@@ -105,7 +105,7 @@ fn throughput_fixedsize_large_payload(b: &mut test::Bencher) {
#[bench]
fn throughput_fixedsize_many_chunks(b: &mut test::Bencher) {
bench_server!(b, ("content-length", "1000000"), || {
- static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
+ static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
Body::wrap_stream(stream::iter(S.iter()).map(|&s| Ok::<_, String>(s)))
})
}
@@ -127,7 +127,7 @@ fn throughput_chunked_large_payload(b: &mut test::Bencher) {
#[bench]
fn throughput_chunked_many_chunks(b: &mut test::Bencher) {
bench_server!(b, ("transfer-encoding", "chunked"), || {
- static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
+ static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
Body::wrap_stream(stream::iter(S.iter()).map(|&s| Ok::<_, String>(s)))
})
}
diff --git a/examples/multi_server.rs b/examples/multi_server.rs
index 936f6951..f599324d 100644
--- a/examples/multi_server.rs
+++ b/examples/multi_server.rs
@@ -5,8 +5,8 @@ use futures_util::future::join;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
-static INDEX1: &'static [u8] = b"The 1st service!";
-static INDEX2: &'static [u8] = b"The 2nd service!";
+static INDEX1: &[u8] = b"The 1st service!";
+static INDEX2: &[u8] = b"The 2nd service!";
async fn index1(_: Request
) -> Result, hyper::Error> {
Ok(Response::new(Body::from(INDEX1)))
diff --git a/examples/send_file.rs b/examples/send_file.rs
index 010d190d..b98b1468 100644
--- a/examples/send_file.rs
+++ b/examples/send_file.rs
@@ -71,5 +71,5 @@ async fn simple_file_send(filename: &str) -> Result> {
return Ok(internal_server_error());
}
- return Ok(not_found());
+ Ok(not_found())
}
diff --git a/examples/tower_server.rs b/examples/tower_server.rs
index 27510c88..95414876 100644
--- a/examples/tower_server.rs
+++ b/examples/tower_server.rs
@@ -6,7 +6,7 @@ use futures_util::future;
use hyper::service::Service;
use hyper::{Body, Request, Response, Server};
-const ROOT: &'static str = "/";
+const ROOT: &str = "/";
#[derive(Debug)]
pub struct Svc;
diff --git a/src/body/body.rs b/src/body/body.rs
index deb2db67..166b4203 100644
--- a/src/body/body.rs
+++ b/src/body/body.rs
@@ -112,10 +112,7 @@ impl Body {
let (tx, rx) = mpsc::channel(0);
let (abort_tx, abort_rx) = oneshot::channel();
- let tx = Sender {
- abort_tx: abort_tx,
- tx: tx,
- };
+ let tx = Sender { abort_tx, tx };
let rx = Body::new(Kind::Chan {
content_length,
abort_rx,
@@ -131,7 +128,6 @@ impl Body {
///
/// ```
/// # use hyper::Body;
- /// # fn main() {
/// let chunks: Vec> = vec
/// to work with this function; or use the `without_shutdown` wrapper.
pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll> {
- match self.inner.as_mut().expect("already upgraded") {
- &mut ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
- &mut ProtoClient::H2(ref mut h2) => Pin::new(h2).poll(cx).map_ok(|_| ()),
+ match *self.inner.as_mut().expect("already upgraded") {
+ ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
+ ProtoClient::H2(ref mut h2) => Pin::new(h2).poll(cx).map_ok(|_| ()),
}
}
diff --git a/src/client/connect/http.rs b/src/client/connect/http.rs
index 8c50d725..3e342d19 100644
--- a/src/client/connect/http.rs
+++ b/src/client/connect/http.rs
@@ -542,7 +542,7 @@ impl ConnectingTcpRemote {
}
}
- return Err(err.take().expect("missing connect error"));
+ Err(err.take().expect("missing connect error"))
}
}
@@ -552,9 +552,9 @@ fn connect(
reuse_address: bool,
connect_timeout: Option,
) -> io::Result>> {
- let builder = match addr {
- &SocketAddr::V4(_) => TcpBuilder::new_v4()?,
- &SocketAddr::V6(_) => TcpBuilder::new_v6()?,
+ let builder = match *addr {
+ SocketAddr::V4(_) => TcpBuilder::new_v4()?,
+ SocketAddr::V6(_) => TcpBuilder::new_v6()?,
};
if reuse_address {
@@ -566,9 +566,9 @@ fn connect(
builder.bind(SocketAddr::new(local_addr.clone(), 0))?;
} else if cfg!(windows) {
// Windows requires a socket be bound before calling connect
- let any: SocketAddr = match addr {
- &SocketAddr::V4(_) => ([0, 0, 0, 0], 0).into(),
- &SocketAddr::V6(_) => ([0, 0, 0, 0, 0, 0, 0, 0], 0).into(),
+ let any: SocketAddr = match *addr {
+ SocketAddr::V4(_) => ([0, 0, 0, 0], 0).into(),
+ SocketAddr::V6(_) => ([0, 0, 0, 0, 0, 0, 0, 0], 0).into(),
};
builder.bind(any)?;
}
@@ -619,7 +619,7 @@ impl ConnectingTcp {
}
};
- if let Err(_) = result {
+ if result.is_err() {
// Fallback to the remaining future (could be preferred or fallback)
// if we get an error
future.await
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs
index 5ab8a257..d28007df 100644
--- a/src/client/dispatch.rs
+++ b/src/client/dispatch.rs
@@ -12,13 +12,10 @@ pub fn channel() -> (Sender, Receiver) {
let (giver, taker) = want::new();
let tx = Sender {
buffered_once: false,
- giver: giver,
+ giver,
inner: tx,
};
- let rx = Receiver {
- inner: rx,
- taker: taker,
- };
+ let rx = Receiver { inner: rx, taker };
(tx, rx)
}
@@ -183,7 +180,7 @@ struct Envelope(Option<(T, Callback)>);
impl Drop for Envelope {
fn drop(&mut self) {
if let Some((val, cb)) = self.0.take() {
- let _ = cb.send(Err((
+ cb.send(Err((
crate::Error::new_canceled().with("connection closed"),
Some(val),
)));
diff --git a/src/client/mod.rs b/src/client/mod.rs
index d4c69820..1071de2f 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -210,7 +210,7 @@ where
/// # fn main() {}
/// ```
pub fn request(&self, mut req: Request) -> ResponseFuture {
- let is_http_connect = req.method() == &Method::CONNECT;
+ let is_http_connect = req.method() == Method::CONNECT;
match req.version() {
Version::HTTP_11 => (),
Version::HTTP_10 => {
@@ -237,7 +237,7 @@ where
}
};
- let pool_key = Arc::new(domain.to_string());
+ let pool_key = Arc::new(domain);
ResponseFuture::new(Box::new(self.retryably_send_request(req, pool_key)))
}
@@ -302,14 +302,14 @@ where
}
// CONNECT always sends authority-form, so check it first...
- if req.method() == &Method::CONNECT {
+ if req.method() == Method::CONNECT {
authority_form(req.uri_mut());
} else if pooled.conn_info.is_proxied {
absolute_form(req.uri_mut());
} else {
origin_form(req.uri_mut());
};
- } else if req.method() == &Method::CONNECT {
+ } else if req.method() == Method::CONNECT {
debug!("client does not support CONNECT requests over HTTP2");
return Either::Left(future::err(ClientError::Normal(
crate::Error::new_user_unsupported_request_method(),
@@ -422,7 +422,7 @@ where
});
// An execute error here isn't important, we're just trying
// to prevent a waste of a socket...
- let _ = executor.execute(bg);
+ executor.execute(bg);
}
Either::Left(future::ok(checked_out))
}
diff --git a/src/client/pool.rs b/src/client/pool.rs
index 274ae242..a9f3991c 100644
--- a/src/client/pool.rs
+++ b/src/client/pool.rs
@@ -352,7 +352,7 @@ impl PoolInner {
Some(value) => {
// borrow-check scope...
{
- let idle_list = self.idle.entry(key.clone()).or_insert(Vec::new());
+ let idle_list = self.idle.entry(key.clone()).or_insert_with(Vec::new);
if self.max_idle_per_host <= idle_list.len() {
trace!("max idle per host for {:?}, dropping connection", key);
return;
@@ -360,7 +360,7 @@ impl PoolInner {
debug!("pooling idle connection for {:?}", key);
idle_list.push(Idle {
- value: value,
+ value,
idle_at: Instant::now(),
});
}
@@ -610,7 +610,7 @@ impl Checkout {
inner
.waiters
.entry(self.key.clone())
- .or_insert(VecDeque::new())
+ .or_insert_with(VecDeque::new)
.push_back(tx);
// register the waker with this oneshot
diff --git a/src/common/buf.rs b/src/common/buf.rs
index 4de4d947..8f71b7bb 100644
--- a/src/common/buf.rs
+++ b/src/common/buf.rs
@@ -34,10 +34,7 @@ impl Buf for BufList {
#[inline]
fn bytes(&self) -> &[u8] {
- for buf in &self.bufs {
- return buf.bytes();
- }
- &[]
+ self.bufs.front().map(Buf::bytes).unwrap_or_default()
}
#[inline]
diff --git a/src/common/io/rewind.rs b/src/common/io/rewind.rs
index 322ee3f0..14650697 100644
--- a/src/common/io/rewind.rs
+++ b/src/common/io/rewind.rs
@@ -58,11 +58,11 @@ where
) -> Poll> {
if let Some(mut prefix) = self.pre.take() {
// If there are no remaining bytes, let the bytes get dropped.
- if prefix.len() > 0 {
+ if !prefix.is_empty() {
let copy_len = cmp::min(prefix.len(), buf.len());
prefix.copy_to_slice(&mut buf[..copy_len]);
// Put back whats left
- if prefix.len() > 0 {
+ if !prefix.is_empty() {
self.pre = Some(prefix);
}
diff --git a/src/common/lazy.rs b/src/common/lazy.rs
index 67359d26..4d2e322c 100644
--- a/src/common/lazy.rs
+++ b/src/common/lazy.rs
@@ -49,9 +49,8 @@ where
type Output = R::Output;
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll {
- match self.inner {
- Inner::Fut(ref mut f) => return Pin::new(f).poll(cx),
- _ => (),
+ if let Inner::Fut(ref mut f) = self.inner {
+ return Pin::new(f).poll(cx);
}
match mem::replace(&mut self.inner, Inner::Empty) {
diff --git a/src/headers.rs b/src/headers.rs
index 33084114..5375e782 100644
--- a/src/headers.rs
+++ b/src/headers.rs
@@ -96,7 +96,7 @@ pub fn is_chunked_(value: &HeaderValue) -> bool {
}
pub fn add_chunked(mut entry: OccupiedEntry<'_, HeaderValue>) {
- const CHUNKED: &'static str = "chunked";
+ const CHUNKED: &str = "chunked";
if let Some(line) = entry.iter_mut().next_back() {
// + 2 for ", "
diff --git a/src/proto/h1/conn.rs b/src/proto/h1/conn.rs
index 1b0f60e4..3022529e 100644
--- a/src/proto/h1/conn.rs
+++ b/src/proto/h1/conn.rs
@@ -13,7 +13,7 @@ use crate::common::{task, Pin, Poll, Unpin};
use crate::headers::connection_keep_alive;
use crate::proto::{BodyLength, DecodedLength, MessageHead};
-const H2_PREFACE: &'static [u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
+const H2_PREFACE: &[u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
/// This handles a connection, which will have been established over an
/// `AsyncRead + AsyncWrite` (like a socket), and will likely include multiple
@@ -391,9 +391,8 @@ where
pub fn can_write_head(&self) -> bool {
if !T::should_read_first() {
- match self.state.reading {
- Reading::Closed => return false,
- _ => {}
+ if let Reading::Closed = self.state.reading {
+ return false;
}
}
match self.state.writing {
@@ -486,7 +485,7 @@ where
let outgoing_is_keep_alive = head
.headers
.get(CONNECTION)
- .and_then(|value| Some(connection_keep_alive(value)))
+ .map(connection_keep_alive)
.unwrap_or(false);
if !outgoing_is_keep_alive {
@@ -510,20 +509,16 @@ where
// If we know the remote speaks an older version, we try to fix up any messages
// to work with our older peer.
fn enforce_version(&mut self, head: &mut MessageHead) {
- match self.state.version {
- Version::HTTP_10 => {
- // Fixes response or connection when keep-alive header is not present
- self.fix_keep_alive(head);
- // If the remote only knows HTTP/1.0, we should force ourselves
- // to do only speak HTTP/1.0 as well.
- head.version = Version::HTTP_10;
- }
- _ => {
- // If the remote speaks HTTP/1.1, then it *should* be fine with
- // both HTTP/1.0 and HTTP/1.1 from us. So again, we just let
- // the user's headers be.
- }
+ if let Version::HTTP_10 = self.state.version {
+ // Fixes response or connection when keep-alive header is not present
+ self.fix_keep_alive(head);
+ // If the remote only knows HTTP/1.0, we should force ourselves
+ // to do only speak HTTP/1.0 as well.
+ head.version = Version::HTTP_10;
}
+ // If the remote speaks HTTP/1.1, then it *should* be fine with
+ // both HTTP/1.0 and HTTP/1.1 from us. So again, we just let
+ // the user's headers be.
}
pub fn write_body(&mut self, chunk: B) {
@@ -603,21 +598,18 @@ where
// - Client: there is nothing we can do
// - Server: if Response hasn't been written yet, we can send a 4xx response
fn on_parse_error(&mut self, err: crate::Error) -> crate::Result<()> {
- match self.state.writing {
- Writing::Init => {
- if self.has_h2_prefix() {
- return Err(crate::Error::new_version_h2());
- }
- if let Some(msg) = T::on_error(&err) {
- // Drop the cached headers so as to not trigger a debug
- // assert in `write_head`...
- self.state.cached_headers.take();
- self.write_head(msg, None);
- self.state.error = Some(err);
- return Ok(());
- }
+ if let Writing::Init = self.state.writing {
+ if self.has_h2_prefix() {
+ return Err(crate::Error::new_version_h2());
+ }
+ if let Some(msg) = T::on_error(&err) {
+ // Drop the cached headers so as to not trigger a debug
+ // assert in `write_head`...
+ self.state.cached_headers.take();
+ self.write_head(msg, None);
+ self.state.error = Some(err);
+ return Ok(());
}
- _ => (),
}
// fallback is pass the error back up
diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs
index 6d5751bc..9e4a6ec3 100644
--- a/src/proto/h1/dispatch.rs
+++ b/src/proto/h1/dispatch.rs
@@ -62,8 +62,8 @@ where
{
pub fn new(dispatch: D, conn: Conn) -> Self {
Dispatcher {
- conn: conn,
- dispatch: dispatch,
+ conn,
+ dispatch,
body_tx: None,
body_rx: Box::pin(None),
is_closing: false,
@@ -443,7 +443,7 @@ where
pub fn new(service: S) -> Server {
Server {
in_flight: Box::pin(None),
- service: service,
+ service,
}
}
@@ -580,7 +580,7 @@ where
*res.status_mut() = msg.subject;
*res.headers_mut() = msg.headers;
*res.version_mut() = msg.version;
- let _ = cb.send(Ok(res));
+ cb.send(Ok(res));
Ok(())
} else {
// Getting here is likely a bug! An error should have happened
@@ -591,7 +591,7 @@ where
}
Err(err) => {
if let Some(cb) = self.callback.take() {
- let _ = cb.send(Err((err, None)));
+ cb.send(Err((err, None)));
Ok(())
} else if !self.rx_closed {
self.rx.close();
@@ -599,7 +599,7 @@ where
trace!("canceling queued request with connection error: {}", err);
// in this case, the message was never even started, so it's safe to tell
// the user that the request was completely canceled
- let _ = cb.send(Err((crate::Error::new_canceled().with(err), Some(req))));
+ cb.send(Err((crate::Error::new_canceled().with(err), Some(req))));
Ok(())
} else {
Err(err)
diff --git a/src/proto/h1/encode.rs b/src/proto/h1/encode.rs
index da280a16..95b0d82b 100644
--- a/src/proto/h1/encode.rs
+++ b/src/proto/h1/encode.rs
@@ -49,7 +49,7 @@ enum BufKind {
impl Encoder {
fn new(kind: Kind) -> Encoder {
Encoder {
- kind: kind,
+ kind,
is_last: false,
}
}
@@ -307,7 +307,7 @@ impl fmt::Write for ChunkSize {
fn write_str(&mut self, num: &str) -> fmt::Result {
use std::io::Write;
(&mut self.bytes[self.len.into()..])
- .write(num.as_bytes())
+ .write_all(num.as_bytes())
.expect("&mut [u8].write() cannot error");
self.len += num.len() as u8; // safe because bytes is never bigger than 256
Ok(())
diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs
index 50ce2383..70f704e0 100644
--- a/src/proto/h1/io.rs
+++ b/src/proto/h1/io.rs
@@ -57,7 +57,7 @@ where
pub fn new(io: T) -> Buffered {
Buffered {
flush_pipeline: false,
- io: io,
+ io,
read_blocked: false,
read_buf: BytesMut::with_capacity(0),
read_buf_strategy: ReadStrategy::default(),
@@ -168,12 +168,9 @@ where
}
}
}
- match ready!(self.poll_read_from_io(cx)).map_err(crate::Error::new_io)? {
- 0 => {
- trace!("parse eof");
- return Poll::Ready(Err(crate::Error::new_incomplete()));
- }
- _ => {}
+ if ready!(self.poll_read_from_io(cx)).map_err(crate::Error::new_io)? == 0 {
+ trace!("parse eof");
+ return Poll::Ready(Err(crate::Error::new_incomplete()));
}
}
}
@@ -216,9 +213,8 @@ where
} else if self.write_buf.remaining() == 0 {
Pin::new(&mut self.io).poll_flush(cx)
} else {
- match self.write_buf.strategy {
- WriteStrategy::Flatten => return self.poll_flush_flattened(cx),
- _ => (),
+ if let WriteStrategy::Flatten = self.write_buf.strategy {
+ return self.poll_flush_flattened(cx);
}
loop {
let n =
@@ -325,35 +321,33 @@ impl ReadStrategy {
}
fn record(&mut self, bytes_read: usize) {
- match *self {
- ReadStrategy::Adaptive {
- ref mut decrease_now,
- ref mut next,
- max,
- ..
- } => {
- if bytes_read >= *next {
- *next = cmp::min(incr_power_of_two(*next), max);
- *decrease_now = false;
- } else {
- let decr_to = prev_power_of_two(*next);
- if bytes_read < decr_to {
- if *decrease_now {
- *next = cmp::max(decr_to, INIT_BUFFER_SIZE);
- *decrease_now = false;
- } else {
- // Decreasing is a two "record" process.
- *decrease_now = true;
- }
- } else {
- // A read within the current range should cancel
- // a potential decrease, since we just saw proof
- // that we still need this size.
+ if let ReadStrategy::Adaptive {
+ ref mut decrease_now,
+ ref mut next,
+ max,
+ ..
+ } = *self
+ {
+ if bytes_read >= *next {
+ *next = cmp::min(incr_power_of_two(*next), max);
+ *decrease_now = false;
+ } else {
+ let decr_to = prev_power_of_two(*next);
+ if bytes_read < decr_to {
+ if *decrease_now {
+ *next = cmp::max(decr_to, INIT_BUFFER_SIZE);
*decrease_now = false;
+ } else {
+ // Decreasing is a two "record" process.
+ *decrease_now = true;
}
+ } else {
+ // A read within the current range should cancel
+ // a potential decrease, since we just saw proof
+ // that we still need this size.
+ *decrease_now = false;
}
}
- _ => (),
}
}
}
@@ -384,10 +378,7 @@ pub struct Cursor {
impl> Cursor {
#[inline]
pub(crate) fn new(bytes: T) -> Cursor {
- Cursor {
- bytes: bytes,
- pos: 0,
- }
+ Cursor { bytes, pos: 0 }
}
}
@@ -527,14 +518,15 @@ impl Buf for WriteBuf {
#[inline]
fn advance(&mut self, cnt: usize) {
let hrem = self.headers.remaining();
- if hrem == cnt {
- self.headers.reset();
- } else if hrem > cnt {
- self.headers.advance(cnt);
- } else {
- let qcnt = cnt - hrem;
- self.headers.reset();
- self.queue.advance(qcnt);
+
+ match hrem.cmp(&cnt) {
+ cmp::Ordering::Equal => self.headers.reset(),
+ cmp::Ordering::Greater => self.headers.advance(cnt),
+ cmp::Ordering::Less => {
+ let qcnt = cnt - hrem;
+ self.headers.reset();
+ self.queue.advance(qcnt);
+ }
}
}
@@ -558,7 +550,7 @@ impl<'a, B: Buf> WriteBufAuto<'a, B> {
WriteBufAuto {
bytes_called: Cell::new(false),
bytes_vec_called: Cell::new(false),
- inner: inner,
+ inner,
}
}
}
diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs
index 31d856dc..e99f4cf5 100644
--- a/src/proto/h1/role.rs
+++ b/src/proto/h1/role.rs
@@ -472,10 +472,8 @@ impl Http1Transaction for Server {
continue 'headers;
}
header::CONNECTION => {
- if !is_last {
- if headers::connection_close(&value) {
- is_last = true;
- }
+ if !is_last && headers::connection_close(&value) {
+ is_last = true;
}
if !is_name_written {
is_name_written = true;
@@ -594,9 +592,8 @@ impl Server {
}
fn can_chunked(method: &Option, status: StatusCode) -> bool {
- if method == &Some(Method::HEAD) {
- false
- } else if method == &Some(Method::CONNECT) && status.is_success() {
+ if method == &Some(Method::HEAD) || method == &Some(Method::CONNECT) && status.is_success()
+ {
false
} else {
match status {
@@ -766,7 +763,7 @@ impl Client {
101 => {
return Ok(Some((DecodedLength::ZERO, true)));
}
- 100..=199 => {
+ 100 | 102..=199 => {
trace!("ignoring informational response: {}", inc.subject.as_u16());
return Ok(None);
}
diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs
index bf4d5706..60e28fa4 100644
--- a/src/proto/h2/client.rs
+++ b/src/proto/h2/client.rs
@@ -44,9 +44,10 @@ where
let (conn_drop_ref, rx) = mpsc::channel(1);
let (cancel_tx, conn_eof) = oneshot::channel();
- let conn_drop_rx = rx.into_future().map(|(item, _rx)| match item {
- Some(never) => match never {},
- None => (),
+ let conn_drop_rx = rx.into_future().map(|(item, _rx)| {
+ if let Some(never) = item {
+ match never {}
+ }
});
let conn = conn.map_err(|e| debug!("connection error: {}", e));
diff --git a/src/proto/h2/mod.rs b/src/proto/h2/mod.rs
index 356b6715..2a3bbe71 100644
--- a/src/proto/h2/mod.rs
+++ b/src/proto/h2/mod.rs
@@ -47,10 +47,8 @@ fn strip_connection_headers(headers: &mut HeaderMap, is_request: bool) {
warn!("TE headers not set to \"trailers\" are illegal in HTTP/2 requests");
headers.remove(TE);
}
- } else {
- if headers.remove(TE).is_some() {
- warn!("TE headers illegal in HTTP/2 responses");
- }
+ } else if headers.remove(TE).is_some() {
+ warn!("TE headers illegal in HTTP/2 responses");
}
if let Some(header) = headers.remove(CONNECTION) {
@@ -94,7 +92,7 @@ where
PipeToSendStream {
body_tx: tx,
data_done: false,
- stream: stream,
+ stream,
}
}
}
@@ -125,17 +123,15 @@ where
None => return Poll::Ready(Err(crate::Error::new_canceled())),
}
}
- } else {
- if let Poll::Ready(reason) = me
- .body_tx
- .poll_reset(cx)
- .map_err(crate::Error::new_body_write)?
- {
- debug!("stream received RST_STREAM: {:?}", reason);
- return Poll::Ready(Err(crate::Error::new_body_write(::h2::Error::from(
- reason,
- ))));
- }
+ } else if let Poll::Ready(reason) = me
+ .body_tx
+ .poll_reset(cx)
+ .map_err(crate::Error::new_body_write)?
+ {
+ debug!("stream received RST_STREAM: {:?}", reason);
+ return Poll::Ready(Err(crate::Error::new_body_write(::h2::Error::from(
+ reason,
+ ))));
}
match ready!(me.stream.as_mut().poll_data(cx)) {
@@ -172,7 +168,7 @@ where
if let Poll::Ready(reason) = me
.body_tx
.poll_reset(cx)
- .map_err(|e| crate::Error::new_body_write(e))?
+ .map_err(crate::Error::new_body_write)?
{
debug!("stream received RST_STREAM: {:?}", reason);
return Poll::Ready(Err(crate::Error::new_body_write(::h2::Error::from(
@@ -238,6 +234,8 @@ impl Buf for SendBuf {
#[inline]
fn advance(&mut self, cnt: usize) {
- self.0.as_mut().map(|b| b.advance(cnt));
+ if let Some(b) = self.0.as_mut() {
+ b.advance(cnt)
+ }
}
}
diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs
index daa5fa2d..d5d9e025 100644
--- a/src/proto/h2/server.rs
+++ b/src/proto/h2/server.rs
@@ -259,10 +259,8 @@ where
Poll::Pending => {
// Response is not yet ready, so we want to check if the client has sent a
// RST_STREAM frame which would cancel the current request.
- if let Poll::Ready(reason) = me
- .reply
- .poll_reset(cx)
- .map_err(|e| crate::Error::new_h2(e))?
+ if let Poll::Ready(reason) =
+ me.reply.poll_reset(cx).map_err(crate::Error::new_h2)?
{
debug!("stream received RST_STREAM: {:?}", reason);
return Poll::Ready(Err(crate::Error::new_h2(reason.into())));
diff --git a/src/server/conn.rs b/src/server/conn.rs
index 222ef958..9e7cec9f 100644
--- a/src/server/conn.rs
+++ b/src/server/conn.rs
@@ -489,8 +489,8 @@ where
ProtoServer::H1(h1) => {
let (io, read_buf, dispatch) = h1.into_inner();
Some(Parts {
- io: io,
- read_buf: read_buf,
+ io,
+ read_buf,
service: dispatch.into_service(),
_inner: (),
})
@@ -522,7 +522,7 @@ where
ProtoServer::H2(ref mut h2) => return Pin::new(h2).poll(cx).map_ok(|_| ()),
};
match ready!(polled) {
- Ok(x) => return Poll::Ready(Ok(x)),
+ Ok(()) => return Poll::Ready(Ok(())),
Err(e) => match *e.kind() {
Kind::Parse(Parse::VersionH2) if self.fallback.to_h2() => {
self.upgrade_h2();
diff --git a/src/server/tcp.rs b/src/server/tcp.rs
index 2f9bdb94..2046d441 100644
--- a/src/server/tcp.rs
+++ b/src/server/tcp.rs
@@ -35,7 +35,7 @@ impl AddrIncoming {
let addr = listener.local_addr().map_err(crate::Error::new_listen)?;
Ok(AddrIncoming {
listener,
- addr: addr,
+ addr,
sleep_on_errors: true,
tcp_keepalive_timeout: None,
tcp_nodelay: false,
diff --git a/tests/client.rs b/tests/client.rs
index 141d5ce8..73693552 100644
--- a/tests/client.rs
+++ b/tests/client.rs
@@ -310,7 +310,7 @@ macro_rules! __client_req_header {
}
}
-static REPLY_OK: &'static str = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n";
+static REPLY_OK: &str = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n";
test! {
name: client_get,
@@ -1771,7 +1771,7 @@ mod dispatch_impl {
// so the unwrapped responses futures show it still worked.
assert_eq!(connects.load(Ordering::SeqCst), 3);
- let res4 = client.get(url.clone());
+ let res4 = client.get(url);
rt.block_on(res4).unwrap();
assert_eq!(
@@ -1800,8 +1800,8 @@ mod dispatch_impl {
fn with_http_and_closes(http: HttpConnector, closes: mpsc::Sender<()>) -> DebugConnector {
DebugConnector {
- http: http,
- closes: closes,
+ http,
+ closes,
connects: Arc::new(AtomicUsize::new(0)),
is_proxy: false,
alpn_h2: false,
@@ -2242,7 +2242,7 @@ mod conn {
let tcp = rt.block_on(tcp_connect(&addr)).unwrap();
let io = DebugStream {
- tcp: tcp,
+ tcp,
shutdown_called: false,
};
@@ -2330,7 +2330,7 @@ mod conn {
let tcp = rt.block_on(tcp_connect(&addr)).unwrap();
let io = DebugStream {
- tcp: tcp,
+ tcp,
shutdown_called: false,
};
diff --git a/tests/server.rs b/tests/server.rs
index 99410288..903b935e 100644
--- a/tests/server.rs
+++ b/tests/server.rs
@@ -1457,7 +1457,7 @@ async fn max_buf_size() {
thread::spawn(move || {
let mut tcp = connect(&addr);
tcp.write_all(b"POST /").expect("write 1");
- tcp.write_all(&vec![b'a'; MAX]).expect("write 2");
+ tcp.write_all(&[b'a'; MAX]).expect("write 2");
let mut buf = [0; 256];
tcp.read(&mut buf).expect("read 1");
@@ -1481,8 +1481,8 @@ fn streaming_body() {
// disable keep-alive so we can use read_to_end
let server = serve_opts().keep_alive(false).serve();
- static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_00] as _;
- let b = ::futures_util::stream::iter(S.into_iter()).map(|&s| Ok::<_, hyper::Error>(s));
+ static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_00] as _;
+ let b = futures_util::stream::iter(S.iter()).map(|&s| Ok::<_, hyper::Error>(s));
let b = hyper::Body::wrap_stream(b);
server.reply().body_stream(b);
@@ -1588,7 +1588,7 @@ fn http2_body_user_error_sends_reset_reason() {
let server = serve();
let addr_str = format!("http://{}", server.addr());
- let b = ::futures_util::stream::once(future::err::(h2::Error::from(
+ let b = futures_util::stream::once(future::err::(h2::Error::from(
h2::Reason::INADEQUATE_SECURITY,
)));
let b = hyper::Body::wrap_stream(b);
@@ -1931,7 +1931,7 @@ impl TestService {
}
}
-const HELLO: &'static str = "hello";
+const HELLO: &str = "hello";
struct HelloWorld;
@@ -2030,8 +2030,8 @@ impl ServeOptions {
let msg_tx = msg_tx.clone();
let reply_rx = reply_rx.clone();
future::ok::<_, BoxError>(TestService {
- tx: msg_tx.clone(),
- reply: reply_rx.clone(),
+ tx: msg_tx,
+ reply: reply_rx,
})
});
@@ -2056,9 +2056,9 @@ impl ServeOptions {
let addr = addr_rx.recv().expect("server addr rx");
Serve {
- msg_rx: msg_rx,
+ msg_rx,
reply_tx: Mutex::new(reply_tx),
- addr: addr,
+ addr,
shutdown_signal: Some(shutdown_tx),
thread: Some(thread),
}
diff --git a/tests/support/mod.rs b/tests/support/mod.rs
index 0893a417..9bbc6370 100644
--- a/tests/support/mod.rs
+++ b/tests/support/mod.rs
@@ -375,7 +375,7 @@ async fn async_test(cfg: __TestConfig) {
let mut addr = server.local_addr();
tokio::task::spawn(server.map(|result| {
- let _ = result.expect("server error");
+ result.expect("server error");
}));
if cfg.proxy {
@@ -460,7 +460,7 @@ fn naive_proxy(cfg: ProxyConfig) -> (SocketAddr, impl Future