Skip to content

Commit 8666a25

Browse files
committed
Use #[proc_macro] at Rust 1.45+
1 parent cb0711e commit 8666a25

File tree

7 files changed

+74
-13
lines changed

7 files changed

+74
-13
lines changed

futures-macro/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ proc-macro = true
1616

1717
[features]
1818

19+
[build-dependencies]
20+
autocfg = "1"
21+
1922
[dependencies]
2023
proc-macro2 = "1.0"
2124
proc-macro-hack = "0.5.19"

futures-macro/build.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![warn(rust_2018_idioms, single_use_lifetimes)]
2+
3+
use autocfg::AutoCfg;
4+
5+
// The rustc-cfg strings below are *not* public API. Please let us know by
6+
// opening a GitHub issue if your build environment requires some way to enable
7+
// these cfgs other than by executing our build script.
8+
fn main() {
9+
let cfg = match AutoCfg::new() {
10+
Ok(cfg) => cfg,
11+
Err(e) => {
12+
println!(
13+
"cargo:warning={}: unable to determine rustc version: {}",
14+
env!("CARGO_PKG_NAME"),
15+
e
16+
);
17+
return;
18+
}
19+
};
20+
21+
// Function like procedural macros in expressions patterns statements stabilized in Rust 1.45:
22+
// https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#stabilizing-function-like-procedural-macros-in-expressions-patterns-and-statements
23+
if cfg.probe_rustc_version(1, 45) {
24+
println!("cargo:rustc-cfg=fn_like_proc_macro");
25+
}
26+
}

futures-macro/src/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,34 @@
1313
extern crate proc_macro;
1414

1515
use proc_macro::TokenStream;
16-
use proc_macro_hack::proc_macro_hack;
1716

1817
mod join;
1918
mod select;
2019

2120
/// The `join!` macro.
22-
#[proc_macro_hack]
21+
#[cfg_attr(fn_like_proc_macro, proc_macro)]
22+
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack)]
2323
pub fn join_internal(input: TokenStream) -> TokenStream {
2424
crate::join::join(input)
2525
}
2626

2727
/// The `try_join!` macro.
28-
#[proc_macro_hack]
28+
#[cfg_attr(fn_like_proc_macro, proc_macro)]
29+
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack)]
2930
pub fn try_join_internal(input: TokenStream) -> TokenStream {
3031
crate::join::try_join(input)
3132
}
3233

3334
/// The `select!` macro.
34-
#[proc_macro_hack]
35+
#[cfg_attr(fn_like_proc_macro, proc_macro)]
36+
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack)]
3537
pub fn select_internal(input: TokenStream) -> TokenStream {
3638
crate::select::select(input)
3739
}
3840

3941
/// The `select_biased!` macro.
40-
#[proc_macro_hack]
42+
#[cfg_attr(fn_like_proc_macro, proc_macro)]
43+
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack)]
4144
pub fn select_biased_internal(input: TokenStream) -> TokenStream {
4245
crate::select::select_biased(input)
4346
}

futures-util/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ bilock = []
3232
read-initializer = ["io", "futures-io/read-initializer", "futures-io/unstable"]
3333
write-all-vectored = ["io"]
3434

35+
[build-dependencies]
36+
autocfg = "1"
37+
3538
[dependencies]
3639
futures-core = { path = "../futures-core", version = "=1.0.0-alpha.0", default-features = false }
3740
futures-task = { path = "../futures-task", version = "=0.4.0-alpha.0", default-features = false }

futures-util/build.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![warn(rust_2018_idioms, single_use_lifetimes)]
2+
3+
use autocfg::AutoCfg;
4+
5+
// The rustc-cfg strings below are *not* public API. Please let us know by
6+
// opening a GitHub issue if your build environment requires some way to enable
7+
// these cfgs other than by executing our build script.
8+
fn main() {
9+
let cfg = match AutoCfg::new() {
10+
Ok(cfg) => cfg,
11+
Err(e) => {
12+
println!(
13+
"cargo:warning={}: unable to determine rustc version: {}",
14+
env!("CARGO_PKG_NAME"),
15+
e
16+
);
17+
return;
18+
}
19+
};
20+
21+
// Function like procedural macros in expressions patterns statements stabilized in Rust 1.45:
22+
// https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#stabilizing-function-like-procedural-macros-in-expressions-patterns-and-statements
23+
if cfg.probe_rustc_version(1, 45) {
24+
println!("cargo:rustc-cfg=fn_like_proc_macro");
25+
}
26+
}

futures-util/src/async_await/join_mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! The `join` macro.
22
3-
use proc_macro_hack::proc_macro_hack;
4-
53
macro_rules! document_join_macro {
64
($join:item $try_join:item) => {
75
/// Polls multiple futures simultaneously, returning a tuple
@@ -81,12 +79,14 @@ macro_rules! document_join_macro {
8179
}
8280
}
8381

82+
#[allow(unreachable_pub)]
8483
#[doc(hidden)]
85-
#[proc_macro_hack(support_nested, only_hack_old_rustc)]
84+
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack(support_nested))]
8685
pub use futures_macro::join_internal;
8786

87+
#[allow(unreachable_pub)]
8888
#[doc(hidden)]
89-
#[proc_macro_hack(support_nested, only_hack_old_rustc)]
89+
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack(support_nested))]
9090
pub use futures_macro::try_join_internal;
9191

9292
document_join_macro! {

futures-util/src/async_await/select_mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! The `select` macro.
22
3-
use proc_macro_hack::proc_macro_hack;
4-
53
macro_rules! document_select_macro {
64
// This branch is required for `futures 0.3.1`, from before select_biased was introduced
75
($select:item) => {
@@ -309,12 +307,14 @@ macro_rules! document_select_macro {
309307
}
310308

311309
#[cfg(feature = "std")]
310+
#[allow(unreachable_pub)]
312311
#[doc(hidden)]
313-
#[proc_macro_hack(support_nested, only_hack_old_rustc)]
312+
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack(support_nested))]
314313
pub use futures_macro::select_internal;
315314

315+
#[allow(unreachable_pub)]
316316
#[doc(hidden)]
317-
#[proc_macro_hack(support_nested, only_hack_old_rustc)]
317+
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack(support_nested))]
318318
pub use futures_macro::select_biased_internal;
319319

320320
document_select_macro! {

0 commit comments

Comments
 (0)