refactor(lib): fix many lint warnings

This commit is contained in:
Sean McArthur
2019-08-21 11:58:02 -07:00
parent fc7f81b67c
commit 7b1d6d71b7
14 changed files with 27 additions and 71 deletions

View File

@@ -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)
}

View File

@@ -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;

View File

@@ -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<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)),

View File

@@ -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>>;
@@ -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) {

View File

@@ -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) {

View File

@@ -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<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>
@@ -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)]

View File

@@ -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};

View File

@@ -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<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 {
@@ -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);

View File

@@ -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<<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>,
@@ -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.

View File

@@ -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)
}
}

View File

@@ -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 {

View File

@@ -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(()))
}

View File

@@ -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,
@@ -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>>,
@@ -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(()))
}

View File

@@ -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<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,
@@ -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(()))
}