Skip to content
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

syn fails to parse async fn inside None-delimited group #916

Closed
Aaron1011 opened this issue Nov 1, 2020 · 1 comment · Fixed by #917
Closed

syn fails to parse async fn inside None-delimited group #916

Aaron1011 opened this issue Nov 1, 2020 · 1 comment · Fixed by #917

Comments

@Aaron1011
Copy link
Contributor

The following code (repository: https://github.com/Aaron1011/async-syn):

// src/lib.rs
use syn::ItemFn;
use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn parse_fn(_attr: TokenStream, item: TokenStream) -> TokenStream {
    syn::parse_macro_input!(item as ItemFn);
    TokenStream::new()
}

// src/main.rs
macro_rules! make_fn {
    ($input:item) => {
        #[async_syn::parse_fn]
        fn outer() {
            $input
        }
    }
}

make_fn!(async fn inner() {});

fn main() {
    println!("Hello, world!");
}

gives the following error:

error: unexpected token
  --> src/main.rs:10:16
   |
10 | make_fn!(async fn inner() {});
   |                ^^

I think this is caused by the way syn does lookahead when parsing async fn. The error goes away if you change async fn inner() {} to fn inner() {}

Minimized from rust-lang/rust#78629

@Aaron1011 Aaron1011 changed the title syn fails to parse asnc fn inside None-delimited group syn fails to parse async fn inside None-delimited group Nov 1, 2020
@Aaron1011
Copy link
Contributor Author

@dtolnay Thanks for the fast fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant