Skip to content

Commit f70e95f

Browse files
authored
Remove cfg_target_has_atomic! macro (#2439)
1 parent ec84d12 commit f70e95f

File tree

17 files changed

+184
-202
lines changed

17 files changed

+184
-202
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ jobs:
246246
steps:
247247
- uses: actions/checkout@v2
248248
- name: Install Rust
249-
run: rustup update stable && rustup default stable
250-
- run: tools/fmt.sh
249+
run: rustup update stable
250+
- run: cargo fmt --all -- --check
251251

252252
docs:
253253
name: cargo doc

ci/no_atomic_cas.sh

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
# Update the list of targets that do not support atomic CAS operations.
4+
#
5+
# Usage:
6+
# ./ci/no_atomic_cas.sh
7+
38
set -euo pipefail
49
IFS=$'\n\t'
510

futures-channel/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include!("no_atomic_cas.rs");
88
// and outside of the normal semver guarantees:
99
//
1010
// - `futures_no_atomic_cas`
11-
// Assume the target does not have atomic CAS (compare-and-swap).
11+
// Assume the target does *not* support atomic CAS operations.
1212
// This is usually detected automatically by the build script, but you may
1313
// need to enable it manually when building for custom targets or using
1414
// non-cargo build systems that don't run the build script.

futures-channel/src/lib.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@
1818
#![warn(clippy::all)]
1919
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
2020

21-
macro_rules! cfg_target_has_atomic {
22-
($($item:item)*) => {$(
23-
#[cfg(not(futures_no_atomic_cas))]
24-
$item
25-
)*};
26-
}
21+
#[cfg(not(futures_no_atomic_cas))]
22+
#[cfg(feature = "alloc")]
23+
extern crate alloc;
2724

28-
cfg_target_has_atomic! {
29-
#[cfg(feature = "alloc")]
30-
extern crate alloc;
31-
32-
#[cfg(feature = "alloc")]
33-
mod lock;
34-
#[cfg(feature = "std")]
35-
pub mod mpsc;
36-
#[cfg(feature = "alloc")]
37-
pub mod oneshot;
38-
}
25+
#[cfg(not(futures_no_atomic_cas))]
26+
#[cfg(feature = "alloc")]
27+
mod lock;
28+
#[cfg(not(futures_no_atomic_cas))]
29+
#[cfg(feature = "std")]
30+
pub mod mpsc;
31+
#[cfg(not(futures_no_atomic_cas))]
32+
#[cfg(feature = "alloc")]
33+
pub mod oneshot;

futures-core/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include!("no_atomic_cas.rs");
88
// and outside of the normal semver guarantees:
99
//
1010
// - `futures_no_atomic_cas`
11-
// Assume the target does not have atomic CAS (compare-and-swap).
11+
// Assume the target does *not* support atomic CAS operations.
1212
// This is usually detected automatically by the build script, but you may
1313
// need to enable it manually when building for custom targets or using
1414
// non-cargo build systems that don't run the build script.

futures-task/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include!("no_atomic_cas.rs");
88
// and outside of the normal semver guarantees:
99
//
1010
// - `futures_no_atomic_cas`
11-
// Assume the target does not have atomic CAS (compare-and-swap).
11+
// Assume the target does *not* support atomic CAS operations.
1212
// This is usually detected automatically by the build script, but you may
1313
// need to enable it manually when building for custom targets or using
1414
// non-cargo build systems that don't run the build script.

futures-task/src/lib.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,29 @@
1010
#[cfg(feature = "alloc")]
1111
extern crate alloc;
1212

13-
macro_rules! cfg_target_has_atomic {
14-
($($item:item)*) => {$(
15-
#[cfg(not(futures_no_atomic_cas))]
16-
$item
17-
)*};
18-
}
19-
2013
mod spawn;
2114
pub use crate::spawn::{LocalSpawn, Spawn, SpawnError};
2215

23-
cfg_target_has_atomic! {
24-
#[cfg(feature = "alloc")]
25-
mod arc_wake;
26-
#[cfg(feature = "alloc")]
27-
pub use crate::arc_wake::ArcWake;
28-
29-
#[cfg(feature = "alloc")]
30-
mod waker;
31-
#[cfg(feature = "alloc")]
32-
pub use crate::waker::waker;
33-
34-
#[cfg(feature = "alloc")]
35-
mod waker_ref;
36-
#[cfg(feature = "alloc")]
37-
pub use crate::waker_ref::{waker_ref, WakerRef};
38-
}
16+
#[cfg(not(futures_no_atomic_cas))]
17+
#[cfg(feature = "alloc")]
18+
mod arc_wake;
19+
#[cfg(not(futures_no_atomic_cas))]
20+
#[cfg(feature = "alloc")]
21+
pub use crate::arc_wake::ArcWake;
22+
23+
#[cfg(not(futures_no_atomic_cas))]
24+
#[cfg(feature = "alloc")]
25+
mod waker;
26+
#[cfg(not(futures_no_atomic_cas))]
27+
#[cfg(feature = "alloc")]
28+
pub use crate::waker::waker;
29+
30+
#[cfg(not(futures_no_atomic_cas))]
31+
#[cfg(feature = "alloc")]
32+
mod waker_ref;
33+
#[cfg(not(futures_no_atomic_cas))]
34+
#[cfg(feature = "alloc")]
35+
pub use crate::waker_ref::{waker_ref, WakerRef};
3936

4037
mod future_obj;
4138
pub use crate::future_obj::{FutureObj, LocalFutureObj, UnsafeFutureObj};

futures-task/src/spawn.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,25 @@ mod if_alloc {
168168
}
169169
}
170170

171-
cfg_target_has_atomic! {
172-
use alloc::{ sync::Arc };
173-
174-
impl<Sp: ?Sized + Spawn> Spawn for Arc<Sp> {
175-
fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> {
176-
(**self).spawn_obj(future)
177-
}
171+
#[cfg(not(futures_no_atomic_cas))]
172+
impl<Sp: ?Sized + Spawn> Spawn for alloc::sync::Arc<Sp> {
173+
fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> {
174+
(**self).spawn_obj(future)
175+
}
178176

179-
fn status(&self) -> Result<(), SpawnError> {
180-
(**self).status()
181-
}
177+
fn status(&self) -> Result<(), SpawnError> {
178+
(**self).status()
182179
}
180+
}
183181

184-
impl<Sp: ?Sized + LocalSpawn> LocalSpawn for Arc<Sp> {
185-
fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> {
186-
(**self).spawn_local_obj(future)
187-
}
182+
#[cfg(not(futures_no_atomic_cas))]
183+
impl<Sp: ?Sized + LocalSpawn> LocalSpawn for alloc::sync::Arc<Sp> {
184+
fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> {
185+
(**self).spawn_local_obj(future)
186+
}
188187

189-
fn status_local(&self) -> Result<(), SpawnError> {
190-
(**self).status_local()
191-
}
188+
fn status_local(&self) -> Result<(), SpawnError> {
189+
(**self).status_local()
192190
}
193191
}
194192
}

futures-util/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include!("no_atomic_cas.rs");
99
// and outside of the normal semver guarantees:
1010
//
1111
// - `futures_no_atomic_cas`
12-
// Assume the target does not have atomic CAS (compare-and-swap).
12+
// Assume the target does *not* support atomic CAS operations.
1313
// This is usually detected automatically by the build script, but you may
1414
// need to enable it manually when building for custom targets or using
1515
// non-cargo build systems that don't run the build script.

futures-util/src/future/mod.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,15 @@ pub use self::select_ok::{select_ok, SelectOk};
106106
mod either;
107107
pub use self::either::Either;
108108

109-
cfg_target_has_atomic! {
110-
#[cfg(feature = "alloc")]
111-
mod abortable;
112-
#[cfg(feature = "alloc")]
113-
pub use crate::abortable::{Abortable, AbortHandle, AbortRegistration, Aborted};
114-
#[cfg(feature = "alloc")]
115-
pub use abortable::abortable;
116-
}
109+
#[cfg(not(futures_no_atomic_cas))]
110+
#[cfg(feature = "alloc")]
111+
mod abortable;
112+
#[cfg(not(futures_no_atomic_cas))]
113+
#[cfg(feature = "alloc")]
114+
pub use crate::abortable::{AbortHandle, AbortRegistration, Abortable, Aborted};
115+
#[cfg(not(futures_no_atomic_cas))]
116+
#[cfg(feature = "alloc")]
117+
pub use abortable::abortable;
117118

118119
// Just a helper function to ensure the futures we're returning all have the
119120
// right implementations.

futures-util/src/lib.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ pub mod __private {
4747
}
4848
}
4949

50-
macro_rules! cfg_target_has_atomic {
51-
($($item:item)*) => {$(
52-
#[cfg(not(futures_no_atomic_cas))]
53-
$item
54-
)*};
55-
}
56-
5750
#[cfg(feature = "sink")]
5851
macro_rules! delegate_sink {
5952
($field:ident, $item:ty) => {
@@ -334,10 +327,9 @@ pub use crate::io::{
334327
#[cfg(feature = "alloc")]
335328
pub mod lock;
336329

337-
cfg_target_has_atomic! {
338-
#[cfg(feature = "alloc")]
339-
mod abortable;
340-
}
330+
#[cfg(not(futures_no_atomic_cas))]
331+
#[cfg(feature = "alloc")]
332+
mod abortable;
341333

342334
mod fns;
343335
mod unfold_state;

futures-util/src/lock/mod.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
//! This module is only available when the `std` or `alloc` feature of this
44
//! library is activated, and it is activated by default.
55
6-
cfg_target_has_atomic! {
7-
#[cfg(feature = "std")]
8-
mod mutex;
9-
#[cfg(feature = "std")]
10-
pub use self::mutex::{MappedMutexGuard, Mutex, MutexLockFuture, MutexGuard};
6+
#[cfg(not(futures_no_atomic_cas))]
7+
#[cfg(feature = "std")]
8+
mod mutex;
9+
#[cfg(not(futures_no_atomic_cas))]
10+
#[cfg(feature = "std")]
11+
pub use self::mutex::{MappedMutexGuard, Mutex, MutexGuard, MutexLockFuture};
1112

12-
#[cfg(any(feature = "bilock", feature = "sink", feature = "io"))]
13-
#[cfg_attr(docsrs, doc(cfg(feature = "bilock")))]
14-
#[cfg_attr(not(feature = "bilock"), allow(unreachable_pub))]
15-
mod bilock;
16-
#[cfg(feature = "bilock")]
17-
#[cfg_attr(docsrs, doc(cfg(feature = "bilock")))]
18-
pub use self::bilock::{BiLock, BiLockAcquire, BiLockGuard, ReuniteError};
19-
#[cfg(any(feature = "sink", feature = "io"))]
20-
#[cfg(not(feature = "bilock"))]
21-
pub(crate) use self::bilock::BiLock;
22-
}
13+
#[cfg(not(futures_no_atomic_cas))]
14+
#[cfg(any(feature = "bilock", feature = "sink", feature = "io"))]
15+
#[cfg_attr(docsrs, doc(cfg(feature = "bilock")))]
16+
#[cfg_attr(not(feature = "bilock"), allow(unreachable_pub))]
17+
mod bilock;
18+
#[cfg(not(futures_no_atomic_cas))]
19+
#[cfg(any(feature = "sink", feature = "io"))]
20+
#[cfg(not(feature = "bilock"))]
21+
pub(crate) use self::bilock::BiLock;
22+
#[cfg(not(futures_no_atomic_cas))]
23+
#[cfg(feature = "bilock")]
24+
#[cfg_attr(docsrs, doc(cfg(feature = "bilock")))]
25+
pub use self::bilock::{BiLock, BiLockAcquire, BiLockGuard, ReuniteError};

futures-util/src/stream/mod.rs

+31-24
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,37 @@ pub use self::select::{select, Select};
9292
mod unfold;
9393
pub use self::unfold::{unfold, Unfold};
9494

95-
cfg_target_has_atomic! {
96-
#[cfg(feature = "alloc")]
97-
mod futures_ordered;
98-
#[cfg(feature = "alloc")]
99-
pub use self::futures_ordered::FuturesOrdered;
100-
101-
#[cfg(feature = "alloc")]
102-
pub mod futures_unordered;
103-
#[cfg(feature = "alloc")]
104-
#[doc(inline)]
105-
pub use self::futures_unordered::FuturesUnordered;
106-
107-
#[cfg(feature = "alloc")]
108-
pub mod select_all;
109-
#[cfg(feature = "alloc")]
110-
pub use self::select_all::{select_all, SelectAll};
111-
112-
#[cfg(feature = "alloc")]
113-
mod abortable;
114-
#[cfg(feature = "alloc")]
115-
pub use crate::abortable::{Abortable, AbortHandle, AbortRegistration, Aborted};
116-
#[cfg(feature = "alloc")]
117-
pub use abortable::abortable;
118-
}
95+
#[cfg(not(futures_no_atomic_cas))]
96+
#[cfg(feature = "alloc")]
97+
mod futures_ordered;
98+
#[cfg(not(futures_no_atomic_cas))]
99+
#[cfg(feature = "alloc")]
100+
pub use self::futures_ordered::FuturesOrdered;
101+
102+
#[cfg(not(futures_no_atomic_cas))]
103+
#[cfg(feature = "alloc")]
104+
pub mod futures_unordered;
105+
#[cfg(not(futures_no_atomic_cas))]
106+
#[cfg(feature = "alloc")]
107+
#[doc(inline)]
108+
pub use self::futures_unordered::FuturesUnordered;
109+
110+
#[cfg(not(futures_no_atomic_cas))]
111+
#[cfg(feature = "alloc")]
112+
pub mod select_all;
113+
#[cfg(not(futures_no_atomic_cas))]
114+
#[cfg(feature = "alloc")]
115+
pub use self::select_all::{select_all, SelectAll};
116+
117+
#[cfg(not(futures_no_atomic_cas))]
118+
#[cfg(feature = "alloc")]
119+
mod abortable;
120+
#[cfg(not(futures_no_atomic_cas))]
121+
#[cfg(feature = "alloc")]
122+
pub use crate::abortable::{AbortHandle, AbortRegistration, Abortable, Aborted};
123+
#[cfg(not(futures_no_atomic_cas))]
124+
#[cfg(feature = "alloc")]
125+
pub use abortable::abortable;
119126

120127
// Just a helper function to ensure the streams we're returning all have the
121128
// right implementations.

0 commit comments

Comments
 (0)