Skip to content

Commit 7f562a8

Browse files
committed
Avoid redundant cfg
1 parent 88ce34b commit 7f562a8

File tree

6 files changed

+97
-189
lines changed

6 files changed

+97
-189
lines changed

futures-util/src/future/mod.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,17 @@ pub use self::unit_error::UnitError;
6969
mod chain;
7070
pub(crate) use self::chain::Chain;
7171

72-
#[cfg_attr(
73-
feature = "cfg-target-has-atomic",
74-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
75-
)]
7672
#[cfg(feature = "alloc")]
77-
mod abortable;
78-
#[cfg_attr(
79-
feature = "cfg-target-has-atomic",
80-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
81-
)]
73+
mod join_all;
8274
#[cfg(feature = "alloc")]
83-
pub use self::abortable::{abortable, Abortable, AbortHandle, AbortRegistration, Aborted};
75+
pub use self::join_all::{join_all, JoinAll};
76+
77+
cfg_target_has_atomic! {
78+
#[cfg(feature = "alloc")]
79+
mod abortable;
80+
#[cfg(feature = "alloc")]
81+
pub use self::abortable::{abortable, Abortable, AbortHandle, AbortRegistration, Aborted};
82+
}
8483

8584
#[cfg(feature = "std")]
8685
mod catch_unwind;
@@ -92,11 +91,6 @@ mod remote_handle;
9291
#[cfg(feature = "std")]
9392
pub use self::remote_handle::{Remote, RemoteHandle};
9493

95-
#[cfg(feature = "alloc")]
96-
mod join_all;
97-
#[cfg(feature = "alloc")]
98-
pub use self::join_all::{join_all, JoinAll};
99-
10094
// #[cfg(feature = "std")]
10195
// mod select_all;
10296
// #[cfg(feature = "std")]

futures-util/src/lib.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ pub mod io;
101101
#[cfg(feature = "std")]
102102
#[doc(hidden)] pub use crate::io::{AsyncReadExt, AsyncWriteExt};
103103

104-
#[cfg_attr(
105-
feature = "cfg-target-has-atomic",
106-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
107-
)]
108-
#[cfg(feature = "alloc")]
109-
pub mod lock;
104+
cfg_target_has_atomic! {
105+
#[cfg(feature = "alloc")]
106+
pub mod lock;
107+
}

futures-util/src/macros/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
#[macro_use]
22
mod poll;
3+
4+
macro_rules! cfg_target_has_atomic {
5+
($($item:item)*) => {$(
6+
#[cfg_attr(
7+
feature = "cfg-target-has-atomic",
8+
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
9+
)]
10+
$item
11+
)*};
12+
}

futures-util/src/stream/mod.rs

+36-90
Original file line numberDiff line numberDiff line change
@@ -99,106 +99,52 @@ pub use self::unfold::{unfold, Unfold};
9999
mod zip;
100100
pub use self::zip::Zip;
101101

102-
#[cfg_attr(
103-
feature = "cfg-target-has-atomic",
104-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
105-
)]
106102
#[cfg(feature = "alloc")]
107-
mod buffer_unordered;
108-
#[cfg_attr(
109-
feature = "cfg-target-has-atomic",
110-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
111-
)]
103+
mod chunks;
112104
#[cfg(feature = "alloc")]
113-
pub use self::buffer_unordered::BufferUnordered;
105+
pub use self::chunks::Chunks;
114106

115-
#[cfg_attr(
116-
feature = "cfg-target-has-atomic",
117-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
118-
)]
119-
#[cfg(feature = "alloc")]
120-
mod buffered;
121-
#[cfg_attr(
122-
feature = "cfg-target-has-atomic",
123-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
124-
)]
125-
#[cfg(feature = "alloc")]
126-
pub use self::buffered::Buffered;
107+
cfg_target_has_atomic! {
108+
#[cfg(feature = "alloc")]
109+
mod buffer_unordered;
110+
#[cfg(feature = "alloc")]
111+
pub use self::buffer_unordered::BufferUnordered;
127112

128-
#[cfg(feature = "std")]
129-
mod catch_unwind;
130-
#[cfg(feature = "std")]
131-
pub use self::catch_unwind::CatchUnwind;
113+
#[cfg(feature = "alloc")]
114+
mod buffered;
115+
#[cfg(feature = "alloc")]
116+
pub use self::buffered::Buffered;
132117

133-
#[cfg(feature = "alloc")]
134-
mod chunks;
135-
#[cfg(feature = "alloc")]
136-
pub use self::chunks::Chunks;
118+
#[cfg(feature = "alloc")]
119+
mod for_each_concurrent;
120+
#[cfg(feature = "alloc")]
121+
pub use self::for_each_concurrent::ForEachConcurrent;
137122

138-
#[cfg_attr(
139-
feature = "cfg-target-has-atomic",
140-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
141-
)]
142-
#[cfg(feature = "alloc")]
143-
mod for_each_concurrent;
144-
#[cfg_attr(
145-
feature = "cfg-target-has-atomic",
146-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
147-
)]
148-
#[cfg(feature = "alloc")]
149-
pub use self::for_each_concurrent::ForEachConcurrent;
123+
#[cfg(feature = "alloc")]
124+
mod futures_ordered;
125+
#[cfg(feature = "alloc")]
126+
pub use self::futures_ordered::{futures_ordered, FuturesOrdered};
150127

151-
#[cfg_attr(
152-
feature = "cfg-target-has-atomic",
153-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
154-
)]
155-
#[cfg(feature = "alloc")]
156-
mod futures_ordered;
157-
#[cfg_attr(
158-
feature = "cfg-target-has-atomic",
159-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
160-
)]
161-
#[cfg(feature = "alloc")]
162-
pub use self::futures_ordered::{futures_ordered, FuturesOrdered};
128+
#[cfg(feature = "alloc")]
129+
mod futures_unordered;
130+
#[cfg(feature = "alloc")]
131+
pub use self::futures_unordered::{futures_unordered, FuturesUnordered};
163132

164-
#[cfg_attr(
165-
feature = "cfg-target-has-atomic",
166-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
167-
)]
168-
#[cfg(feature = "alloc")]
169-
mod futures_unordered;
170-
#[cfg_attr(
171-
feature = "cfg-target-has-atomic",
172-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
173-
)]
174-
#[cfg(feature = "alloc")]
175-
pub use self::futures_unordered::{futures_unordered, FuturesUnordered};
133+
#[cfg(feature = "alloc")]
134+
mod split;
135+
#[cfg(feature = "alloc")]
136+
pub use self::split::{SplitStream, SplitSink, ReuniteError};
176137

177-
#[cfg_attr(
178-
feature = "cfg-target-has-atomic",
179-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
180-
)]
181-
#[cfg(feature = "alloc")]
182-
mod split;
183-
#[cfg_attr(
184-
feature = "cfg-target-has-atomic",
185-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
186-
)]
187-
#[cfg(feature = "alloc")]
188-
pub use self::split::{SplitStream, SplitSink, ReuniteError};
138+
#[cfg(feature = "alloc")]
139+
mod select_all;
140+
#[cfg(feature = "alloc")]
141+
pub use self::select_all::{select_all, SelectAll};
142+
}
189143

190-
#[cfg_attr(
191-
feature = "cfg-target-has-atomic",
192-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
193-
)]
194-
#[cfg(feature = "alloc")]
195-
mod select_all;
196-
#[cfg_attr(
197-
feature = "cfg-target-has-atomic",
198-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
199-
)]
200-
#[cfg(feature = "alloc")]
201-
pub use self::select_all::{select_all, SelectAll};
144+
#[cfg(feature = "std")]
145+
mod catch_unwind;
146+
#[cfg(feature = "std")]
147+
pub use self::catch_unwind::CatchUnwind;
202148

203149
impl<T: ?Sized> StreamExt for T where T: Stream {}
204150

futures-util/src/task/mod.rs

+25-47
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
//! Task notification
22
3-
/// A macro for creating a `RawWaker` vtable for a type that implements
4-
/// the `ArcWake` trait.
5-
#[cfg_attr(
6-
feature = "cfg-target-has-atomic",
7-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
8-
)]
9-
#[cfg(feature = "alloc")]
10-
macro_rules! waker_vtable {
11-
($ty:ident) => {
12-
&RawWakerVTable {
13-
clone: clone_arc_raw::<$ty>,
14-
drop: drop_arc_raw::<$ty>,
15-
wake: wake_arc_raw::<$ty>,
16-
}
17-
};
18-
}
3+
cfg_target_has_atomic! {
4+
/// A macro for creating a `RawWaker` vtable for a type that implements
5+
/// the `ArcWake` trait.
6+
#[cfg(feature = "alloc")]
7+
macro_rules! waker_vtable {
8+
($ty:ident) => {
9+
&RawWakerVTable {
10+
clone: clone_arc_raw::<$ty>,
11+
drop: drop_arc_raw::<$ty>,
12+
wake: wake_arc_raw::<$ty>,
13+
}
14+
};
15+
}
16+
17+
#[cfg(feature = "alloc")]
18+
mod arc_wake;
19+
#[cfg(feature = "alloc")]
20+
pub use self::arc_wake::ArcWake;
21+
22+
#[cfg(feature = "alloc")]
23+
mod waker_ref;
24+
#[cfg(feature = "alloc")]
25+
pub use self::waker_ref::{waker_ref, WakerRef};
1926

20-
#[cfg_attr(
21-
feature = "cfg-target-has-atomic",
22-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
23-
)]
24-
#[cfg(feature = "alloc")]
25-
mod arc_wake;
26-
#[cfg_attr(
27-
feature = "cfg-target-has-atomic",
28-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
29-
)]
30-
#[cfg(feature = "alloc")]
31-
pub use self::arc_wake::ArcWake;
27+
pub use futures_core::task::__internal::AtomicWaker;
28+
}
3229

3330
mod noop_waker;
3431
pub use self::noop_waker::noop_waker;
@@ -38,25 +35,6 @@ pub use self::noop_waker::noop_waker_ref;
3835
mod spawn;
3936
pub use self::spawn::{SpawnExt, LocalSpawnExt};
4037

41-
#[cfg_attr(
42-
feature = "cfg-target-has-atomic",
43-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
44-
)]
45-
#[cfg(feature = "alloc")]
46-
mod waker_ref;
47-
#[cfg_attr(
48-
feature = "cfg-target-has-atomic",
49-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
50-
)]
51-
#[cfg(feature = "alloc")]
52-
pub use self::waker_ref::{waker_ref, WakerRef};
53-
54-
#[cfg_attr(
55-
feature = "cfg-target-has-atomic",
56-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
57-
)]
58-
pub use futures_core::task::__internal::AtomicWaker;
59-
6038
// re-export for `select!`
6139
#[doc(hidden)]
6240
pub use futures_core::task::{Waker, Poll};

futures-util/src/try_stream/mod.rs

+13-31
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,19 @@ pub use self::try_fold::TryFold;
4444
mod try_skip_while;
4545
pub use self::try_skip_while::TrySkipWhile;
4646

47-
#[cfg_attr(
48-
feature = "cfg-target-has-atomic",
49-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
50-
)]
51-
#[cfg(feature = "alloc")]
52-
mod try_buffer_unordered;
53-
#[cfg_attr(
54-
feature = "cfg-target-has-atomic",
55-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
56-
)]
57-
#[cfg(feature = "alloc")]
58-
pub use self::try_buffer_unordered::TryBufferUnordered;
59-
60-
#[cfg_attr(
61-
feature = "cfg-target-has-atomic",
62-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
63-
)]
64-
#[cfg(feature = "alloc")]
65-
mod try_for_each_concurrent;
66-
#[cfg_attr(
67-
feature = "cfg-target-has-atomic",
68-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
69-
)]
70-
#[cfg(feature = "alloc")]
71-
pub use self::try_for_each_concurrent::TryForEachConcurrent;
72-
#[cfg_attr(
73-
feature = "cfg-target-has-atomic",
74-
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
75-
)]
76-
#[cfg(feature = "alloc")]
77-
use futures_core::future::Future;
47+
cfg_target_has_atomic! {
48+
#[cfg(feature = "alloc")]
49+
mod try_buffer_unordered;
50+
#[cfg(feature = "alloc")]
51+
pub use self::try_buffer_unordered::TryBufferUnordered;
52+
53+
#[cfg(feature = "alloc")]
54+
mod try_for_each_concurrent;
55+
#[cfg(feature = "alloc")]
56+
pub use self::try_for_each_concurrent::TryForEachConcurrent;
57+
#[cfg(feature = "alloc")]
58+
use futures_core::future::Future;
59+
}
7860

7961
#[cfg(feature = "std")]
8062
mod into_async_read;

0 commit comments

Comments
 (0)