From b1fb6366730586aa10c35127a78d1cbd766d0202 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 19 Jun 2019 18:50:15 +0900 Subject: [PATCH 1/3] Replace empty enums with Never type --- futures-core/src/lib.rs | 3 +++ futures-core/src/never.rs | 17 +++++++++++++++++ futures-sink/src/lib.rs | 19 ++++++------------- futures-util/src/sink/drain.rs | 29 +++-------------------------- futures-util/src/sink/mod.rs | 2 +- futures/src/lib.rs | 12 +++++++++++- 6 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 futures-core/src/never.rs diff --git a/futures-core/src/lib.rs b/futures-core/src/lib.rs index 375c99b5e5..ca4357e3d7 100644 --- a/futures-core/src/lib.rs +++ b/futures-core/src/lib.rs @@ -29,6 +29,9 @@ pub mod stream; pub mod task; #[doc(hidden)] pub use self::task::Poll; +pub mod never; +#[doc(hidden)] pub use self::never::Never; + #[doc(hidden)] pub mod core_reexport { #[doc(hidden)] diff --git a/futures-core/src/never.rs b/futures-core/src/never.rs new file mode 100644 index 0000000000..767c5af568 --- /dev/null +++ b/futures-core/src/never.rs @@ -0,0 +1,17 @@ +//! Definition of the `Never` type, +//! a stand-in for the `!` type until it becomes stable. + +/// A type with no possible values. +/// +/// This is used to indicate values which can never be created, such as the +/// error type of infallible futures. +/// +/// This type is a stable equivalent to the `!` type from `std`. +/// +/// This is currently an alias for [`std::convert::Infallible`], but in +/// the future it may be an alias for [`!`][never]. +/// See ["Future compatibility" section of `std::convert::Infallible`][infallible] for more. +/// +/// [never]: https://doc.rust-lang.org/nightly/std/primitive.never.html +/// [infallible]: https://doc.rust-lang.org/nightly/std/convert/enum.Infallible.html#future-compatibility +pub type Never = core::convert::Infallible; diff --git a/futures-sink/src/lib.rs b/futures-sink/src/lib.rs index a690ff9dae..99df50c354 100644 --- a/futures-sink/src/lib.rs +++ b/futures-sink/src/lib.rs @@ -165,14 +165,10 @@ mod channel_impls; #[cfg(feature = "alloc")] mod if_alloc { use super::*; + use futures_core::never::Never; - /// The error type for `Vec` and `VecDequeue` when used as `Sink`s. - /// Values of this type can never be created. - #[derive(Copy, Clone, Debug)] - pub enum VecSinkError {} - - impl Sink for ::alloc::vec::Vec { - type SinkError = VecSinkError; + impl Sink for alloc::vec::Vec { + type SinkError = Never; fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) @@ -193,8 +189,8 @@ mod if_alloc { } } - impl Sink for ::alloc::collections::VecDeque { - type SinkError = VecSinkError; + impl Sink for alloc::collections::VecDeque { + type SinkError = Never; fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) @@ -215,7 +211,7 @@ mod if_alloc { } } - impl + Unpin, Item> Sink for ::alloc::boxed::Box { + impl + Unpin, Item> Sink for alloc::boxed::Box { type SinkError = S::SinkError; fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { @@ -235,6 +231,3 @@ mod if_alloc { } } } - -#[cfg(feature = "alloc")] -pub use self::if_alloc::*; diff --git a/futures-util/src/sink/drain.rs b/futures-util/src/sink/drain.rs index 558d7a153a..6318bb18ee 100644 --- a/futures-util/src/sink/drain.rs +++ b/futures-util/src/sink/drain.rs @@ -1,7 +1,7 @@ -use core::fmt; use core::marker::PhantomData; use core::pin::Pin; use futures_core::task::{Context, Poll}; +use futures_core::never::Never; use futures_sink::Sink; /// Sink for the [`drain`] function. @@ -11,11 +11,6 @@ pub struct Drain { marker: PhantomData, } -/// The error type for the [`Drain`] sink. -#[derive(Debug)] -pub enum DrainError { -} - /// Create a sink that will just discard all items given to it. /// /// Similar to [`io::Sink`](::std::io::Sink). @@ -29,14 +24,14 @@ pub enum DrainError { /// /// let mut drain = sink::drain(); /// drain.send(5).await?; -/// # Ok::<(), futures::sink::DrainError>(()) }).unwrap(); +/// # Ok::<(), futures::never::Never>(()) }).unwrap(); /// ``` pub fn drain() -> Drain { Drain { marker: PhantomData } } impl Sink for Drain { - type SinkError = DrainError; + type SinkError = Never; fn poll_ready( self: Pin<&mut Self>, @@ -66,21 +61,3 @@ impl Sink for Drain { Poll::Ready(Ok(())) } } - -impl fmt::Display for DrainError { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self { - } - } -} - -#[cfg(feature = "std")] -impl std::error::Error for DrainError {} - -impl DrainError { - /// Convert this drain error into any type - pub fn into_any(self) -> T { - match self { - } - } -} diff --git a/futures-util/src/sink/mod.rs b/futures-util/src/sink/mod.rs index 45d4423e50..9ff4455931 100644 --- a/futures-util/src/sink/mod.rs +++ b/futures-util/src/sink/mod.rs @@ -15,7 +15,7 @@ mod close; pub use self::close::Close; mod drain; -pub use self::drain::{drain, Drain, DrainError}; +pub use self::drain::{drain, Drain}; mod fanout; pub use self::fanout::Fanout; diff --git a/futures/src/lib.rs b/futures/src/lib.rs index 3182bf41c5..eed533b44f 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -66,6 +66,8 @@ compile_error!("The `never-type` feature requires the `nightly` feature as an ex #[doc(hidden)] pub use futures_core::task::Poll; +#[doc(hidden)] pub use futures_core::never::Never; + // Macro reexports pub use futures_core::ready; // Readiness propagation pub use futures_util::pin_mut; @@ -369,7 +371,7 @@ pub mod sink { pub use futures_util::sink::{ Close, Flush, Send, SendAll, SinkErrInto, SinkMapErr, With, - SinkExt, Fanout, Drain, DrainError, drain, + SinkExt, Fanout, Drain, drain, WithFlatMap, }; @@ -504,6 +506,14 @@ pub mod task { pub use futures_util::task::AtomicWaker; } +pub mod never { + //! This module contains the `Never` type. + //! + //! Values of this type can never be created and will never exist. + + pub use futures_core::never::Never; +} + // `select!` re-export -------------------------------------- #[cfg(feature = "async-await")] From c730359cbc45bfbe62d858cd7f5891a3a1c81af0 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Tue, 2 Jul 2019 18:56:12 +0900 Subject: [PATCH 2/3] Use Never type in FutureExt::never_error --- futures-util/Cargo.toml | 1 - futures-util/src/future/mod.rs | 5 +---- futures-util/src/future/never_error.rs | 5 +++-- futures-util/src/lib.rs | 4 ---- futures/Cargo.toml | 1 - futures/src/lib.rs | 8 +------- 6 files changed, 5 insertions(+), 19 deletions(-) diff --git a/futures-util/Cargo.toml b/futures-util/Cargo.toml index bb5daa4d62..78b34df92e 100644 --- a/futures-util/Cargo.toml +++ b/futures-util/Cargo.toml @@ -23,7 +23,6 @@ io-compat = ["compat", "tokio-io"] bench = [] nightly = ["futures-core-preview/nightly", "futures-sink-preview/nightly"] cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic"] -never-type = [] alloc = ["futures-core-preview/alloc", "futures-sink-preview/alloc"] [dependencies] diff --git a/futures-util/src/future/mod.rs b/futures-util/src/future/mod.rs index f44bfb0cdb..d74bcb8735 100644 --- a/futures-util/src/future/mod.rs +++ b/futures-util/src/future/mod.rs @@ -76,9 +76,7 @@ pub use self::inspect::Inspect; mod unit_error; pub use self::unit_error::UnitError; -#[cfg(feature = "never-type")] mod never_error; -#[cfg(feature = "never-type")] pub use self::never_error::NeverError; mod either; @@ -516,9 +514,8 @@ pub trait FutureExt: Future { UnitError::new(self) } - #[cfg(feature = "never-type")] /// Turns a [`Future`](Future) into a - /// [`TryFuture](futures_core::future::TryFuture). + /// [`TryFuture](futures_core::future::TryFuture). fn never_error(self) -> NeverError where Self: Sized { diff --git a/futures-util/src/future/never_error.rs b/futures-util/src/future/never_error.rs index 8924ec6ceb..6e8094c118 100644 --- a/futures-util/src/future/never_error.rs +++ b/futures-util/src/future/never_error.rs @@ -1,6 +1,7 @@ use core::pin::Pin; use futures_core::future::{FusedFuture, Future}; use futures_core::task::{self, Poll}; +use futures_core::never::Never; use pin_utils::unsafe_pinned; /// Future for the [`never_error`](super::FutureExt::never_error) combinator. @@ -27,9 +28,9 @@ impl FusedFuture for NeverError { impl Future for NeverError where Fut: Future, { - type Output = Result; + type Output = Result; - fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll> { + fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { self.future().poll(cx).map(Ok) } } diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs index b2308b32bc..e234003a98 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -3,7 +3,6 @@ #![cfg_attr(feature = "async-await", feature(async_await))] #![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))] -#![cfg_attr(feature = "never-type", feature(never_type))] #![cfg_attr(not(feature = "std"), no_std)] #![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)] @@ -18,9 +17,6 @@ #[cfg(all(feature = "cfg-target-has-atomic", not(feature = "nightly")))] compile_error!("The `cfg-target-has-atomic` feature requires the `nightly` feature as an explicit opt-in to unstable features"); -#[cfg(all(feature = "never-type", not(feature = "nightly")))] -compile_error!("The `never-type` feature requires the `nightly` feature as an explicit opt-in to unstable features"); - #[cfg(all(feature = "async-await", not(feature = "nightly")))] compile_error!("The `async-await` feature requires the `nightly` feature as an explicit opt-in to unstable features"); diff --git a/futures/Cargo.toml b/futures/Cargo.toml index 856b5e26c7..48bcb67988 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -44,7 +44,6 @@ default = ["std"] compat = ["std", "futures-util-preview/compat"] io-compat = ["compat", "futures-util-preview/io-compat"] cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic", "futures-util-preview/cfg-target-has-atomic"] -never-type = ["futures-util-preview/never-type"] alloc = ["futures-core-preview/alloc", "futures-sink-preview/alloc", "futures-util-preview/alloc"] [package.metadata.docs.rs] diff --git a/futures/src/lib.rs b/futures/src/lib.rs index eed533b44f..b29dcc48eb 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -22,7 +22,6 @@ //! completion, but *do not block* the thread running them. #![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))] -#![cfg_attr(feature = "never-type", feature(never_type))] #![cfg_attr(not(feature = "std"), no_std)] @@ -41,9 +40,6 @@ compile_error!("The `async-await` feature requires the `nightly` feature as an e #[cfg(all(feature = "cfg-target-has-atomic", not(feature = "nightly")))] compile_error!("The `cfg-target-has-atomic` feature requires the `nightly` feature as an explicit opt-in to unstable features"); -#[cfg(all(feature = "never-type", not(feature = "nightly")))] -compile_error!("The `never-type` feature requires the `nightly` feature as an explicit opt-in to unstable features"); - #[doc(hidden)] pub use futures_core::core_reexport; #[doc(hidden)] pub use futures_core::future::Future; @@ -227,6 +223,7 @@ pub mod future { FutureExt, FlattenStream, Flatten, Fuse, Inspect, IntoStream, Map, Then, UnitError, + NeverError, }; #[cfg(feature = "alloc")] @@ -261,9 +258,6 @@ pub mod future { InspectOk, InspectErr, TryFlattenStream, UnwrapOrElse, }; - #[cfg(feature = "never-type")] - pub use futures_util::future::NeverError; - #[cfg(feature = "alloc")] pub use futures_util::try_future::{ try_join_all, TryJoinAll, From a943d6501834766072462a628641c418bfe5a307 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 3 Jul 2019 03:24:05 +0900 Subject: [PATCH 3/3] ci: Temporarily disable caching --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2b3ae0be39..b9e785b773 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: rust sudo: false -cache: cargo +# TODO: https://github.com/rust-lang-nursery/futures-rs/pull/1681#issuecomment-507791279 +# cache: cargo stages: - name: test