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

Update to syn version 2 #299

Closed
wants to merge 3 commits into from
Closed

Conversation

Urist-McGit
Copy link
Contributor

As there were quite substantial changes from syn version 1 to 2 some minor changes to the codebase are necessary:

The Attribute type is more accurately typed now, that means instead of having simply a Path entity and some tokens after it, there is now a differentation between attributes with a =, in parentheses or without any other tokens but the path. This makes parsing slightly easier for us. Some test fixes were also required as these rely on the old tokens we got from an attribute.

The Spanned trait was sealed in syn v2. We implemented it for some of the internal meta types. As we still have the span information readily available and the trait is otherwise required nowhere, simply remove the impl.

Some syntax enums were marked as non-exhaustive. Handle these additional options in a sensible way where possible and throw compile errors in all other places.

@Urist-McGit
Copy link
Contributor Author

The failing tests come from some UI tests, the difference of one of them is here:

 -    |                    ^^^^^^^ the trait `Default` is not implemented for `VecArgs<()>`, which is required by `VecArgs<()>: MissingArgsDirective`
 +    |                    ^^^^^^^ the trait `Default` is not implemented for `VecArgs<()>`

Both of them have a similiar difference. Running the tests with the 1.79 and 1.80 compilers works fine, it is just nightly that seems to have changed the trait bound diagnostic message slightly.

@csnover
Copy link
Collaborator

csnover commented Nov 26, 2024

Yep, that happens from time to time and is easy for me to fix before the merge, no worries. The bigger issue is the code coverage failure caused by incompatibility between syn versions.

@csnover csnover self-assigned this Nov 26, 2024
let tokens = match &attr.meta {
syn::Meta::Path(_) => TokenStream::new(),
syn::Meta::List(ml) => ml.tokens.clone(),
syn::Meta::NameValue(nv) => nv.to_token_stream(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Really the only unaddressed question I have is regarding these new match arms. I believe that it had been the case that MetaAttrList would have failed a parse in parenthesized! before, but now that part of it has been uplifted into syn::Meta. I notice there is now a syn::Meta::require_list function. It seems to me like that should be used here instead?

Copy link
Contributor Author

@Urist-McGit Urist-McGit Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! Since the parsing was moved up, we should error out when it is not a Meta::List. I added and rebased the necessary changes.

Urist-McGit and others added 3 commits November 27, 2024 09:15
As there were quite substantial changes from syn version 1 to 2 some
minor changes to the codebase are necessary:

The `Attribute` type is more accurately typed now, that means instead
of having simply a `Path` entity and some tokens after it, there is now
a differentation between attributes with a `=`, in parentheses or
without any other tokens but the path. This makes parsing slightly
easier for us. Some test fixes were also required as these rely on the
old tokens we got from an attribute.

The `Spanned` trait was sealed in syn v2. We implemented it for some
of the internal meta types. As we still have the span information
readily available and the trait is otherwise required nowhere, simply
remove the impl.

Some syntax enums were marked as `non-exhaustive`. Handle these
additional options in a sensible way where possible and throw compile
errors in all other places.
@csnover
Copy link
Collaborator

csnover commented Nov 27, 2024

I’ve squashed the relevant commits together with a couple of irrelevant tweaks and merged this. It will be in the next release. Thank you so much for doing this work!

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 this pull request may close these issues.

2 participants