Skip to content

Commit

Permalink
Avoid redundant cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Mar 20, 2019
1 parent b789bfe commit e84500a
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 189 deletions.
24 changes: 9 additions & 15 deletions futures-util/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")]
Expand Down
10 changes: 4 additions & 6 deletions futures-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions futures-util/src/macros/mod.rs
Original file line number Diff line number Diff line change
@@ -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
)*};
}
126 changes: 36 additions & 90 deletions futures-util/src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: ?Sized> StreamExt for T where T: Stream {}

Expand Down
72 changes: 25 additions & 47 deletions futures-util/src/task/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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};
44 changes: 13 additions & 31 deletions futures-util/src/try_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e84500a

Please sign in to comment.