Rust edition upgrade, DX fix for generated token macros #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Breaking changes
Generated token macros are no longer
#[macro_export]
The
Token
derive macro generates amacro_rules!
macro for each of the enum variants. E.g., for Lox'sToken
enum inexamples/lox
:We get
macro_rules!
macros namedkeyword
,ident
,brace
,punct
,operator
,num_lit
andstr_lit
. These are mostly useful for theParse
implementations, e.g.:Previously, those generated macros were declared like this:
That has always caused some headaches which I was never really sure how to deal with. In the examples here, and in my consuming projects, I had resorted to using
*
imports everywhere to work around the problem (in hindsight though, I think that likely just hides the lint by obscuring what we're doing instead of actually addressing the issue).This PR attempts an alternative solution.
#[macro_export]
is intended for libraries to expose macros to external consumers, but I don't foresee the macros generated by theToken
derive being actually useful in that context. So instead, the generated macros are now declared like this:This is a breaking change for two reasons:
If you were depending on those
#[macro_export]
attributes to make the generated macros available to external consumers of your library, that is no longer going to work. Again, I don't imagine this was actually a real-world use case for anyone, but I've been wrong before! Let me know if this is a problem for you and I'll see what we can do about it.If you had been importing those macros from the root of your crate, but your
Token
enum is not declared in the crate root, you'll need to update your import paths to instead import them from the module where the enum is declared. E.g.:On the bright side, tools like
rust-analyzer
should now find and automatically suggest the correct import paths for those macros, so the fastest way to migrate will probably be to just delete your existinguse
statement and invoke your editor's suggestion feature to re-import any unresolved symbols from their correct paths.Other changes
Updated the Rust edition to 2021 and fixed any resulting errors
Fixed any new
clippy
lints as a result of upgrading my environment to v1.77.2Performed some low-hanging-fruit dependency upgrades.
regex-automata
andsyn
are still out of date for now — I attempted to update the former, but couldn't figure out how to migrate after ~10 minutes of poking around, and unfortunately I have other priorities that need to take precedence. Didn't even attemptsyn
because it's a major version bump, and that crate is basically the backbone of this whole project, so it'll have to wait for now.