Skip to content

Commit

Permalink
Remove dependency on proc-macro-hack
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Nov 23, 2021
1 parent eeae634 commit 09b0186
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 80 deletions.
4 changes: 0 additions & 4 deletions futures-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ proc-macro = true

[features]

[build-dependencies]
autocfg = "1"

[dependencies]
proc-macro2 = "1.0"
proc-macro-hack = "0.5.19"
quote = "1.0"
syn = { version = "1.0.56", features = ["full"] }
28 changes: 0 additions & 28 deletions futures-macro/build.rs

This file was deleted.

17 changes: 6 additions & 11 deletions futures-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,38 @@ mod select;
mod stream_select;

/// The `join!` macro.
#[cfg_attr(fn_like_proc_macro, proc_macro)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack)]
#[proc_macro]
pub fn join_internal(input: TokenStream) -> TokenStream {
crate::join::join(input)
}

/// The `try_join!` macro.
#[cfg_attr(fn_like_proc_macro, proc_macro)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack)]
#[proc_macro]
pub fn try_join_internal(input: TokenStream) -> TokenStream {
crate::join::try_join(input)
}

/// The `select!` macro.
#[cfg_attr(fn_like_proc_macro, proc_macro)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack)]
#[proc_macro]
pub fn select_internal(input: TokenStream) -> TokenStream {
crate::select::select(input)
}

/// The `select_biased!` macro.
#[cfg_attr(fn_like_proc_macro, proc_macro)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack)]
#[proc_macro]
pub fn select_biased_internal(input: TokenStream) -> TokenStream {
crate::select::select_biased(input)
}

// TODO: Change this to doc comment once rustdoc bug fixed.
// TODO: Change this to doc comment once rustdoc bug fixed: https://github.com/rust-lang/futures-rs/pull/2435
// The `test` attribute.
#[proc_macro_attribute]
pub fn test_internal(input: TokenStream, item: TokenStream) -> TokenStream {
crate::executor::test(input, item)
}

/// The `stream_select!` macro.
#[cfg_attr(fn_like_proc_macro, proc_macro)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack)]
#[proc_macro]
pub fn stream_select_internal(input: TokenStream) -> TokenStream {
crate::stream_select::stream_select(input.into())
.unwrap_or_else(syn::Error::into_compile_error)
Expand Down
7 changes: 1 addition & 6 deletions futures-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default = ["std", "async-await", "async-await-macro"]
std = ["alloc", "futures-core/std", "futures-task/std", "slab"]
alloc = ["futures-core/alloc", "futures-task/alloc"]
async-await = []
async-await-macro = ["async-await", "futures-macro", "proc-macro-hack", "proc-macro-nested"]
async-await-macro = ["async-await", "futures-macro"]
compat = ["std", "futures_01"]
io-compat = ["io", "compat", "tokio-io"]
sink = ["futures-sink"]
Expand All @@ -34,18 +34,13 @@ write-all-vectored = ["io"]
# TODO: remove in the next major version.
cfg-target-has-atomic = []

[build-dependencies]
autocfg = "1"

[dependencies]
futures-core = { path = "../futures-core", version = "0.3.17", default-features = false }
futures-task = { path = "../futures-task", version = "0.3.17", default-features = false }
futures-channel = { path = "../futures-channel", version = "0.3.17", default-features = false, features = ["std"], optional = true }
futures-io = { path = "../futures-io", version = "0.3.17", default-features = false, features = ["std"], optional = true }
futures-sink = { path = "../futures-sink", version = "0.3.17", default-features = false, optional = true }
futures-macro = { path = "../futures-macro", version = "=0.3.17", default-features = false, optional = true }
proc-macro-hack = { version = "0.5.19", optional = true }
proc-macro-nested = { version = "0.1.2", optional = true }
slab = { version = "0.4.2", optional = true }
memchr = { version = "2.2", optional = true }
futures_01 = { version = "0.1.25", optional = true, package = "futures" }
Expand Down
19 changes: 0 additions & 19 deletions futures-util/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]

use autocfg::AutoCfg;
use std::env;

include!("no_atomic_cas.rs");
Expand Down Expand Up @@ -39,23 +38,5 @@ fn main() {
println!("cargo:rustc-cfg=futures_no_atomic_cas");
}

let cfg = match AutoCfg::new() {
Ok(cfg) => cfg,
Err(e) => {
println!(
"cargo:warning={}: unable to determine rustc version: {}",
env!("CARGO_PKG_NAME"),
e
);
return;
}
};

// Function like procedural macros in expressions patterns statements stabilized in Rust 1.45:
// https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#stabilizing-function-like-procedural-macros-in-expressions-patterns-and-statements
if cfg.probe_rustc_version(1, 45) {
println!("cargo:rustc-cfg=fn_like_proc_macro");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
2 changes: 0 additions & 2 deletions futures-util/src/async_await/join_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ macro_rules! document_join_macro {

#[allow(unreachable_pub)]
#[doc(hidden)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack(support_nested))]
pub use futures_macro::join_internal;

#[allow(unreachable_pub)]
#[doc(hidden)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack(support_nested))]
pub use futures_macro::try_join_internal;

document_join_macro! {
Expand Down
5 changes: 0 additions & 5 deletions futures-util/src/async_await/select_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ macro_rules! document_select_macro {
/// It is also gated behind the `async-await` feature of this library, which is
/// activated by default.
///
/// Note that `select!` relies on `proc-macro-hack`, and may require to set the
/// compiler's recursion limit very high, e.g. `#![recursion_limit="1024"]`.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -309,12 +306,10 @@ macro_rules! document_select_macro {
#[cfg(feature = "std")]
#[allow(unreachable_pub)]
#[doc(hidden)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack(support_nested))]
pub use futures_macro::select_internal;

#[allow(unreachable_pub)]
#[doc(hidden)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack(support_nested))]
pub use futures_macro::select_biased_internal;

document_select_macro! {
Expand Down
5 changes: 0 additions & 5 deletions futures-util/src/async_await/stream_select_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#[cfg(feature = "std")]
#[allow(unreachable_pub)]
#[doc(hidden)]
#[cfg_attr(not(fn_like_proc_macro), proc_macro_hack::proc_macro_hack(support_nested))]
pub use futures_macro::stream_select_internal;

/// Combines several streams, all producing the same `Item` type, into one stream.
Expand All @@ -13,10 +12,6 @@ pub use futures_macro::stream_select_internal;
///
/// If multiple streams are ready, one will be pseudo randomly selected at runtime.
///
/// This macro is gated behind the `async-await` feature of this library, which is activated by default.
/// Note that `stream_select!` relies on `proc-macro-hack`, and may require to set the compiler's recursion
/// limit very high, e.g. `#![recursion_limit="1024"]`.
///
/// # Examples
///
/// ```
Expand Down

0 comments on commit 09b0186

Please sign in to comment.