Uh oh!
There was an error while loading. Please reload this page.
Rework treatment of $crate in procedural macros - #56647
Conversation
petrochenkov
commented
Dec 9, 2018
cc @dtolnay@eddyb |
This comment has been minimized.
This comment has been minimized.
dtolnay
left a comment
There was a problem hiding this comment.
src/test/ui/proc-macro/dollar-crate.stdout looks good to me.
Uh oh!
There was an error while loading. Please reload this page.
alexcrichton
commented
Dec 10, 2018
@bors: r+ This sounds like a solid strategy to me, thanks @petrochenkov! |
alexcrichton
commented
Dec 10, 2018
@bors: r+ |
alexcrichton
commented
Dec 10, 2018
@bors: r+ |
bors
commented
Dec 10, 2018
📌 Commit 66a76b456801a4c409f5f7cfc2013e669dc04855 has been approved by |
petrochenkov
commented
Dec 10, 2018
@bors r- |
petrochenkov
commented
Dec 10, 2018
@bors r=alexcrichton |
bors
commented
Dec 10, 2018
📌 Commit 52d89f64fa3835229d8e4b495820a598b2b9bebc has been approved by |
Centril
commented
Dec 16, 2018
This PR might have failed #56873 (comment); might possibly also have been due to being combined with #56737. |
bors
commented
Dec 17, 2018
⌛ Testing commit 52d89f64fa3835229d8e4b495820a598b2b9bebc with merge 995baf76c1a4bf0b4e7ce8e604a168297c0c5806... |
bors
commented
Dec 17, 2018
💔 Test failed - status-travis |
bors
commented
Dec 19, 2018
📌 Commit f756257 has been approved by |
petrochenkov
commented
Dec 19, 2018
@bors r- |
petrochenkov
commented
Dec 19, 2018
@bors r=alexcrichton |
bors
commented
Dec 19, 2018
📌 Commit edab6c7 has been approved by |
bors
commented
Dec 20, 2018
⌛ Testing commit edab6c7 with merge 029fea7a15eca70cfe0bdd01e938a100c43c9b14... |
bors
commented
Dec 20, 2018
💔 Test failed - status-travis |
rust-highfive
commented
Dec 20, 2018
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 |
petrochenkov
commented
Dec 20, 2018
Spurious ( |
bors
commented
Dec 20, 2018
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#55640Closes#56622 r? @ghost
bors
commented
Dec 20, 2018
☀️ 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. Fixesrust-lang#62325 Previous iterations - rust-lang#56647, rust-lang#57155, rust-lang#57915.
Important clarification:
$cratebelow means "processed$crate" or "output$crate". In the input of a decl macro$crateis just two separate tokens, but in the output of a decl macro$crateis a single keyword identifier (#55640 (comment)).First of all, this PR removes the
eliminate_crate_varhack.$crate::foois no longer replaced with::fooor::crate_name::fooin 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 (likecrateorself) after that. (Note:eliminate_crate_varwas never used for non-derive proc macros.)This creates an annoying problem - derive macros still may stringify their input before processing and expect
$cratesurvive 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_varhack in reduced form, but apply it only to AST pretty-printing.If an AST fragment is pretty-printed, the resulting text will have
$cratereplaced withcrateor::crate_name. This should be enough to keep all the legacy cases working.Closes#55640
Closes#56622
r? @ghost