diff --git a/examples/client.rs b/examples/client.rs index f5587ef330..00ae1c26bb 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -1,7 +1,5 @@ #![deny(warnings)] -extern crate hyper; -extern crate pretty_env_logger; - +#![warn(rust_2018_idioms)] use std::env; use std::io::{self, Write}; diff --git a/examples/client_json.rs b/examples/client_json.rs index 1188a76e90..4239ba9a36 100644 --- a/examples/client_json.rs +++ b/examples/client_json.rs @@ -1,9 +1,8 @@ #![deny(warnings)] -extern crate hyper; +#![warn(rust_2018_idioms)] + #[macro_use] extern crate serde_derive; -extern crate serde; -extern crate serde_json; use hyper::Client; use futures_util::TryStreamExt; diff --git a/examples/multi_server.rs b/examples/multi_server.rs index 5b2433abbc..6d38478e60 100644 --- a/examples/multi_server.rs +++ b/examples/multi_server.rs @@ -1,6 +1,5 @@ #![deny(warnings)] -extern crate hyper; -extern crate pretty_env_logger; +#![warn(rust_2018_idioms)] use hyper::{Body, Request, Response, Server}; use hyper::service::{service_fn, make_service_fn}; diff --git a/examples/params.rs b/examples/params.rs index 7f7867b893..6c2788059f 100644 --- a/examples/params.rs +++ b/examples/params.rs @@ -1,7 +1,5 @@ // #![deny(warnings)] // FIXME: https://github.com/rust-lang/rust/issues/62411 -extern crate hyper; -extern crate pretty_env_logger; -extern crate url; +#![warn(rust_2018_idioms)] use hyper::{Body, Method, Request, Response, Server, StatusCode}; use hyper::service::{service_fn, make_service_fn}; diff --git a/src/body/body.rs b/src/body/body.rs index 020de397f0..d147cf6946 100644 --- a/src/body/body.rs +++ b/src/body/body.rs @@ -7,7 +7,6 @@ use futures_core::{Stream, TryStream}; use futures_channel::{mpsc, oneshot}; use futures_util::TryStreamExt; //use tokio_buf::SizeHint; -use h2; use http::HeaderMap; use crate::common::{Future, Never, Pin, Poll, task}; @@ -130,7 +129,6 @@ impl Body { /// /// ``` /// # use hyper::Body; - /// # use futures_util; /// # fn main() { /// let chunks: Vec> = vec![ /// Ok("hello"), @@ -346,7 +344,7 @@ impl Payload for Body { } impl fmt::Debug for Body { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[derive(Debug)] struct Streaming; #[derive(Debug)] diff --git a/src/body/chunk.rs b/src/body/chunk.rs index c8c469892a..f3524cf425 100644 --- a/src/body/chunk.rs +++ b/src/body/chunk.rs @@ -113,7 +113,7 @@ impl AsRef<[u8]> for Chunk { impl fmt::Debug for Chunk { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.bytes, f) } } diff --git a/src/client/conn.rs b/src/client/conn.rs index 8e743e0a4a..795642fd8e 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -14,7 +14,6 @@ use std::sync::Arc; use bytes::Bytes; use futures_util::future::{self, Either, FutureExt as _}; -use h2; use tokio_io::{AsyncRead, AsyncWrite}; use crate::body::Payload; @@ -258,7 +257,7 @@ impl Service for SendRequest { */ impl fmt::Debug for SendRequest { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SendRequest") .finish() } @@ -305,7 +304,7 @@ where } impl fmt::Debug for Http2SendRequest { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Http2SendRequest") .finish() } @@ -410,7 +409,7 @@ where T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static, B: Payload + 'static, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Connection") .finish() } @@ -575,7 +574,7 @@ impl Future for ResponseFuture { } impl fmt::Debug for ResponseFuture { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ResponseFuture") .finish() } diff --git a/src/client/connect/dns.rs b/src/client/connect/dns.rs index d31756eefb..6237dd5a48 100644 --- a/src/client/connect/dns.rs +++ b/src/client/connect/dns.rs @@ -75,13 +75,13 @@ impl Name { } impl fmt::Debug for Name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.host, f) } } impl fmt::Display for Name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.host, f) } } @@ -100,7 +100,7 @@ impl FromStr for Name { pub struct InvalidNameError(()); impl fmt::Display for InvalidNameError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Not a valid domain name") } } @@ -166,7 +166,7 @@ impl Resolve for GaiResolver { } impl fmt::Debug for GaiResolver { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("GaiResolver") } } @@ -184,7 +184,7 @@ impl Future for GaiFuture { } impl fmt::Debug for GaiFuture { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("GaiFuture") } } @@ -198,7 +198,7 @@ impl Iterator for GaiAddrs { } impl fmt::Debug for GaiAddrs { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("GaiAddrs") } } diff --git a/src/client/connect/http.rs b/src/client/connect/http.rs index e8fc792ae9..b39d0261a0 100644 --- a/src/client/connect/http.rs +++ b/src/client/connect/http.rs @@ -198,7 +198,7 @@ impl HttpConnector { // R: Debug required for now to allow adding it to debug output later... impl fmt::Debug for HttpConnector { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("HttpConnector") .finish() } @@ -282,7 +282,7 @@ enum InvalidUrl { } impl fmt::Display for InvalidUrl { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.description()) } } @@ -382,7 +382,7 @@ where } impl fmt::Debug for HttpConnecting { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("HttpConnecting") } } @@ -615,8 +615,6 @@ mod tests { #[test] #[cfg_attr(not(feature = "__internal_happy_eyeballs_tests"), ignore)] fn client_happy_eyeballs() { - extern crate pretty_env_logger; - use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, TcpListener}; use std::time::{Duration, Instant}; diff --git a/src/client/connect/mod.rs b/src/client/connect/mod.rs index d26b0628b4..0134ef9551 100644 --- a/src/client/connect/mod.rs +++ b/src/client/connect/mod.rs @@ -346,7 +346,7 @@ impl Clone for Extra { } impl fmt::Debug for Extra { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Extra") .finish() } diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index c30e03856f..b003e9da6b 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -1,7 +1,6 @@ use futures_core::Stream; use futures_channel::{mpsc, oneshot}; use futures_util::future; -use want; use crate::common::{Future, Never, Pin, Poll, task}; @@ -254,7 +253,6 @@ mod tests { // trigger a warning to remind us use crate::Error; /* - extern crate pretty_env_logger; #[cfg(feature = "nightly")] extern crate test; diff --git a/src/client/mod.rs b/src/client/mod.rs index cdf122af08..4181b901b6 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -137,7 +137,6 @@ impl Client<(), Body> { /// # Example /// /// ``` - /// # extern crate hyper; /// # #[cfg(feature = "runtime")] /// # fn run () { /// use hyper::Client; @@ -175,7 +174,6 @@ where C: Connect + Sync + 'static, /// # Example /// /// ``` - /// # extern crate hyper; /// # #[cfg(feature = "runtime")] /// # fn run () { /// use hyper::{Client, Uri}; @@ -205,7 +203,6 @@ where C: Connect + Sync + 'static, /// # Example /// /// ``` - /// # extern crate hyper; /// # #[cfg(feature = "runtime")] /// # fn run () { /// use hyper::{Body, Client, Request}; @@ -558,7 +555,7 @@ impl Clone for Client { } impl fmt::Debug for Client { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Client") .finish() } @@ -580,7 +577,7 @@ impl ResponseFuture { } impl fmt::Debug for ResponseFuture { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Future") } } @@ -821,7 +818,6 @@ fn set_scheme(uri: &mut Uri, scheme: Scheme) { /// # Example /// /// ``` -/// # extern crate hyper; /// # #[cfg(feature = "runtime")] /// # fn run () { /// use hyper::Client; @@ -1053,7 +1049,7 @@ impl Builder { } impl fmt::Debug for Builder { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Builder") .field("client_config", &self.client_config) .field("conn_builder", &self.conn_builder) @@ -1097,7 +1093,6 @@ mod unit_tests { #[test] fn test_authority_form() { - extern crate pretty_env_logger; let _ = pretty_env_logger::try_init(); let mut uri = "http://hyper.rs".parse().unwrap(); diff --git a/src/client/pool.rs b/src/client/pool.rs index 7bdd91e310..716a2c9232 100644 --- a/src/client/pool.rs +++ b/src/client/pool.rs @@ -171,7 +171,7 @@ impl Pool { } #[cfg(test)] - fn locked(&self) -> ::std::sync::MutexGuard> { + fn locked(&self) -> ::std::sync::MutexGuard<'_, PoolInner> { self .inner .as_ref() @@ -263,7 +263,7 @@ impl Pool { } /// Pop off this list, looking for a usable connection that hasn't expired. -struct IdlePopper<'a, T: 'a> { +struct IdlePopper<'a, T> { key: &'a Key, list: &'a mut Vec>, } @@ -547,7 +547,7 @@ impl Drop for Pooled { } impl fmt::Debug for Pooled { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Pooled") .field("key", &self.key) .finish() diff --git a/src/client/tests.rs b/src/client/tests.rs index c26256ffd2..b96c6f94a9 100644 --- a/src/client/tests.rs +++ b/src/client/tests.rs @@ -3,7 +3,6 @@ use super::Client; /* #![cfg(feature = "runtime")] -extern crate pretty_env_logger; use futures::{Async, Future, Stream}; use futures::future::poll_fn; diff --git a/src/common/exec.rs b/src/common/exec.rs index baf3650521..1650c8f7c5 100644 --- a/src/common/exec.rs +++ b/src/common/exec.rs @@ -57,13 +57,13 @@ impl Exec { struct TokioSpawnError; impl fmt::Debug for TokioSpawnError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt("tokio::spawn failed (is a tokio runtime running this future?)", f) } } impl fmt::Display for TokioSpawnError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt("tokio::spawn failed (is a tokio runtime running this future?)", f) } } @@ -99,7 +99,7 @@ impl Exec { } impl fmt::Debug for Exec { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Exec") .finish() } diff --git a/src/common/io/rewind.rs b/src/common/io/rewind.rs index b1cb68cd4f..9510f5d718 100644 --- a/src/common/io/rewind.rs +++ b/src/common/io/rewind.rs @@ -129,8 +129,7 @@ mod tests { use super::Rewind; /* use super::*; - extern crate tokio_mockstream; - use self::tokio_mockstream::MockStream; + use tokio_mockstream::MockStream; use std::io::Cursor; // Test a partial rewind diff --git a/src/common/never.rs b/src/common/never.rs index dfb763b2a4..c44c9adb97 100644 --- a/src/common/never.rs +++ b/src/common/never.rs @@ -9,7 +9,7 @@ use std::fmt; pub enum Never {} impl fmt::Display for Never { - fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { match *self {} } } diff --git a/src/common/task.rs b/src/common/task.rs index 9a7c2aea5b..aca869e6ef 100644 --- a/src/common/task.rs +++ b/src/common/task.rs @@ -4,7 +4,7 @@ use super::Never; /// A function to help "yield" a future, such that it is re-scheduled immediately. /// /// Useful for spin counts, so a future doesn't hog too much time. -pub(crate) fn yield_now(cx: &mut Context) -> Poll { +pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll { cx.waker().wake_by_ref(); Poll::Pending } diff --git a/src/error.rs b/src/error.rs index 1a025c5e6f..ac01d8c421 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,10 +3,6 @@ use std::error::Error as StdError; use std::fmt; use std::io; -use httparse; -use http; -use h2; - /// Result type often returned from methods that can have hyper `Error`s. pub type Result = ::std::result::Result; @@ -284,7 +280,7 @@ impl Error { } impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut f = f.debug_tuple("Error"); f.field(&self.inner.kind); if let Some(ref cause) = self.inner.cause { @@ -295,7 +291,7 @@ impl fmt::Debug for Error { } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(ref cause) = self.inner.cause { write!(f, "{}: {}", self.description(), cause) } else { diff --git a/src/headers.rs b/src/headers.rs index 52fcaba89b..fbacd08beb 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -33,7 +33,7 @@ pub fn content_length_parse_all(headers: &HeaderMap) -> Option { content_length_parse_all_values(headers.get_all(CONTENT_LENGTH).into_iter()) } -pub fn content_length_parse_all_values(values: ValueIter) -> Option { +pub fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>) -> Option { // If multiple Content-Length headers were sent, everything can still // be alright if they all contain the same value, and all parse // correctly. If not, then it's an error. @@ -74,7 +74,7 @@ pub fn transfer_encoding_is_chunked(headers: &HeaderMap) -> bool { is_chunked(headers.get_all(TRANSFER_ENCODING).into_iter()) } -pub fn is_chunked(mut encodings: ValueIter) -> bool { +pub fn is_chunked(mut encodings: ValueIter<'_, HeaderValue>) -> bool { // chunked must always be the last encoding, according to spec if let Some(line) = encodings.next_back() { return is_chunked_(line); @@ -94,7 +94,7 @@ pub fn is_chunked_(value: &HeaderValue) -> bool { false } -pub fn add_chunked(mut entry: OccupiedEntry) { +pub fn add_chunked(mut entry: OccupiedEntry<'_, HeaderValue>) { const CHUNKED: &'static str = "chunked"; if let Some(line) = entry.iter_mut().next_back() { diff --git a/src/lib.rs b/src/lib.rs index 6ec2c7719b..0a6ac08b4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ #![doc(html_root_url = "https://docs.rs/hyper/0.12.32")] #![deny(missing_docs)] #![deny(missing_debug_implementations)] +#![deny(rust_2018_idioms)] // XXX NOOOOOOOO //#![cfg_attr(test, deny(warnings))] #![allow(warnings)] @@ -19,7 +20,7 @@ //! If looking for just a convenient HTTP client, consider the //! [reqwest](https://crates.io/crates/reqwest) crate. -#[doc(hidden)] pub extern crate http; +#[doc(hidden)] pub use http; #[macro_use] extern crate log; #[cfg(all(test, feature = "nightly"))] diff --git a/src/proto/h1/conn.rs b/src/proto/h1/conn.rs index 49fd4f368c..4ace672668 100644 --- a/src/proto/h1/conn.rs +++ b/src/proto/h1/conn.rs @@ -646,7 +646,7 @@ where I: AsyncRead + AsyncWrite + Unpin, } impl fmt::Debug for Conn { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Conn") .field("state", &self.state) .field("io", &self.io) @@ -701,7 +701,7 @@ enum Writing { } impl fmt::Debug for State { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut builder = f.debug_struct("State"); builder .field("reading", &self.reading) @@ -720,7 +720,7 @@ impl fmt::Debug for State { } impl fmt::Debug for Writing { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Writing::Init => f.write_str("Init"), Writing::Body(ref enc) => f.debug_tuple("Body") @@ -1112,7 +1112,6 @@ mod tests { #[test] fn test_conn_body_write_length() { - extern crate pretty_env_logger; let _ = pretty_env_logger::try_init(); let _: Result<(), ()> = future::lazy(|| { let io = AsyncIo::new_buf(vec![], 0); diff --git a/src/proto/h1/decode.rs b/src/proto/h1/decode.rs index 6583ddf39b..3c1247e297 100644 --- a/src/proto/h1/decode.rs +++ b/src/proto/h1/decode.rs @@ -147,7 +147,7 @@ impl Decoder { impl fmt::Debug for Decoder { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.kind, f) } } @@ -306,7 +306,7 @@ impl ChunkedState { struct IncompleteBody; impl fmt::Display for IncompleteBody { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.description()) } } diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index db08e4958e..bd8e048dff 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -602,8 +602,6 @@ mod tests { // trigger a warning to remind us use crate::Error; /* - extern crate pretty_env_logger; - use super::*; use crate::mock::AsyncIo; use crate::proto::h1::ClientTransaction; diff --git a/src/proto/h1/encode.rs b/src/proto/h1/encode.rs index 56ed2eecea..48c27da071 100644 --- a/src/proto/h1/encode.rs +++ b/src/proto/h1/encode.rs @@ -298,7 +298,7 @@ impl Buf for ChunkSize { } impl fmt::Debug for ChunkSize { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ChunkSize") .field("bytes", &&self.bytes[..self.len.into()]) .field("pos", &self.pos) diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs index 79e1b0ee8c..b5352f79ad 100644 --- a/src/proto/h1/io.rs +++ b/src/proto/h1/io.rs @@ -42,7 +42,7 @@ impl fmt::Debug for Buffered where B: Buf, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Buffered") .field("read_buf", &self.read_buf) .field("write_buf", &self.write_buf) @@ -135,7 +135,7 @@ where } } - pub(super) fn parse(&mut self, cx: &mut task::Context<'_>, parse_ctx: ParseContext) + pub(super) fn parse(&mut self, cx: &mut task::Context<'_>, parse_ctx: ParseContext<'_>) -> Poll>> where S: Http1Transaction, @@ -376,7 +376,7 @@ impl Cursor> { } impl> fmt::Debug for Cursor { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Cursor") .field("pos", &self.pos) .field("len", &self.bytes.as_ref().len()) @@ -433,7 +433,7 @@ where } #[inline] - fn auto(&mut self) -> WriteBufAuto { + fn auto(&mut self) -> WriteBufAuto<'_, B> { WriteBufAuto::new(self) } @@ -481,7 +481,7 @@ where } impl fmt::Debug for WriteBuf { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("WriteBuf") .field("remaining", &self.remaining()) .field("strategy", &self.strategy) @@ -528,7 +528,7 @@ impl Buf for WriteBuf { /// Detects when wrapped `WriteBuf` is used for vectored IO, and /// adjusts the `WriteBuf` strategy if not. -struct WriteBufAuto<'a, B: Buf + 'a> { +struct WriteBufAuto<'a, B: Buf> { bytes_called: Cell, bytes_vec_called: Cell, inner: &'a mut WriteBuf, @@ -822,7 +822,6 @@ mod tests { TODO: needs tokio_test::io to allow configure write_buf calls #[test] fn write_buf_queue() { - extern crate pretty_env_logger; let _ = pretty_env_logger::try_init(); let mock = AsyncIo::new_buf(vec![], 1024); @@ -844,7 +843,6 @@ mod tests { #[tokio::test] async fn write_buf_flatten() { - extern crate pretty_env_logger; let _ = pretty_env_logger::try_init(); let mock = Mock::new() @@ -866,7 +864,6 @@ mod tests { #[tokio::test] async fn write_buf_auto_flatten() { - extern crate pretty_env_logger; let _ = pretty_env_logger::try_init(); let mock = Mock::new() @@ -894,7 +891,6 @@ mod tests { #[tokio::test] async fn write_buf_queue_disable_auto() { - extern crate pretty_env_logger; let _ = pretty_env_logger::try_init(); let mock = Mock::new() diff --git a/src/proto/h1/mod.rs b/src/proto/h1/mod.rs index 2784ed4fc3..65cea1391d 100644 --- a/src/proto/h1/mod.rs +++ b/src/proto/h1/mod.rs @@ -26,8 +26,8 @@ pub(crate) trait Http1Transaction { type Incoming; type Outgoing: Default; const LOG: &'static str; - fn parse(bytes: &mut BytesMut, ctx: ParseContext) -> ParseResult; - fn encode(enc: Encode, dst: &mut Vec) -> crate::Result; + fn parse(bytes: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult; + fn encode(enc: Encode<'_, Self::Outgoing>, dst: &mut Vec) -> crate::Result; fn on_error(err: &crate::Error) -> Option>; @@ -68,7 +68,7 @@ pub(crate) struct ParseContext<'a> { } /// Passed to Http1Transaction::encode -pub(crate) struct Encode<'a, T: 'a> { +pub(crate) struct Encode<'a, T> { head: &'a mut MessageHead, body: Option, keep_alive: bool, diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index 9aecb8ddd9..86ad8fdb2f 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -8,7 +8,6 @@ use std::mem; use bytes::{BytesMut}; use http::header::{self, Entry, HeaderName, HeaderValue}; use http::{HeaderMap, Method, StatusCode, Version}; -use httparse; use crate::error::Parse; use crate::headers; @@ -68,7 +67,7 @@ impl Http1Transaction for Server { type Outgoing = StatusCode; const LOG: &'static str = "{role=server}"; - fn parse(buf: &mut BytesMut, ctx: ParseContext) -> ParseResult { + fn parse(buf: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult { if buf.is_empty() { return Ok(None); } @@ -86,7 +85,7 @@ impl Http1Transaction for Server { // a good ~5% on pipeline benchmarks. let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() }; { - let mut headers: [httparse::Header; MAX_HEADERS] = unsafe { mem::uninitialized() }; + let mut headers: [httparse::Header<'_>; MAX_HEADERS] = unsafe { mem::uninitialized() }; trace!("Request.parse([Header; {}], [u8; {}])", headers.len(), buf.len()); let mut req = httparse::Request::new(&mut headers); let bytes = buf.as_ref(); @@ -239,7 +238,7 @@ impl Http1Transaction for Server { })) } - fn encode(mut msg: Encode, mut dst: &mut Vec) -> crate::Result { + fn encode(mut msg: Encode<'_, Self::Outgoing>, mut dst: &mut Vec) -> crate::Result { trace!( "Server::encode status={:?}, body={:?}, req_method={:?}", msg.head.subject, @@ -589,7 +588,7 @@ impl Http1Transaction for Client { type Outgoing = RequestLine; const LOG: &'static str = "{role=client}"; - fn parse(buf: &mut BytesMut, ctx: ParseContext) -> ParseResult { + fn parse(buf: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult { // Loop to skip information status code headers (100 Continue, etc). loop { if buf.is_empty() { @@ -598,7 +597,7 @@ impl Http1Transaction for Client { // Unsafe: see comment in Server Http1Transaction, above. let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() }; let (len, status, version, headers_len) = { - let mut headers: [httparse::Header; MAX_HEADERS] = unsafe { mem::uninitialized() }; + let mut headers: [httparse::Header<'_>; MAX_HEADERS] = unsafe { mem::uninitialized() }; trace!("Response.parse([Header; {}], [u8; {}])", headers.len(), buf.len()); let mut res = httparse::Response::new(&mut headers); let bytes = buf.as_ref(); @@ -666,7 +665,7 @@ impl Http1Transaction for Client { } } - fn encode(msg: Encode, dst: &mut Vec) -> crate::Result { + fn encode(msg: Encode<'_, Self::Outgoing>, dst: &mut Vec) -> crate::Result { trace!("Client::encode method={:?}, body={:?}", msg.head.subject.0, msg.body); *msg.req_method = Some(msg.head.subject.0.clone()); @@ -935,7 +934,7 @@ struct HeaderIndices { fn record_header_indices( bytes: &[u8], - headers: &[httparse::Header], + headers: &[httparse::Header<'_>], indices: &mut [HeaderIndices] ) -> Result<(), crate::error::Parse> { let bytes_ptr = bytes.as_ptr() as usize; @@ -1044,7 +1043,7 @@ impl<'a> fmt::Write for FastWrite<'a> { } #[inline] - fn write_fmt(&mut self, args: fmt::Arguments) -> fmt::Result { + fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> fmt::Result { fmt::write(self, args) } } @@ -1062,7 +1061,6 @@ mod tests { #[test] fn test_parse_request() { - extern crate pretty_env_logger; let _ = pretty_env_logger::try_init(); let mut raw = BytesMut::from(b"GET /echo HTTP/1.1\r\nHost: hyper.rs\r\n\r\n".to_vec()); let mut method = None; @@ -1082,7 +1080,6 @@ mod tests { #[test] fn test_parse_response() { - extern crate pretty_env_logger; let _ = pretty_env_logger::try_init(); let mut raw = BytesMut::from(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n".to_vec()); let ctx = ParseContext { diff --git a/src/proto/mod.rs b/src/proto/mod.rs index dd33ac2141..600d39af97 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -94,7 +94,7 @@ mod body_length { } impl fmt::Display for DecodedLength { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { DecodedLength::CLOSE_DELIMITED => f.write_str("close-delimited"), DecodedLength::CHUNKED => f.write_str("chunked encoding"), diff --git a/src/server/conn.rs b/src/server/conn.rs index baede2d7cc..2913b7c9aa 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -17,7 +17,6 @@ use std::sync::Arc; use bytes::Bytes; use futures_core::Stream; -use h2; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use tokio_io::{AsyncRead, AsyncWrite}; #[cfg(feature = "runtime")] use tokio_net::driver::Handle; @@ -666,7 +665,7 @@ impl fmt::Debug for Connection where S: Service, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Connection") .finish() } diff --git a/src/server/mod.rs b/src/server/mod.rs index 0c094307dc..e4cf6fe524 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -222,7 +222,7 @@ where } impl fmt::Debug for Server { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Server") .field("listener", &self.spawn_all.incoming_ref()) .finish() diff --git a/src/server/tcp.rs b/src/server/tcp.rs index 75d7d47616..7b7db2b5cf 100644 --- a/src/server/tcp.rs +++ b/src/server/tcp.rs @@ -182,7 +182,7 @@ fn is_connection_error(e: &io::Error) -> bool { } impl fmt::Debug for AddrIncoming { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("AddrIncoming") .field("addr", &self.addr) .field("sleep_on_errors", &self.sleep_on_errors) diff --git a/src/service/make_service.rs b/src/service/make_service.rs index 83b7521941..58a2e1ab3d 100644 --- a/src/service/make_service.rs +++ b/src/service/make_service.rs @@ -201,7 +201,7 @@ where } impl fmt::Debug for MakeServiceFn { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("MakeServiceFn") .finish() } diff --git a/src/service/service.rs b/src/service/service.rs index 50bcdff370..041442e2e9 100644 --- a/src/service/service.rs +++ b/src/service/service.rs @@ -122,7 +122,7 @@ where } impl fmt::Debug for ServiceFn { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("impl Service") .finish() } diff --git a/src/upgrade.rs b/src/upgrade.rs index 6dc5b4a131..618cc4e61d 100644 --- a/src/upgrade.rs +++ b/src/upgrade.rs @@ -160,7 +160,7 @@ impl AsyncWrite for Upgraded { } impl fmt::Debug for Upgraded { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Upgraded") .finish() } @@ -198,7 +198,7 @@ impl Future for OnUpgrade { } impl fmt::Debug for OnUpgrade { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("OnUpgrade") .finish() } @@ -223,7 +223,7 @@ impl Pending { // ===== impl UpgradeExpected ===== impl fmt::Display for UpgradeExpected { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.description()) } } diff --git a/tests/client.rs b/tests/client.rs index 702c2a91ee..c88c6f8d75 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -1,13 +1,7 @@ #![deny(warnings)] -extern crate bytes; -extern crate hyper; +#![warn(rust_2018_idioms)] + #[macro_use] extern crate matches; -extern crate net2; -extern crate pretty_env_logger; -extern crate tokio; -extern crate tokio_io; -extern crate tokio_net; -extern crate tokio_timer; use std::io::{Read, Write}; use std::net::{SocketAddr, TcpListener}; @@ -777,9 +771,6 @@ mod dispatch_impl { use hyper::client::connect::{Connect, Connected, Destination, HttpConnector}; use hyper::Client; - use hyper; - - #[test] fn drop_body_before_eof_closes_connection() { @@ -1609,7 +1600,7 @@ mod dispatch_impl { impl AsyncRead for DebugStream { fn poll_read( mut self: Pin<&mut Self>, - cx: &mut Context, + cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { Pin::new(&mut self.0).poll_read(cx, buf) @@ -2171,7 +2162,7 @@ mod conn { impl AsyncRead for DebugStream { fn poll_read( mut self: Pin<&mut Self>, - cx: &mut Context, + cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { Pin::new(&mut self.tcp).poll_read(cx, buf) diff --git a/tests/server.rs b/tests/server.rs index 4e4f29ccd7..5f37947321 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -1,14 +1,6 @@ #![feature(async_closure)] #![deny(warnings)] -extern crate http; -extern crate hyper; -extern crate h2; -extern crate net2; -extern crate spmc; -extern crate pretty_env_logger; -extern crate tokio; -extern crate tokio_io; -extern crate tokio_net; +#![warn(rust_2018_idioms)] use std::net::{TcpStream, Shutdown, SocketAddr}; use std::io::{self, Read, Write}; @@ -1241,7 +1233,7 @@ fn http_connect() { #[test] fn upgrades_new() { - use crate::tokio::io::{AsyncReadExt, AsyncWriteExt}; + use tokio::io::{AsyncReadExt, AsyncWriteExt}; let _ = pretty_env_logger::try_init(); let mut rt = Runtime::new().unwrap(); @@ -1765,7 +1757,7 @@ impl Serve { Ok(buf) } - fn reply(&self) -> ReplyBuilder { + fn reply(&self) -> ReplyBuilder<'_> { ReplyBuilder { tx: &self.reply_tx } diff --git a/tests/support/mod.rs b/tests/support/mod.rs index bfdd19384a..1d5eae1aea 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -1,21 +1,17 @@ -pub extern crate hyper; -pub extern crate tokio; -extern crate futures_util; - use std::future::Future; use std::pin::Pin; use std::sync::{Arc, Mutex, atomic::{AtomicUsize, Ordering}}; use std::time::{Duration/*, Instant*/}; -use crate::hyper::{Body, Client, Request, Response, Server, Version}; -use crate::hyper::client::HttpConnector; -use crate::hyper::service::{make_service_fn, service_fn}; +use hyper::{Body, Client, Request, Response, Server, Version}; +use hyper::client::HttpConnector; +use hyper::service::{make_service_fn, service_fn}; pub use std::net::SocketAddr; -pub use self::futures_util::{future, try_future, FutureExt as _, StreamExt as _, TryFutureExt as _, TryStreamExt as _}; +pub use futures_util::{future, try_future, FutureExt as _, StreamExt as _, TryFutureExt as _, TryStreamExt as _}; //pub use self::futures_channel::oneshot; -pub use self::hyper::{HeaderMap, StatusCode}; -pub use self::tokio::runtime::current_thread::Runtime; +pub use hyper::{HeaderMap, StatusCode}; +pub use tokio::runtime::current_thread::Runtime; macro_rules! t { ( @@ -209,12 +205,12 @@ macro_rules! __internal_headers_map { macro_rules! __internal_headers_eq { (@pat $name: expr, $pat:pat) => { - ::std::sync::Arc::new(move |__hdrs: &crate::hyper::HeaderMap| { + ::std::sync::Arc::new(move |__hdrs: &hyper::HeaderMap| { match __hdrs.get($name) { $pat => (), other => panic!("headers[{}] was not {}: {:?}", stringify!($name), stringify!($pat), other), } - }) as ::std::sync::Arc + }) as ::std::sync::Arc }; (@val $name: expr, NONE) => { __internal_headers_eq!(@pat $name, None); @@ -224,13 +220,13 @@ macro_rules! __internal_headers_eq { }; (@val $name: expr, $val:expr) => ({ let __val = Option::from($val); - ::std::sync::Arc::new(move |__hdrs: &crate::hyper::HeaderMap| { + ::std::sync::Arc::new(move |__hdrs: &hyper::HeaderMap| { if let Some(ref val) = __val { assert_eq!(__hdrs.get($name).expect(stringify!($name)), val.to_string().as_str(), stringify!($name)); } else { assert_eq!(__hdrs.get($name), None, stringify!($name)); } - }) as ::std::sync::Arc + }) as ::std::sync::Arc }); ($headers:ident, { $($name:expr => $val:tt,)* }) => { $( @@ -306,7 +302,6 @@ pub struct __TestConfig { } pub fn __run_test(cfg: __TestConfig) { - extern crate pretty_env_logger; let _ = pretty_env_logger::try_init(); let mut rt = Runtime::new().expect("new rt"); @@ -379,7 +374,7 @@ pub fn __run_test(cfg: __TestConfig) { let fut = connecting .then(|res| res.expect("connecting")) .map(|conn_res| conn_res.expect("server connection error")); - crate::tokio::spawn(fut); + tokio::spawn(fut); future::ok::<_, hyper::Error>(cnt) }) .map(|res| {