Skip to content

Commit

Permalink
refactor(lib): fix many lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Aug 21, 2019
1 parent fc7f81b commit 7b1d6d7
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 71 deletions.
1 change: 1 addition & 0 deletions src/body/payload.rs
Expand Up @@ -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<Option<Result<HeaderMap, Self::Error>>> {
drop(cx);
Poll::Ready(None)
}

Expand Down
1 change: 0 additions & 1 deletion src/client/conn.rs
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions src/client/connect/dns.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -330,7 +328,7 @@ impl Resolve for TokioThreadpoolGaiResolver {
impl Future for TokioThreadpoolGaiFuture {
type Output = Result<GaiAddrs, io::Error>;

fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, _cx: &mut task::Context<'_>) -> Poll<Self::Output> {
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)),
Expand Down
5 changes: 1 addition & 4 deletions src/client/dispatch.rs
Expand Up @@ -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<T, U> = oneshot::Receiver<Result<U, (crate::Error, Option<T>)>>;
pub type Promise<T> = oneshot::Receiver<Result<T, crate::Error>>;
Expand Down Expand Up @@ -136,9 +136,6 @@ pub struct Receiver<T, U> {
taker: want::Taker,
}

//impl<T, U> Stream for Receiver<T, U> {
// type Item = (T, Callback<T, U>);

impl<T, U> Receiver<T, U> {
pub(crate) fn poll_next(&mut self, cx: &mut task::Context<'_>) -> Poll<Option<(T, Callback<T, U>)>> {
match Pin::new(&mut self.inner).poll_next(cx) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/drain.rs
Expand Up @@ -95,7 +95,7 @@ where
{
type Output = F::Output;

fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
let me = unsafe { self.get_unchecked_mut() };
loop {
match mem::replace(&mut me.state, State::Draining) {
Expand Down
37 changes: 3 additions & 34 deletions 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};
Expand Down Expand Up @@ -67,35 +67,6 @@ where
}
Pin::new(&mut self.inner).poll_read(cx, buf)
}

/*
#[inline]
fn read_buf<B: BufMut>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
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<T> AsyncWrite for Rewind<T>
Expand All @@ -114,12 +85,10 @@ where
Pin::new(&mut self.inner).poll_shutdown(cx)
}

/*
#[inline]
fn write_buf<B: Buf>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
self.inner.write_buf(buf)
fn poll_write_buf<B: Buf>(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>, buf: &mut B) -> Poll<io::Result<usize>> {
Pin::new(&mut self.inner).poll_write_buf(cx, buf)
}
*/
}

#[cfg(test)]
Expand Down
3 changes: 0 additions & 3 deletions 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};

Expand Down
12 changes: 6 additions & 6 deletions 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};
Expand Down Expand Up @@ -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(()));
}
Expand Down Expand Up @@ -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")))
}
Expand Down Expand Up @@ -237,7 +237,7 @@ where
B::Data: Unpin,
E: Into<Box<dyn StdError + Send + Sync>>,
{
fn poll2(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
fn poll2(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
// Safety: State::{Service, Body} futures are never moved
let me = unsafe { self.get_unchecked_mut() };
loop {
Expand Down Expand Up @@ -328,7 +328,7 @@ where
{
type Output = ();

fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
self.poll2(cx).map(|res| {
if let Err(e) = res {
debug!("stream error: {}", e);
Expand Down
5 changes: 2 additions & 3 deletions src/server/conn.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -785,7 +784,7 @@ where
B: Payload,
E: H2Exec<<S::Service as Service<Body>>::Future, B>,
{
pub(super) fn poll_watch<W>(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>, watcher: &W) -> Poll<crate::Result<()>>
pub(super) fn poll_watch<W>(self: Pin<&mut Self>, cx: &mut task::Context<'_>, watcher: &W) -> Poll<crate::Result<()>>
where
E: NewSvcExec<IO, S::Future, S::Service, E, W>,
W: Watcher<IO, S::Service, E>,
Expand Down Expand Up @@ -904,7 +903,7 @@ pub(crate) mod spawn_all {
{
type Output = ();

fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion src/server/mod.rs
Expand Up @@ -216,7 +216,7 @@ where
{
type Output = crate::Result<()>;

fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
self.spawn_all().poll_watch(cx, &NoopWatcher)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/shutdown.rs
Expand Up @@ -54,7 +54,7 @@ where
{
type Output = crate::Result<()>;

fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
// Safety: the futures are NEVER moved, self.state is overwritten instead.
let me = unsafe { self.get_unchecked_mut() };
loop {
Expand Down
2 changes: 1 addition & 1 deletion src/server/tcp.rs
Expand Up @@ -259,7 +259,7 @@ mod addr_stream {
}

#[inline]
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
fn poll_flush(self: Pin<&mut Self>, _cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
// TCP flush is a noop
Poll::Ready(Ok(()))
}
Expand Down
12 changes: 5 additions & 7 deletions src/service/make_service.rs
Expand Up @@ -13,7 +13,7 @@ pub trait MakeService<Target, ReqBody>: sealed::Sealed<Target, ReqBody> {
/// The error type that can be returned by `Service`s.
type Error: Into<Box<dyn StdError + Send + Sync>>;

/// The resolved `Service` from `new_service()`.
/// The resolved `Service` from `make_service()`.
type Service: Service<
ReqBody,
ResBody=Self::ResBody,
Expand All @@ -31,16 +31,14 @@ pub trait MakeService<Target, ReqBody>: sealed::Sealed<Target, ReqBody> {
/// 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<Result<(), Self::MakeError>> {
Poll::Ready(Ok(()))
}
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::MakeError>>;

/// Create a new `Service`.
fn make_service(&mut self, target: Target) -> Self::Future;
}

impl<T, Target, S, B1, B2, E, F> MakeService<Target, B1> for T
where
impl<T, Target, S, B1, B2, E, F> MakeService<Target, B1> for T
where
T: for<'a> tower_service::Service<&'a Target, Response = S, Error = E, Future = F>,
S: tower_service::Service<crate::Request<B1>, Response = crate::Response<B2>>,
E: Into<Box<dyn std::error::Error + Send + Sync>>,
Expand Down Expand Up @@ -191,7 +189,7 @@ where
type Response = Svc;
type Future = Ret;

fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

Expand Down
10 changes: 4 additions & 6 deletions src/service/service.rs
Expand Up @@ -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`.
Expand All @@ -26,15 +26,13 @@ pub trait Service<ReqBody>: sealed::Sealed<ReqBody> {
/// 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<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>>;

/// Calls this `Service` with a request, returning a `Future` of the response.
fn call(&mut self, req: Request<ReqBody>) -> Self::Future;
}

impl<T, B1, B2> Service<B1> for T
impl<T, B1, B2> Service<B1> for T
where
T: tower_service::Service<Request<B1>, Response = Response<B2>>,
B2: Payload,
Expand Down Expand Up @@ -112,7 +110,7 @@ where
type Error = E;
type Future = Ret;

fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

Expand Down

0 comments on commit 7b1d6d7

Please sign in to comment.