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

Edition 2015 DeriveInput with edition 2018 keyword as ident fails to parse in syn 2.x #1408

Closed
matthias-stemmler opened this issue Mar 18, 2023 · 3 comments

Comments

@matthias-stemmler
Copy link

Thanks for your work on the 2.x release. I came across this issue when trying to update.

Starting from syn 2.x, the Parse impl of Ident rejects edition 2018 keywords such as async, so one has to use Ident::parse_any instead.
This is unfortunate when the ident is part of a more complex structure that's actually valid Rust code in edition 2015. Say you're implementing a derive macro and want to support edition 2015 code. Then parsing the macro input as a DeriveInput fails e.g. when the name of a struct field is a 2018 keyword.

Minimal example:

#[test]
fn test() {
    let _: syn::DeriveInput = syn::parse_quote! {
        struct Foo {
            async: (),
        }
    };
}

This panics with the message expected identifier. In syn 1.x it succeeds.

Other than implementing a custom parser for DeriveInput that uses Ident::parse_any, is there a recommended approach in this case?

@jonasbb

This comment was marked as off-topic.

@matthias-stemmler

This comment was marked as off-topic.

@dtolnay
Copy link
Owner

dtolnay commented Mar 20, 2023

Parsing arbitrary 2015-edition identifiers interchangeably with identifiers in newer edition code is not a thing I would want to do, but if there are specific unambiguous identifiers that are valuable to support in specific locations in the grammar (like async as a field of a struct) then I am open to PRs which make that parse.

The way this issue was filed, I am not sure if async in a field name of struct is specifically the case that you care about.

@dtolnay dtolnay closed this as completed Mar 20, 2023
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

No branches or pull requests

3 participants