From e84500a37217b4d7270e20d1350341bf3e168d23 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Tue, 19 Mar 2019 18:24:26 +0900 Subject: [PATCH] Avoid redundant cfg --- futures-util/src/future/mod.rs | 24 +++--- futures-util/src/lib.rs | 10 +-- futures-util/src/macros/mod.rs | 10 +++ futures-util/src/stream/mod.rs | 126 +++++++++-------------------- futures-util/src/task/mod.rs | 72 ++++++----------- futures-util/src/try_stream/mod.rs | 44 +++------- 6 files changed, 97 insertions(+), 189 deletions(-) diff --git a/futures-util/src/future/mod.rs b/futures-util/src/future/mod.rs index ad5e8453cf..1605a41d23 100644 --- a/futures-util/src/future/mod.rs +++ b/futures-util/src/future/mod.rs @@ -69,18 +69,17 @@ pub use self::unit_error::UnitError; mod chain; pub(crate) use self::chain::Chain; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] #[cfg(feature = "alloc")] -mod abortable; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] +mod join_all; #[cfg(feature = "alloc")] -pub use self::abortable::{abortable, Abortable, AbortHandle, AbortRegistration, Aborted}; +pub use self::join_all::{join_all, JoinAll}; + +cfg_target_has_atomic! { + #[cfg(feature = "alloc")] + mod abortable; + #[cfg(feature = "alloc")] + pub use self::abortable::{abortable, Abortable, AbortHandle, AbortRegistration, Aborted}; +} #[cfg(feature = "std")] mod catch_unwind; @@ -92,11 +91,6 @@ mod remote_handle; #[cfg(feature = "std")] pub use self::remote_handle::{Remote, RemoteHandle}; -#[cfg(feature = "alloc")] -mod join_all; -#[cfg(feature = "alloc")] -pub use self::join_all::{join_all, JoinAll}; - // #[cfg(feature = "std")] // mod select_all; // #[cfg(feature = "std")] diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs index f6673b12bc..d01bf36ea6 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -101,9 +101,7 @@ pub mod io; #[cfg(feature = "std")] #[doc(hidden)] pub use crate::io::{AsyncReadExt, AsyncWriteExt}; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub mod lock; +cfg_target_has_atomic! { + #[cfg(feature = "alloc")] + pub mod lock; +} diff --git a/futures-util/src/macros/mod.rs b/futures-util/src/macros/mod.rs index f0e9f05edc..0a9ac422c1 100644 --- a/futures-util/src/macros/mod.rs +++ b/futures-util/src/macros/mod.rs @@ -1,2 +1,12 @@ #[macro_use] mod poll; + +macro_rules! cfg_target_has_atomic { + ($($item:item)*) => {$( + #[cfg_attr( + feature = "cfg-target-has-atomic", + cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) + )] + $item + )*}; +} diff --git a/futures-util/src/stream/mod.rs b/futures-util/src/stream/mod.rs index daa04193ab..3b734dad8e 100644 --- a/futures-util/src/stream/mod.rs +++ b/futures-util/src/stream/mod.rs @@ -99,106 +99,52 @@ pub use self::unfold::{unfold, Unfold}; mod zip; pub use self::zip::Zip; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] #[cfg(feature = "alloc")] -mod buffer_unordered; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] +mod chunks; #[cfg(feature = "alloc")] -pub use self::buffer_unordered::BufferUnordered; +pub use self::chunks::Chunks; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod buffered; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::buffered::Buffered; +cfg_target_has_atomic! { + #[cfg(feature = "alloc")] + mod buffer_unordered; + #[cfg(feature = "alloc")] + pub use self::buffer_unordered::BufferUnordered; -#[cfg(feature = "std")] -mod catch_unwind; -#[cfg(feature = "std")] -pub use self::catch_unwind::CatchUnwind; + #[cfg(feature = "alloc")] + mod buffered; + #[cfg(feature = "alloc")] + pub use self::buffered::Buffered; -#[cfg(feature = "alloc")] -mod chunks; -#[cfg(feature = "alloc")] -pub use self::chunks::Chunks; + #[cfg(feature = "alloc")] + mod for_each_concurrent; + #[cfg(feature = "alloc")] + pub use self::for_each_concurrent::ForEachConcurrent; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod for_each_concurrent; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::for_each_concurrent::ForEachConcurrent; + #[cfg(feature = "alloc")] + mod futures_ordered; + #[cfg(feature = "alloc")] + pub use self::futures_ordered::{futures_ordered, FuturesOrdered}; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod futures_ordered; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::futures_ordered::{futures_ordered, FuturesOrdered}; + #[cfg(feature = "alloc")] + mod futures_unordered; + #[cfg(feature = "alloc")] + pub use self::futures_unordered::{futures_unordered, FuturesUnordered}; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod futures_unordered; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::futures_unordered::{futures_unordered, FuturesUnordered}; + #[cfg(feature = "alloc")] + mod split; + #[cfg(feature = "alloc")] + pub use self::split::{SplitStream, SplitSink, ReuniteError}; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod split; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::split::{SplitStream, SplitSink, ReuniteError}; + #[cfg(feature = "alloc")] + mod select_all; + #[cfg(feature = "alloc")] + pub use self::select_all::{select_all, SelectAll}; +} -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod select_all; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::select_all::{select_all, SelectAll}; +#[cfg(feature = "std")] +mod catch_unwind; +#[cfg(feature = "std")] +pub use self::catch_unwind::CatchUnwind; impl StreamExt for T where T: Stream {} diff --git a/futures-util/src/task/mod.rs b/futures-util/src/task/mod.rs index 3802673c5b..d686272124 100644 --- a/futures-util/src/task/mod.rs +++ b/futures-util/src/task/mod.rs @@ -1,34 +1,31 @@ //! Task notification -/// A macro for creating a `RawWaker` vtable for a type that implements -/// the `ArcWake` trait. -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -macro_rules! waker_vtable { - ($ty:ident) => { - &RawWakerVTable { - clone: clone_arc_raw::<$ty>, - drop: drop_arc_raw::<$ty>, - wake: wake_arc_raw::<$ty>, - } - }; -} +cfg_target_has_atomic! { + /// A macro for creating a `RawWaker` vtable for a type that implements + /// the `ArcWake` trait. + #[cfg(feature = "alloc")] + macro_rules! waker_vtable { + ($ty:ident) => { + &RawWakerVTable { + clone: clone_arc_raw::<$ty>, + drop: drop_arc_raw::<$ty>, + wake: wake_arc_raw::<$ty>, + } + }; + } + + #[cfg(feature = "alloc")] + mod arc_wake; + #[cfg(feature = "alloc")] + pub use self::arc_wake::ArcWake; + + #[cfg(feature = "alloc")] + mod waker_ref; + #[cfg(feature = "alloc")] + pub use self::waker_ref::{waker_ref, WakerRef}; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod arc_wake; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::arc_wake::ArcWake; + pub use futures_core::task::__internal::AtomicWaker; +} mod noop_waker; pub use self::noop_waker::noop_waker; @@ -38,25 +35,6 @@ pub use self::noop_waker::noop_waker_ref; mod spawn; pub use self::spawn::{SpawnExt, LocalSpawnExt}; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod waker_ref; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::waker_ref::{waker_ref, WakerRef}; - -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -pub use futures_core::task::__internal::AtomicWaker; - // re-export for `select!` #[doc(hidden)] pub use futures_core::task::{Waker, Poll}; diff --git a/futures-util/src/try_stream/mod.rs b/futures-util/src/try_stream/mod.rs index 98fb9a1f33..a71798bd07 100644 --- a/futures-util/src/try_stream/mod.rs +++ b/futures-util/src/try_stream/mod.rs @@ -44,37 +44,19 @@ pub use self::try_fold::TryFold; mod try_skip_while; pub use self::try_skip_while::TrySkipWhile; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod try_buffer_unordered; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::try_buffer_unordered::TryBufferUnordered; - -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -mod try_for_each_concurrent; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -pub use self::try_for_each_concurrent::TryForEachConcurrent; -#[cfg_attr( - feature = "cfg-target-has-atomic", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -#[cfg(feature = "alloc")] -use futures_core::future::Future; +cfg_target_has_atomic! { + #[cfg(feature = "alloc")] + mod try_buffer_unordered; + #[cfg(feature = "alloc")] + pub use self::try_buffer_unordered::TryBufferUnordered; + + #[cfg(feature = "alloc")] + mod try_for_each_concurrent; + #[cfg(feature = "alloc")] + pub use self::try_for_each_concurrent::TryForEachConcurrent; + #[cfg(feature = "alloc")] + use futures_core::future::Future; +} #[cfg(feature = "std")] mod into_async_read;