Skip to content

Commit a3c9fde

Browse files
authored
refactor(common): replace Never with Infallible (#3392)
1 parent 8e6095e commit a3c9fde

File tree

9 files changed

+25
-47
lines changed

9 files changed

+25
-47
lines changed

src/body/body.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::borrow::Cow;
2+
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
3+
use std::convert::Infallible;
24
#[cfg(feature = "stream")]
35
use std::error::Error as StdError;
46
use std::fmt;
@@ -19,8 +21,6 @@ use super::DecodedLength;
1921
#[cfg(feature = "stream")]
2022
use crate::common::sync_wrapper::SyncWrapper;
2123
use crate::common::watch;
22-
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
23-
use crate::common::Never;
2424
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
2525
use crate::proto::h2::ping;
2626

@@ -79,7 +79,7 @@ struct Extra {
7979
}
8080

8181
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
82-
type DelayEofUntil = oneshot::Receiver<Never>;
82+
type DelayEofUntil = oneshot::Receiver<Infallible>;
8383

8484
enum DelayEof {
8585
/// Initial state, stream hasn't seen EOF yet.

src/client/conn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub mod http1;
5959
#[cfg(all(feature = "backports", feature = "http2"))]
6060
pub mod http2;
6161

62+
#[cfg(not(all(feature = "http1", feature = "http2")))]
63+
use std::convert::Infallible;
6264
use std::error::Error as StdError;
6365
use std::fmt;
6466
use std::future::Future;
@@ -82,8 +84,6 @@ use tracing::{debug, trace};
8284
use super::dispatch;
8385
use crate::body::HttpBody;
8486
use crate::common::exec::{BoxSendFuture, Exec};
85-
#[cfg(not(all(feature = "http1", feature = "http2")))]
86-
use crate::common::Never;
8787
use crate::proto;
8888
use crate::rt::Executor;
8989
#[cfg(feature = "http1")]
@@ -95,13 +95,13 @@ type Http1Dispatcher<T, B> =
9595
proto::dispatch::Dispatcher<proto::dispatch::Client<B>, B, T, proto::h1::ClientTransaction>;
9696

9797
#[cfg(not(feature = "http1"))]
98-
type Http1Dispatcher<T, B> = (Never, PhantomData<(T, Pin<Box<B>>)>);
98+
type Http1Dispatcher<T, B> = (Infallible, PhantomData<(T, Pin<Box<B>>)>);
9999

100100
#[cfg(feature = "http2")]
101101
type Http2ClientTask<B> = proto::h2::ClientTask<B>;
102102

103103
#[cfg(not(feature = "http2"))]
104-
type Http2ClientTask<B> = (Never, PhantomData<Pin<Box<B>>>);
104+
type Http2ClientTask<B> = (Infallible, PhantomData<Pin<Box<B>>>);
105105

106106
pin_project! {
107107
#[project = ProtoClientProj]

src/client/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct PoolInner<T> {
8383
// A oneshot channel is used to allow the interval to be notified when
8484
// the Pool completely drops. That way, the interval can cancel immediately.
8585
#[cfg(feature = "runtime")]
86-
idle_interval_ref: Option<oneshot::Sender<crate::common::Never>>,
86+
idle_interval_ref: Option<oneshot::Sender<std::convert::Infallible>>,
8787
#[cfg(feature = "runtime")]
8888
exec: Exec,
8989
timeout: Option<Duration>,
@@ -741,7 +741,7 @@ pin_project_lite::pin_project! {
741741
// Pool is fully dropped, and shutdown. This channel is never sent on,
742742
// but Err(Canceled) will be received when the Pool is dropped.
743743
#[pin]
744-
pool_drop_notifier: oneshot::Receiver<crate::common::Never>,
744+
pool_drop_notifier: oneshot::Receiver<std::convert::Infallible>,
745745
}
746746
}
747747

src/common/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub(crate) mod exec;
1717
pub(crate) mod io;
1818
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
1919
mod lazy;
20-
mod never;
2120
#[cfg(any(
2221
feature = "stream",
2322
all(feature = "client", any(feature = "http1", feature = "http2"))
@@ -29,5 +28,3 @@ pub(crate) mod watch;
2928

3029
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
3130
pub(crate) use self::lazy::{lazy, Started as Lazy};
32-
#[cfg(any(feature = "http1", feature = "http2", feature = "runtime"))]
33-
pub(crate) use self::never::Never;

src/common/never.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/common/task.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use std::task::{Context, Poll};
2-
3-
use super::Never;
1+
use std::{
2+
convert::Infallible,
3+
task::{Context, Poll},
4+
};
45

56
/// A function to help "yield" a future, such that it is re-scheduled immediately.
67
///
78
/// Useful for spin counts, so a future doesn't hog too much time.
8-
pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll<Never> {
9+
pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll<Infallible> {
910
cx.waker().wake_by_ref();
1011
Poll::Pending
1112
}

src/proto/h1/dispatch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,13 @@ cfg_client! {
566566
{
567567
type PollItem = RequestHead;
568568
type PollBody = B;
569-
type PollError = crate::common::Never;
569+
type PollError = std::convert::Infallible;
570570
type RecvItem = crate::proto::ResponseHead;
571571

572572
fn poll_msg(
573573
mut self: Pin<&mut Self>,
574574
cx: &mut Context<'_>,
575-
) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), crate::common::Never>>> {
575+
) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), Self::PollError>>> {
576576
let mut this = self.as_mut();
577577
debug_assert!(!this.rx_closed);
578578
match this.rx.poll_recv(cx) {

src/proto/h2/client.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::convert::Infallible;
12
use std::error::Error as StdError;
23
use std::future::Future;
34
use std::marker::Unpin;
@@ -19,7 +20,7 @@ use tracing::{debug, trace, warn};
1920
use super::{ping, H2Upgraded, PipeToSendStream, SendBuf};
2021
use crate::body::HttpBody;
2122
use crate::client::dispatch::Callback;
22-
use crate::common::{exec::Exec, Never};
23+
use crate::common::exec::Exec;
2324
use crate::ext::Protocol;
2425
use crate::headers;
2526
use crate::proto::h2::UpgradedSendStream;
@@ -32,11 +33,11 @@ type ClientRx<B> = crate::client::dispatch::Receiver<Request<B>, Response<Body>>
3233

3334
///// An mpsc channel is used to help notify the `Connection` task when *all*
3435
///// other handles to it have been dropped, so that it can shutdown.
35-
type ConnDropRef = mpsc::Sender<Never>;
36+
type ConnDropRef = mpsc::Sender<Infallible>;
3637

3738
///// A oneshot channel watches the `Connection` task, and when it completes,
3839
///// the "dispatch" task will be notified and can shutdown sooner.
39-
type ConnEof = oneshot::Receiver<Never>;
40+
type ConnEof = oneshot::Receiver<Infallible>;
4041

4142
// Our defaults are chosen for the "majority" case, which usually are not
4243
// resource constrained, and so the spec default of 64kb can be too limiting
@@ -181,7 +182,7 @@ where
181182
})
182183
}
183184

184-
async fn conn_task<C, D>(conn: C, drop_rx: D, cancel_tx: oneshot::Sender<Never>)
185+
async fn conn_task<C, D>(conn: C, drop_rx: D, cancel_tx: oneshot::Sender<Infallible>)
185186
where
186187
C: Future + Unpin,
187188
D: Future<Output = ()> + Unpin,

src/server/conn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ cfg_feature! {
7272
use std::pin::Pin;
7373
use std::future::Future;
7474
use std::marker::Unpin;
75+
#[cfg(not(all(feature = "http1", feature = "http2")))]
76+
use std::convert::Infallible;
7577

7678
use bytes::Bytes;
7779
use pin_project_lite::pin_project;
@@ -80,8 +82,6 @@ cfg_feature! {
8082

8183
pub use super::server::Connecting;
8284
use crate::body::{Body, HttpBody};
83-
#[cfg(not(all(feature = "http1", feature = "http2")))]
84-
use crate::common::Never;
8585
use crate::common::exec::{ConnStreamExec, Exec};
8686
use crate::proto;
8787
use crate::service::HttpService;
@@ -159,14 +159,14 @@ type Http1Dispatcher<T, B, S> =
159159
proto::h1::Dispatcher<proto::h1::dispatch::Server<S, Body>, B, T, proto::ServerTransaction>;
160160

161161
#[cfg(all(not(feature = "http1"), feature = "http2"))]
162-
type Http1Dispatcher<T, B, S> = (Never, PhantomData<(T, Box<Pin<B>>, Box<Pin<S>>)>);
162+
type Http1Dispatcher<T, B, S> = (Infallible, PhantomData<(T, Box<Pin<B>>, Box<Pin<S>>)>);
163163

164164
#[cfg(feature = "http2")]
165165
type Http2Server<T, B, S, E> = proto::h2::Server<Rewind<T>, S, B, E>;
166166

167167
#[cfg(all(not(feature = "http2"), feature = "http1"))]
168168
type Http2Server<T, B, S, E> = (
169-
Never,
169+
Infallible,
170170
PhantomData<(T, Box<Pin<S>>, Box<Pin<B>>, Box<Pin<E>>)>,
171171
);
172172

0 commit comments

Comments
 (0)