diff --git a/.travis.yml b/.travis.yml index 7716513128..99b369bfbe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,7 +75,7 @@ matrix: rust: nightly script: - cargo bench --all - - cargo bench --manifest-path futures-util/Cargo.toml --features=bench,unstable + - cargo bench --manifest-path futures-util/Cargo.toml --features=bilock,unstable - name: cargo +stable build --no-default-features rust: stable @@ -146,11 +146,18 @@ matrix: - cargo check --manifest-path futures-util/Cargo.toml --features io-compat - cargo check --manifest-path futures-util/Cargo.toml --features sink,compat - cargo check --manifest-path futures-util/Cargo.toml --features sink,channel + - cargo check --manifest-path futures-util/Cargo.toml --features bilock,unstable + - cargo check --manifest-path futures-util/Cargo.toml --features sink,bilock,unstable + - cargo check --manifest-path futures-util/Cargo.toml --features io,bilock,unstable + - cargo check --manifest-path futures-util/Cargo.toml --features sink,io - cargo check --manifest-path futures-util/Cargo.toml --no-default-features - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features sink - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features alloc,sink - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features async-await + - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features bilock,unstable + - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features sink,bilock,unstable + - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features io,bilock,unstable - name: cargo doc rust: nightly diff --git a/futures-util/Cargo.toml b/futures-util/Cargo.toml index 32654e073b..360dd3ec3f 100644 --- a/futures-util/Cargo.toml +++ b/futures-util/Cargo.toml @@ -32,7 +32,7 @@ select-macro = ["async-await", "futures-select-macro-preview", "proc-macro-hack" # `unstable` feature as an explicit opt-in to unstable API. unstable = ["futures-core-preview/unstable"] cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic"] -bench = [] +bilock = [] [dependencies] futures-core-preview = { path = "../futures-core", version = "=0.3.0-alpha.18", default-features = false } diff --git a/futures-util/benches_disabled/bilock.rs b/futures-util/benches_disabled/bilock.rs index 4b1a172ecc..78b5edb6bf 100644 --- a/futures-util/benches_disabled/bilock.rs +++ b/futures-util/benches_disabled/bilock.rs @@ -1,6 +1,6 @@ #![feature(test)] -#[cfg(feature = "bench")] +#[cfg(feature = "bilock")] mod bench { use futures::task::{Context, Waker}; use futures::executor::LocalPool; diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs index db95c297ea..ef216e650e 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -16,8 +16,8 @@ #[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))] compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features"); -#[cfg(all(feature = "bench", not(feature = "unstable")))] -compile_error!("The `bench` feature requires the `unstable` feature as an explicit opt-in to unstable features"); +#[cfg(all(feature = "bilock", not(feature = "unstable")))] +compile_error!("The `bilock` feature requires the `unstable` feature as an explicit opt-in to unstable features"); #[cfg(feature = "alloc")] extern crate alloc; diff --git a/futures-util/src/lock/bilock.rs b/futures-util/src/lock/bilock.rs index f749dc2af6..8ea809d07a 100644 --- a/futures-util/src/lock/bilock.rs +++ b/futures-util/src/lock/bilock.rs @@ -1,11 +1,10 @@ //! Futures-powered synchronization primitives. -#![allow(unused)] +#[cfg(feature = "bilock")] use futures_core::future::Future; use futures_core::task::{Context, Poll, Waker}; use core::cell::UnsafeCell; use core::fmt; -use core::mem; use core::ops::{Deref, DerefMut}; use core::pin::Pin; use core::sync::atomic::AtomicUsize; @@ -35,6 +34,9 @@ use std::error::Error; /// example a TCP stream could be both a reader and a writer or a framing layer /// could be both a stream and a sink for messages. A `BiLock` enables splitting /// these two and then using each independently in a futures-powered fashion. +/// +/// This type is only available when the `bilock` feature of this +/// library is activated. #[derive(Debug)] pub struct BiLock { arc: Arc>, @@ -140,6 +142,7 @@ impl BiLock { /// `BiLockGuard`. /// /// Note that the returned future will never resolve to an error. + #[cfg(feature = "bilock")] pub fn lock(&self) -> BiLockAcquire<'_, T> { BiLockAcquire { bilock: self, @@ -149,6 +152,7 @@ impl BiLock { /// Attempts to put the two "halves" of a `BiLock` back together and /// recover the original value. Succeeds only if the two `BiLock`s /// originated from the same call to `BiLock::new`. + #[cfg(any(feature = "bilock", feature = "sink"))] pub fn reunite(self, other: Self) -> Result> where T: Unpin, @@ -182,6 +186,7 @@ impl BiLock { } } +#[cfg(any(feature = "bilock", feature = "sink"))] impl Inner { unsafe fn into_value(mut self) -> T { self.value.take().unwrap().into_inner() @@ -255,6 +260,7 @@ impl Drop for BiLockGuard<'_, T> { /// Future returned by `BiLock::lock` which will resolve when the lock is /// acquired. +#[cfg(feature = "bilock")] #[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct BiLockAcquire<'a, T> { @@ -262,8 +268,10 @@ pub struct BiLockAcquire<'a, T> { } // Pinning is never projected to fields +#[cfg(feature = "bilock")] impl Unpin for BiLockAcquire<'_, T> {} +#[cfg(feature = "bilock")] impl<'a, T> Future for BiLockAcquire<'a, T> { type Output = BiLockGuard<'a, T>; diff --git a/futures-util/src/lock/mod.rs b/futures-util/src/lock/mod.rs index 7a5dc11461..6d831f3dcb 100644 --- a/futures-util/src/lock/mod.rs +++ b/futures-util/src/lock/mod.rs @@ -1,16 +1,18 @@ //! Futures-powered synchronization primitives. +//! +//! This module is only available when the `std` or `alloc` feature of this +//! library is activated, and it is activated by default. #[cfg(feature = "std")] mod mutex; #[cfg(feature = "std")] pub use self::mutex::{Mutex, MutexLockFuture, MutexGuard}; -#[cfg(any(feature = "sink", feature = "io"))] -#[allow(unreachable_pub)] +#[cfg(any(feature = "bilock", feature = "sink", feature = "io"))] +#[cfg_attr(not(feature = "bilock"), allow(unreachable_pub))] mod bilock; -#[cfg(any(feature = "sink", feature = "io"))] -#[cfg(any(test, feature = "bench"))] +#[cfg(feature = "bilock")] pub use self::bilock::{BiLock, BiLockAcquire, BiLockGuard, ReuniteError}; #[cfg(any(feature = "sink", feature = "io"))] -#[cfg(not(any(test, feature = "bench")))] +#[cfg(not(feature = "bilock"))] pub(crate) use self::bilock::BiLock; diff --git a/futures/Cargo.toml b/futures/Cargo.toml index 56d6355bc6..e17f4833d1 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -48,6 +48,7 @@ io-compat = ["compat", "futures-util-preview/io-compat"] # `unstable` feature as an explicit opt-in to unstable API. unstable = ["futures-core-preview/unstable", "futures-channel-preview/unstable", "futures-util-preview/unstable"] cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic", "futures-channel-preview/cfg-target-has-atomic", "futures-util-preview/cfg-target-has-atomic"] +bilock = ["futures-util-preview/bilock"] [package.metadata.docs.rs] all-features = true diff --git a/futures/src/lib.rs b/futures/src/lib.rs index c238efb9f7..3cfef84425 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -37,6 +37,9 @@ #[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))] compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features"); +#[cfg(all(feature = "bilock", not(feature = "unstable")))] +compile_error!("The `bilock` feature requires the `unstable` 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; @@ -307,13 +310,21 @@ pub mod io { }; } -#[cfg(feature = "std")] +#[cfg_attr( + feature = "cfg-target-has-atomic", + cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) +)] +#[cfg(feature = "alloc")] pub mod lock { //! Futures-powered synchronization primitives. //! - //! This module is only available when the `std` feature of this + //! This module is only available when the `std` or `alloc` feature of this //! library is activated, and it is activated by default. + #[cfg(feature = "bilock")] + pub use futures_util::lock::{BiLock, BiLockAcquire, BiLockGuard, ReuniteError}; + + #[cfg(feature = "std")] pub use futures_util::lock::{Mutex, MutexLockFuture, MutexGuard}; } diff --git a/futures-util/bilock.rs b/futures/tests_disabled/bilock.rs similarity index 100% rename from futures-util/bilock.rs rename to futures/tests_disabled/bilock.rs