Skip to content

Commit ec053fc

Browse files
committed
Replace empty enums with Never type
1 parent cd6983f commit ec053fc

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed

futures-core/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ pub mod stream;
2525

2626
pub mod task;
2727
#[doc(hidden)] pub use self::task::Poll;
28+
29+
pub mod never;
30+
#[doc(hidden)] pub use self::never::Never;

futures-core/src/never.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Definition of the `Never` type,
2+
//! a stand-in for the `!` type until it becomes stable.
3+
4+
/// A type with no possible values.
5+
///
6+
/// This is used to indicate values which can never be created, such as the
7+
/// error type of infallible futures.
8+
///
9+
/// This type is a stable equivalent to the `!` type from `std`.
10+
///
11+
/// This is currently an alias for [`std::convert::Infallible`], but in
12+
/// the future it may be an alias for [`!`][never].
13+
/// See ["Future compatibility" section of `std::convert::Infallible`][infallible] for more.
14+
///
15+
/// [never]: https://doc.rust-lang.org/nightly/std/primitive.never.html
16+
/// [infallible]: https://doc.rust-lang.org/nightly/std/convert/enum.Infallible.html#future-compatibility
17+
pub type Never = core::convert::Infallible;

futures-sink/src/lib.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,10 @@ mod channel_impls;
163163
#[cfg(feature = "alloc")]
164164
mod if_alloc {
165165
use super::*;
166+
use futures_core::never::Never;
166167

167-
/// The error type for `Vec` and `VecDequeue` when used as `Sink`s.
168-
/// Values of this type can never be created.
169-
#[derive(Copy, Clone, Debug)]
170-
pub enum VecSinkError {}
171-
172-
impl<T> Sink<T> for ::alloc::vec::Vec<T> {
173-
type SinkError = VecSinkError;
168+
impl<T> Sink<T> for alloc::vec::Vec<T> {
169+
type SinkError = Never;
174170

175171
fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
176172
Poll::Ready(Ok(()))
@@ -191,8 +187,8 @@ mod if_alloc {
191187
}
192188
}
193189

194-
impl<T> Sink<T> for ::alloc::collections::VecDeque<T> {
195-
type SinkError = VecSinkError;
190+
impl<T> Sink<T> for alloc::collections::VecDeque<T> {
191+
type SinkError = Never;
196192

197193
fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
198194
Poll::Ready(Ok(()))
@@ -213,7 +209,7 @@ mod if_alloc {
213209
}
214210
}
215211

216-
impl<S: ?Sized + Sink<Item> + Unpin, Item> Sink<Item> for ::alloc::boxed::Box<S> {
212+
impl<S: ?Sized + Sink<Item> + Unpin, Item> Sink<Item> for alloc::boxed::Box<S> {
217213
type SinkError = S::SinkError;
218214

219215
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
@@ -233,6 +229,3 @@ mod if_alloc {
233229
}
234230
}
235231
}
236-
237-
#[cfg(feature = "alloc")]
238-
pub use self::if_alloc::*;

futures-util/src/sink/drain.rs

+3-26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use core::fmt;
21
use core::marker::PhantomData;
32
use core::pin::Pin;
43
use futures_core::task::{Context, Poll};
4+
use futures_core::never::Never;
55
use futures_sink::Sink;
66

77
/// Sink for the [`drain`] function.
@@ -11,11 +11,6 @@ pub struct Drain<T> {
1111
marker: PhantomData<T>,
1212
}
1313

14-
/// The error type for the [`Drain`] sink.
15-
#[derive(Debug)]
16-
pub enum DrainError {
17-
}
18-
1914
/// Create a sink that will just discard all items given to it.
2015
///
2116
/// Similar to [`io::Sink`](::std::io::Sink).
@@ -29,14 +24,14 @@ pub enum DrainError {
2924
///
3025
/// let mut drain = sink::drain();
3126
/// drain.send(5).await?;
32-
/// # Ok::<(), futures::sink::DrainError>(()) }).unwrap();
27+
/// # Ok::<(), futures::never::Never>(()) }).unwrap();
3328
/// ```
3429
pub fn drain<T>() -> Drain<T> {
3530
Drain { marker: PhantomData }
3631
}
3732

3833
impl<T> Sink<T> for Drain<T> {
39-
type SinkError = DrainError;
34+
type SinkError = Never;
4035

4136
fn poll_ready(
4237
self: Pin<&mut Self>,
@@ -66,21 +61,3 @@ impl<T> Sink<T> for Drain<T> {
6661
Poll::Ready(Ok(()))
6762
}
6863
}
69-
70-
impl fmt::Display for DrainError {
71-
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
72-
match *self {
73-
}
74-
}
75-
}
76-
77-
#[cfg(feature = "std")]
78-
impl std::error::Error for DrainError {}
79-
80-
impl DrainError {
81-
/// Convert this drain error into any type
82-
pub fn into_any<T>(self) -> T {
83-
match self {
84-
}
85-
}
86-
}

futures-util/src/sink/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod close;
1515
pub use self::close::Close;
1616

1717
mod drain;
18-
pub use self::drain::{drain, Drain, DrainError};
18+
pub use self::drain::{drain, Drain};
1919

2020
mod fanout;
2121
pub use self::fanout::Fanout;

futures/src/lib.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ compile_error!("The `never-type` feature requires the `nightly` feature as an ex
6464

6565
#[doc(hidden)] pub use futures_core::task::Poll;
6666

67+
#[doc(hidden)] pub use futures_core::never::Never;
68+
6769
// Macro reexports
6870
pub use futures_util::ready; // Readiness propagation
6971
#[cfg(feature = "async-await")]
@@ -366,7 +368,7 @@ pub mod sink {
366368

367369
pub use futures_util::sink::{
368370
Close, Flush, Send, SendAll, SinkErrInto, SinkMapErr, With,
369-
SinkExt, Fanout, Drain, DrainError, drain,
371+
SinkExt, Fanout, Drain, drain,
370372
WithFlatMap,
371373
};
372374

@@ -500,6 +502,14 @@ pub mod task {
500502
pub use futures_util::task::AtomicWaker;
501503
}
502504

505+
pub mod never {
506+
//! This module contains the `Never` type.
507+
//!
508+
//! Values of this type can never be created and will never exist.
509+
510+
pub use futures_core::never::Never;
511+
}
512+
503513
// `select!` re-export --------------------------------------
504514

505515
#[cfg(feature = "async-await")]

0 commit comments

Comments
 (0)