Skip to content

Commit

Permalink
Use Never type in FutureExt::never_error
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jul 2, 2019
1 parent b1fb636 commit b334141
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 19 deletions.
1 change: 0 additions & 1 deletion futures-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 1 addition & 4 deletions futures-util/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -516,9 +514,8 @@ pub trait FutureExt: Future {
UnitError::new(self)
}

#[cfg(feature = "never-type")]
/// Turns a [`Future<Output = T>`](Future) into a
/// [`TryFuture<Ok = T, Error = !`>](futures_core::future::TryFuture).
/// [`TryFuture<Ok = T, Error = Never`>](futures_core::future::TryFuture).
fn never_error(self) -> NeverError<Self>
where Self: Sized
{
Expand Down
5 changes: 3 additions & 2 deletions futures-util/src/future/never_error.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -27,9 +28,9 @@ impl<Fut: FusedFuture> FusedFuture for NeverError<Fut> {
impl<Fut, T> Future for NeverError<Fut>
where Fut: Future<Output = T>,
{
type Output = Result<T, !>;
type Output = Result<T, Never>;

fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Result<T, !>> {
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
self.future().poll(cx).map(Ok)
}
}
4 changes: 0 additions & 4 deletions futures-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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");

Expand Down
1 change: 0 additions & 1 deletion futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 1 addition & 7 deletions futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand All @@ -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;
Expand Down Expand Up @@ -227,6 +223,7 @@ pub mod future {

FutureExt,
FlattenStream, Flatten, Fuse, Inspect, IntoStream, Map, Then, UnitError,
NeverError,
};

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b334141

Please sign in to comment.