-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Rework treatment of $crate
in procedural macros
#56647
Conversation
cc @dtolnay @eddyb |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/test/ui/proc-macro/dollar-crate.stdout looks good to me.
@bors: r+ This sounds like a solid strategy to me, thanks @petrochenkov! |
@bors: r+ |
@bors: r+ |
📌 Commit 66a76b456801a4c409f5f7cfc2013e669dc04855 has been approved by |
66a76b4
to
52d89f6
Compare
@bors r- |
@bors r=alexcrichton |
📌 Commit 52d89f64fa3835229d8e4b495820a598b2b9bebc has been approved by |
This PR might have failed #56873 (comment); might possibly also have been due to being combined with #56737. |
⌛ Testing commit 52d89f64fa3835229d8e4b495820a598b2b9bebc with merge 995baf76c1a4bf0b4e7ce8e604a168297c0c5806... |
💔 Test failed - status-travis |
📌 Commit f756257 has been approved by |
@bors r- |
@bors r=alexcrichton |
📌 Commit edab6c7 has been approved by |
⌛ Testing commit edab6c7 with merge 029fea7a15eca70cfe0bdd01e938a100c43c9b14... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Spurious ( |
Rework treatment of `$crate` in procedural macros Important clarification: `$crate` below means "processed `$crate`" or "output `$crate`". In the input of a decl macro `$crate` is just two separate tokens, but in the *output of a decl macro* `$crate` is a single keyword identifier (#55640 (comment)). First of all, this PR removes the `eliminate_crate_var` hack. `$crate::foo` is no longer replaced with `::foo` or `::crate_name::foo` in the input of derive proc macros, it's passed to the macro instead with its precise span and hygiene data, and can be treated as any other path segment keyword (like `crate` or `self`) after that. (Note: `eliminate_crate_var` was never used for non-derive proc macros.) This creates an annoying problem - derive macros still may stringify their input before processing and expect `$crate` survive that stringification and refer to the same crate (the Rust 1.15-1.29 way of doing things). Moreover, the input of proc macro attributes and derives (but not fn-like proc macros) also effectively survives stringification before being passed to the macro (also for legacy implementation reasons). So we kind of resurrect the `eliminate_crate_var` hack in reduced form, but apply it only to AST pretty-printing. If an AST fragment is pretty-printed, the resulting *text* will have `$crate` replaced with `crate` or `::crate_name`. This should be enough to keep all the legacy cases working. Closes #55640 Closes #56622 r? @ghost
☀️ Test successful - status-appveyor, status-travis |
…ulacrum Fix pretty-printing of `$crate` (take 4) Pretty-print `$crate` as `crate` or `crate_name` in unstructured tokens like `a $crate c` in `foo!(a $crate c)`, but only if those tokens are printed as a part of AST pretty-printing, rather than as a standalone token stream. Fixes rust-lang#62325 Previous iterations - rust-lang#56647, rust-lang#57155, rust-lang#57915.
Important clarification:
$crate
below means "processed$crate
" or "output$crate
". In the input of a decl macro$crate
is just two separate tokens, but in the output of a decl macro$crate
is a single keyword identifier (#55640 (comment)).First of all, this PR removes the
eliminate_crate_var
hack.$crate::foo
is no longer replaced with::foo
or::crate_name::foo
in the input of derive proc macros, it's passed to the macro instead with its precise span and hygiene data, and can be treated as any other path segment keyword (likecrate
orself
) after that. (Note:eliminate_crate_var
was never used for non-derive proc macros.)This creates an annoying problem - derive macros still may stringify their input before processing and expect
$crate
survive that stringification and refer to the same crate (the Rust 1.15-1.29 way of doing things).Moreover, the input of proc macro attributes and derives (but not fn-like proc macros) also effectively survives stringification before being passed to the macro (also for legacy implementation reasons).
So we kind of resurrect the
eliminate_crate_var
hack in reduced form, but apply it only to AST pretty-printing.If an AST fragment is pretty-printed, the resulting text will have
$crate
replaced withcrate
or::crate_name
. This should be enough to keep all the legacy cases working.Closes #55640
Closes #56622
r? @ghost