-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile error mixing declarative macros with procedural macros #82784
Comments
Looks like this is a regression introduced in 1.49.0 (probably #77135, cc @Aaron1011). Code# Cargo.toml
[package]
name = "repro"
version = "0.1.0"
authors = []
edition = "2018"
[dependencies]
# The `macro-debug' branch contains a patch that prints the input and output of `tokio::main`:
# https://github.com/taiki-e/tokio/commit/13bdbe4b15183887b4382382dc7a6295155e533e
tokio = { version = "1", features = ["full"], git = "https://github.com/taiki-e/tokio.git", branch = "macro-debug" } // src/main.rs
fn main() {
macro_rules! mac {
($e:expr) => {
#[tokio::main]
async fn f() -> i32 {
$e(())
}
};
}
mac!(|_| 5);
}
|
This is caused by the fact that we do not parse For now, this can be worked around by inserting extra parenthesis into the macro body - for example: |
As a side note - #77135 is only tangentially related to this. The root cause of this issue is the fact that we now preserve the original |
Unless we do some kind of closure-specific check in the parser, it's very unlikely that this will be resolved any time soon. |
Cross posting with tokio issue tracker.
I know how to work around this (can put parens around the macro variable:
($foo_factory)()
), but I don't think this should be happening in the first place. Feels like a bug in the macro system. This is reproducible in the playground:https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fb6d73cfb878547b438d8ec49431a4d2
concrete_tests2
andconcrete_tests3
compile whereasconcrete_tests1
does not.I'm producing a declarative macro that takes in an
expr
that is meant to be a closure, and produces a#[tokio::test]
that invokes that closure. The compile error is:The code (from the playground link above) is:
The text was updated successfully, but these errors were encountered: