macros: Allow field path segments to be keywords #2925
+45
−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.
Motivation
Currently, a keyword like
type
fails compilation as (a path segment of) a field name, for no clear reason. Trying to user#type
instead leads to ther#
being part of the field name, which is unhelpful¹.Solution
Don't require the field path to match a
macro_rules!
expr
, use repeatedtt
instead. I can't tell why this was ever required: The internal stringify macro was introduced in 55091c9#diff-315c02cd05738da173861537577d159833f70f79cfda8cd7cf1a0d7a28ace31b with anexpr
matcher without any explanation, and no tests are failing from making it match upstream'sstringify!
input format.Special thanks to whoever implemented the unstable
macro-backtrace
feature in rustc, otherwise this would have been nigh impossible to track down!¹ this can likely be fixed too by some sort of "unraw" macro that turns
r#foo
intofoo
, but that's a separate change not made in this PR