From 7b1d6d71b7e15dfab47010a56a6ca295697dfe10 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 21 Aug 2019 11:58:02 -0700 Subject: [PATCH] refactor(lib): fix many lint warnings --- src/body/payload.rs | 1 + src/client/conn.rs | 1 - src/client/connect/dns.rs | 4 +--- src/client/dispatch.rs | 5 +---- src/common/drain.rs | 2 +- src/common/io/rewind.rs | 37 +++---------------------------------- src/proto/h2/client.rs | 3 --- src/proto/h2/server.rs | 12 ++++++------ src/server/conn.rs | 5 ++--- src/server/mod.rs | 2 +- src/server/shutdown.rs | 2 +- src/server/tcp.rs | 2 +- src/service/make_service.rs | 12 +++++------- src/service/service.rs | 10 ++++------ 14 files changed, 27 insertions(+), 71 deletions(-) diff --git a/src/body/payload.rs b/src/body/payload.rs index 3e2d6fb219..fe77012135 100644 --- a/src/body/payload.rs +++ b/src/body/payload.rs @@ -29,6 +29,7 @@ pub trait Payload: Send + 'static { /// /// Note: Trailers aren't currently used for HTTP/1, only for HTTP/2. fn poll_trailers(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll>> { + drop(cx); Poll::Ready(None) } diff --git a/src/client/conn.rs b/src/client/conn.rs index 795642fd8e..a1603814e6 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -8,7 +8,6 @@ //! If don't have need to manage connections yourself, consider using the //! higher-level [Client](super) API. use std::fmt; -use std::marker::PhantomData; use std::mem; use std::sync::Arc; diff --git a/src/client/connect/dns.rs b/src/client/connect/dns.rs index 6237dd5a48..a525483f72 100644 --- a/src/client/connect/dns.rs +++ b/src/client/connect/dns.rs @@ -14,10 +14,8 @@ use std::net::{ SocketAddrV4, SocketAddrV6, }; use std::str::FromStr; -use std::sync::Arc; use futures_util::{FutureExt, StreamExt}; -use tokio_executor::TypedExecutor; use tokio_sync::{mpsc, oneshot}; use crate::common::{Future, Never, Pin, Poll, Unpin, task}; @@ -330,7 +328,7 @@ impl Resolve for TokioThreadpoolGaiResolver { impl Future for TokioThreadpoolGaiFuture { type Output = Result; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { + fn poll(self: Pin<&mut Self>, _cx: &mut task::Context<'_>) -> Poll { match ready!(tokio_executor::threadpool::blocking(|| (self.name.as_str(), 0).to_socket_addrs())) { Ok(Ok(iter)) => Poll::Ready(Ok(GaiAddrs { inner: IpAddrs { iter } })), Ok(Err(e)) => Poll::Ready(Err(e)), diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index b003e9da6b..4d4723ee5d 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -2,7 +2,7 @@ use futures_core::Stream; use futures_channel::{mpsc, oneshot}; use futures_util::future; -use crate::common::{Future, Never, Pin, Poll, task}; +use crate::common::{Future, Pin, Poll, task}; pub type RetryPromise = oneshot::Receiver)>>; pub type Promise = oneshot::Receiver>; @@ -136,9 +136,6 @@ pub struct Receiver { taker: want::Taker, } -//impl Stream for Receiver { -// type Item = (T, Callback); - impl Receiver { pub(crate) fn poll_next(&mut self, cx: &mut task::Context<'_>) -> Poll)>> { match Pin::new(&mut self.inner).poll_next(cx) { diff --git a/src/common/drain.rs b/src/common/drain.rs index 6ce6da6bf3..561b733a28 100644 --- a/src/common/drain.rs +++ b/src/common/drain.rs @@ -95,7 +95,7 @@ where { type Output = F::Output; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { + fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { let me = unsafe { self.get_unchecked_mut() }; loop { match mem::replace(&mut me.state, State::Draining) { diff --git a/src/common/io/rewind.rs b/src/common/io/rewind.rs index 9510f5d718..94b32cd633 100644 --- a/src/common/io/rewind.rs +++ b/src/common/io/rewind.rs @@ -1,7 +1,7 @@ use std::io::{self, Read}; use std::marker::Unpin; -use bytes::{Buf, BufMut, Bytes, IntoBuf}; +use bytes::{Buf, Bytes, IntoBuf}; use tokio_io::{AsyncRead, AsyncWrite}; use crate::common::{Pin, Poll, task}; @@ -67,35 +67,6 @@ where } Pin::new(&mut self.inner).poll_read(cx, buf) } - - /* - #[inline] - fn read_buf(&mut self, buf: &mut B) -> Poll { - use std::cmp; - - if let Some(bs) = self.pre.take() { - let pre_len = bs.len(); - // If there are no remaining bytes, let the bytes get dropped. - if pre_len > 0 { - let cnt = cmp::min(buf.remaining_mut(), pre_len); - let pre_buf = bs.into_buf(); - let mut xfer = Buf::take(pre_buf, cnt); - buf.put(&mut xfer); - - let mut new_pre = xfer.into_inner().into_inner(); - new_pre.advance(cnt); - - // Put back whats left - if new_pre.len() > 0 { - self.pre = Some(new_pre); - } - - return Ok(Async::Ready(cnt)); - } - } - self.inner.read_buf(buf) - } - */ } impl AsyncWrite for Rewind @@ -114,12 +85,10 @@ where Pin::new(&mut self.inner).poll_shutdown(cx) } - /* #[inline] - fn write_buf(&mut self, buf: &mut B) -> Poll { - self.inner.write_buf(buf) + fn poll_write_buf(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>, buf: &mut B) -> Poll> { + Pin::new(&mut self.inner).poll_write_buf(cx, buf) } - */ } #[cfg(test)] diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 5a8e9d2668..aa338363d4 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -1,10 +1,7 @@ -use bytes::IntoBuf; use futures_channel::{mpsc, oneshot}; use futures_util::future::{self, FutureExt as _, Either}; use futures_util::stream::StreamExt as _; use futures_util::try_future::TryFutureExt as _; -//use futures::future::{self, Either}; -//use futures::sync::{mpsc, oneshot}; use h2::client::{Builder, SendRequest}; use tokio_io::{AsyncRead, AsyncWrite}; diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index 7204784945..8f0dc526c3 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -1,7 +1,6 @@ use std::error::Error as StdError; use std::marker::Unpin; -use futures_core::Stream; use h2::Reason; use h2::server::{Builder, Connection, Handshake, SendResponse}; use tokio_io::{AsyncRead, AsyncWrite}; @@ -145,8 +144,9 @@ where match service.poll_ready(cx) { Poll::Ready(Ok(())) => (), Poll::Pending => { - // use `poll_close` instead of `poll`, in order to avoid accepting a request. - ready!(self.conn.poll_close(cx).map_err(crate::Error::new_h2))?; + // use `poll_closed` instead of `poll_accept`, + // in order to avoid accepting a request. + ready!(self.conn.poll_closed(cx).map_err(crate::Error::new_h2))?; trace!("incoming connection complete"); return Poll::Ready(Ok(())); } @@ -193,7 +193,7 @@ where debug_assert!(self.closing.is_some(), "poll_server broke loop without closing"); - ready!(self.conn.poll_close(cx).map_err(crate::Error::new_h2))?; + ready!(self.conn.poll_closed(cx).map_err(crate::Error::new_h2))?; Poll::Ready(Err(self.closing.take().expect("polled after error"))) } @@ -237,7 +237,7 @@ where B::Data: Unpin, E: Into>, { - fn poll2(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll> { + fn poll2(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll> { // Safety: State::{Service, Body} futures are never moved let me = unsafe { self.get_unchecked_mut() }; loop { @@ -328,7 +328,7 @@ where { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { + fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { self.poll2(cx).map(|res| { if let Err(e) = res { debug!("stream error: {}", e); diff --git a/src/server/conn.rs b/src/server/conn.rs index 2913b7c9aa..d1458f1cec 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -12,7 +12,6 @@ use std::error::Error as StdError; use std::fmt; use std::mem; #[cfg(feature = "runtime")] use std::net::SocketAddr; -use std::sync::Arc; #[cfg(feature = "runtime")] use std::time::Duration; use bytes::Bytes; @@ -785,7 +784,7 @@ where B: Payload, E: H2Exec<>::Future, B>, { - pub(super) fn poll_watch(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>, watcher: &W) -> Poll> + pub(super) fn poll_watch(self: Pin<&mut Self>, cx: &mut task::Context<'_>, watcher: &W) -> Poll> where E: NewSvcExec, W: Watcher, @@ -904,7 +903,7 @@ pub(crate) mod spawn_all { { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { + fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { // If it weren't for needing to name this type so the `Send` bounds // could be projected to the `Serve` executor, this could just be // an `async fn`, and much safer. Woe is me. diff --git a/src/server/mod.rs b/src/server/mod.rs index e4cf6fe524..bcd307cacd 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -216,7 +216,7 @@ where { type Output = crate::Result<()>; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { + fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { self.spawn_all().poll_watch(cx, &NoopWatcher) } } diff --git a/src/server/shutdown.rs b/src/server/shutdown.rs index 17b69fe34a..462fd1e1c3 100644 --- a/src/server/shutdown.rs +++ b/src/server/shutdown.rs @@ -54,7 +54,7 @@ where { type Output = crate::Result<()>; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { + fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { // Safety: the futures are NEVER moved, self.state is overwritten instead. let me = unsafe { self.get_unchecked_mut() }; loop { diff --git a/src/server/tcp.rs b/src/server/tcp.rs index 7b7db2b5cf..f48711ab37 100644 --- a/src/server/tcp.rs +++ b/src/server/tcp.rs @@ -259,7 +259,7 @@ mod addr_stream { } #[inline] - fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _cx: &mut task::Context<'_>) -> Poll> { // TCP flush is a noop Poll::Ready(Ok(())) } diff --git a/src/service/make_service.rs b/src/service/make_service.rs index 58a2e1ab3d..731c38b0af 100644 --- a/src/service/make_service.rs +++ b/src/service/make_service.rs @@ -13,7 +13,7 @@ pub trait MakeService: sealed::Sealed { /// The error type that can be returned by `Service`s. type Error: Into>; - /// The resolved `Service` from `new_service()`. + /// The resolved `Service` from `make_service()`. type Service: Service< ReqBody, ResBody=Self::ResBody, @@ -31,16 +31,14 @@ pub trait MakeService: sealed::Sealed { /// The implementation of this method is allowed to return a `Ready` even if /// the factory is not ready to create a new service. In this case, the future /// returned from `make_service` will resolve to an error. - fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll>; /// Create a new `Service`. fn make_service(&mut self, target: Target) -> Self::Future; } -impl MakeService for T -where +impl MakeService for T +where T: for<'a> tower_service::Service<&'a Target, Response = S, Error = E, Future = F>, S: tower_service::Service, Response = crate::Response>, E: Into>, @@ -191,7 +189,7 @@ where type Response = Svc; type Future = Ret; - fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { + fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll> { Poll::Ready(Ok(())) } diff --git a/src/service/service.rs b/src/service/service.rs index 041442e2e9..171135a05c 100644 --- a/src/service/service.rs +++ b/src/service/service.rs @@ -3,7 +3,7 @@ use std::fmt; use std::marker::PhantomData; use crate::body::Payload; -use crate::common::{Future, Never, Poll, task}; +use crate::common::{Future, Poll, task}; use crate::{Request, Response}; /// An asynchronous function from `Request` to `Response`. @@ -26,15 +26,13 @@ pub trait Service: sealed::Sealed { /// The implementation of this method is allowed to return a `Ready` even if /// the service is not ready to process. In this case, the future returned /// from `call` will resolve to an error. - fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll>; /// Calls this `Service` with a request, returning a `Future` of the response. fn call(&mut self, req: Request) -> Self::Future; } -impl Service for T +impl Service for T where T: tower_service::Service, Response = Response>, B2: Payload, @@ -112,7 +110,7 @@ where type Error = E; type Future = Ret; - fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { + fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll> { Poll::Ready(Ok(())) }