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

Parsing a syn::ItemFn fails with "unexpected token" on nightlies newer than 2020-05-24 #833

Closed
rrbutani opened this issue May 26, 2020 · 2 comments · Fixed by #834
Closed

Comments

@rrbutani
Copy link

rrbutani commented May 26, 2020

Caused by rust-lang/rust#72388; this has more details.

Here's a (kind of, but not really) minified test case:

macro_rules! import_macro {
    ($(($rust:ident, $js:ident, $i:ident))*) => ($(
        #[wasm_bindgen]
        pub fn $rust(a: &[$i]) -> Vec<$i> {
            $js(a, Some(a), None)
        }
    )*)
}

import_macro! {
    (import_rust_i8, import_js_i8, i8)
}

#[wasm_bindgen] tries to parse the function as a syn::ItemFn which fails on the function's block (specifically on the ( after $js). As mentioned in the linked issue, as best as I can tell, this happens because trailer_expr (in expr.rs) returns if it sees a group which causes Block::parse_within to only see $js rather than the whole expression. Block::parse_within then expects a semicolon after $js (since it's not the last thing in the block) which it doesn't see and so it errors.

As mentioned in the linked issue's thread, removing the token::Group check in trailer_expr seems to fix this problem but I don't know if this will cause other problems; I'm not very familiar with syn's internals.

I noticed #832 altered that exact check; I tested again with 1.0.26 and I still get the same error.

Also, slightly unrelated, but would it be correct for the error here to be "expected semicolon"?

@rrbutani rrbutani changed the title Parsing a syn::ItemFn fails with "unexpected token" Parsing a syn::ItemFn fails with "unexpected token" on nightlies newer than 2020-05-24 May 26, 2020
@dtolnay
Copy link
Owner

dtolnay commented May 26, 2020

Fixed in 1.0.27.

@rrbutani
Copy link
Author

Thank you!

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.

2 participants