From 5a8f4c0f60cb99f5935f4ed6aca268e3ed641ab1 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 4 Oct 2023 22:43:36 +0900 Subject: [PATCH] refactor(common): replace Never with Infallible (#3335) --- src/common/mod.rs | 3 --- src/common/never.rs | 21 --------------------- src/common/task.rs | 4 ++-- src/proto/h1/dispatch.rs | 6 ++++-- src/proto/h2/client.rs | 20 +++++++++----------- 5 files changed, 15 insertions(+), 39 deletions(-) delete mode 100644 src/common/never.rs diff --git a/src/common/mod.rs b/src/common/mod.rs index 2392851951..632b363e2b 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -13,14 +13,11 @@ pub(crate) mod date; #[cfg(not(feature = "http2"))] pub(crate) mod exec; pub(crate) mod io; -mod never; pub(crate) mod task; #[cfg(any(feature = "http1", feature = "http2", feature = "server"))] pub(crate) mod time; pub(crate) mod watch; -#[cfg(any(feature = "http1", feature = "http2"))] -pub(crate) use self::never::Never; pub(crate) use self::task::Poll; // group up types normally needed for `Future` diff --git a/src/common/never.rs b/src/common/never.rs deleted file mode 100644 index f143caf60f..0000000000 --- a/src/common/never.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! An uninhabitable type meaning it can never happen. -//! -//! To be replaced with `!` once it is stable. - -use std::error::Error; -use std::fmt; - -#[derive(Debug)] -pub(crate) enum Never {} - -impl fmt::Display for Never { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self {} - } -} - -impl Error for Never { - fn description(&self) -> &str { - match *self {} - } -} diff --git a/src/common/task.rs b/src/common/task.rs index ec70c957d6..10a7802bdd 100644 --- a/src/common/task.rs +++ b/src/common/task.rs @@ -1,12 +1,12 @@ #[cfg(feature = "http1")] -use super::Never; +use std::convert::Infallible; pub(crate) use std::task::{Context, Poll}; /// 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. #[cfg(feature = "http1")] -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/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index c1d068a487..705bc77a4a 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -549,6 +549,8 @@ cfg_server! { // ===== impl Client ===== cfg_client! { + use std::convert::Infallible; + impl Client { pub(crate) fn new(rx: ClientRx) -> Client { Client { @@ -565,13 +567,13 @@ cfg_client! { { type PollItem = RequestHead; type PollBody = B; - type PollError = crate::common::Never; + type PollError = Infallible; type RecvItem = crate::proto::ResponseHead; fn poll_msg( mut self: Pin<&mut Self>, cx: &mut task::Context<'_>, - ) -> Poll>> { + ) -> Poll>> { let mut this = self.as_mut(); debug_assert!(!this.rx_closed); match this.rx.poll_recv(cx) { diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index ebd8822a5d..c6b24212e8 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -1,6 +1,4 @@ -use std::marker::PhantomData; - -use std::time::Duration; +use std::{convert::Infallible, marker::PhantomData, time::Duration}; use crate::rt::{Read, Write}; use bytes::Bytes; @@ -19,7 +17,7 @@ use crate::body::{Body, Incoming as IncomingBody}; use crate::client::dispatch::{Callback, SendWhen}; use crate::common::io::Compat; use crate::common::time::Time; -use crate::common::{task, Future, Never, Pin, Poll}; +use crate::common::{task, Future, Pin, Poll}; use crate::ext::Protocol; use crate::headers; use crate::proto::h2::UpgradedSendStream; @@ -33,11 +31,11 @@ type ClientRx = crate::client::dispatch::Receiver, Response; +type ConnDropRef = mpsc::Sender; ///// A oneshot channel watches the `Connection` task, and when it completes, ///// the "dispatch" task will be notified and can shutdown sooner. -type ConnEof = oneshot::Receiver; +type ConnEof = oneshot::Receiver; // Our defaults are chosen for the "majority" case, which usually are not // resource constrained, and so the spec default of 64kb can be too limiting @@ -267,9 +265,9 @@ pin_project! { T: Unpin, { #[pin] - drop_rx: StreamFuture>, + drop_rx: StreamFuture>, #[pin] - cancel_tx: Option>, + cancel_tx: Option>, #[pin] conn: ConnMapErr, } @@ -282,8 +280,8 @@ where { fn new( conn: ConnMapErr, - drop_rx: StreamFuture>, - cancel_tx: oneshot::Sender, + drop_rx: StreamFuture>, + cancel_tx: oneshot::Sender, ) -> Self { Self { drop_rx, @@ -421,7 +419,7 @@ pin_project! { #[pin] pipe: PipeToSendStream, #[pin] - conn_drop_ref: Option>, + conn_drop_ref: Option>, #[pin] ping: Option, }