Repository navigation
Tracking issue for the quote! macro in proc_macro #54722
Copy link
Copy link
Open
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-proc_macro_quote`#![feature(proc_macro_quote)]``#![feature(proc_macro_quote)]`S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-langRelevant to the language teamRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
I'm splitting this off #38356 to track the quote! macro specifically contained in proc_macro. This macro has different syntax than the quote crate on crates.io but I believe similar functionality. At this time it's not clear (to me at least) what the status of this macro is in terms of how much we actually want to stabilize it or what would block its stabilization. Others are welcome to fill this in though!
Steps / History
- RFC: https://rust-lang.github.io/rfcs/1566-proc-macros.html
- Implementation: proc_macro: implement
TokenTree,TokenKind, hygienicquote!, and other API #40939 - Stabilization:
Unresolved questions
- proc_macro::quote does not work with interpolated constant inside repetition #146603
- Should this use
$to match other macros or#to drop in withquote::quote? Tracking issue for thequote!macro inproc_macro#54722 (comment) - Which spans should be used? Tracking issue for the
quote!macro inproc_macro#54722 (comment)
From #54722 (comment):
- Do we want our own version of
quote::ToTokensrather than relying onFrom? Changed in Tracking Issue forproc_macro::ToTokens#130977 - Should we add repetition before stabilization?
Reacted by Stanislav Tkach, Jacob Pratt, Finn Bear, Voltangle, Gabriel Onezio Ferreira, Mo Bitar, George Bateman, Isak Wertwein, Orión, José Luis Cruz and 4 more
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-proc_macro_quote`#![feature(proc_macro_quote)]``#![feature(proc_macro_quote)]`S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-langRelevant to the language teamRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Activity
alexcrichton commentedon Oct 1, 2018
Ah, and this is also tracking the
proc_macro_quotefeature.eddyb commentedon Nov 3, 2018
We need to avoid
.clone()-ing the variables interpolated byquote!, we should have&T -> TokenStream(or, better, an append taking&T, &mut TokenStream, like thequotecrate).EDIT: thinking more about it, I think we should support
TokenStream, all theproc_macrotypes that convert toTokenStream, including references of all of those, and, on top of that, anything that.extend(...)on aTokenStreamwould take (I haven't checked, do we implementExtendfor it?).I don't like
$$used for escaping$, I'd prefer if\$was used (we could make$$an error for now).We should make sure we error on
$(...)even if we don't start supporting repetition syntax right away, to reserve the right to do so in the future.And maybe we should consider
${...}for nesting expressions, but, again, as long as any unsupported syntax that starts with$errors, we can extend it later.There's also the question of what to do about spans. The
quotecrate has a version of the macro that also takesSpan, but I'd prefer pointing to the proc macro source wherequote!was used.For this, we can use an unstable
Spanconstructor that takes aSourceFilereference and a byte range into that, and an unstable constructor forSourceFilethat provides all the per-fileSourceMapinformation (file path, expected content hash, line map, etc.) the compiler needs.Making def-site hygiene also work would be trickier, but not impossible AFAIK.
cc @petrochenkov
alercah commentedon Jan 9, 2019
alercah commentedon Jan 9, 2019
alexreg commentedon Jan 9, 2019
Yes please.
jjpe commentedon Jan 9, 2019
I'm wondering what the reasoning is behind the preference for
\$over$$.Is it purely a syntactic style preference? Or is there more to it?
I ask because as I see it (but without announcing a preference either way),
$$has the advantage of being easier to type for pretty much everyone, while it has the disadvantage of being less easy to read for e.g. people with dyslexia.alexreg commentedon Jan 9, 2019
@jjpe As I see, there are two main reasons: 1) easier to read (can be picked out at a glance with less difficulty), 2) agrees with long-established convention of backslash escapes (beginning with C I think, but existing in most current languages for strings, including Rust).
Furthermore, it will probably be more common to escape
$than it will be to escape\in macros.jan-hudec commentedon Jan 9, 2019
@alexreg, main advantage of
$$is that it does not need another special character. In this case there is only one, so adding another doubles the complexity. If there were more special characters, a common escape would make sense, but in this case there is only one and most of the languages that have only one special character escape it by doubling it.alexreg commentedon Jan 10, 2019
@jan-hudec That's not a real advantage to me. There's no additional complexity, when you already have all of those chars in the syntax. And I think the two reasons I gave above are more pertinent.
37 remaining items
GoldsteinE commentedon Aug 21, 2024
I’d argue that
#is better, since it lets you generate declmacros without escaping. I’m not sure what are the advantages of$here.traviscross commentedon Aug 21, 2024
Apropos of proposed RFC 3607, we're considering an
.#tagsyntax for accessing the discriminant of an enum. See here.More generally, we find ourselves wanting to use the
#syntax space (e.g.), and so an interpolation syntax that doesn't conflict with that has some appeal.workingjubilee commentedon Aug 30, 2024
So concretely, the hardest blockers seem to be:
Span::def_site()OR makequote!useSpan::{call,mixed}_site()OR otherwise address the span issue so that we don't compromise diagnosticsAt least personally, I consider "feature-parity with the crate" to be a huge "nice-to-have" and something that's easy to use as a block to ever shipping this. We should focus mainly on those that we expect to be essentially impossible to simply tack on later, which will probably include...
Rollup merge of rust-lang#134693 - SpriteOvO:proc-macro-use-to-tokens…
Unrolled build for rust-lang#134693
Rollup merge of rust-lang#134693 - SpriteOvO:proc-macro-use-to-tokens…
ora-0 commentedon May 26, 2025
What's the behavior with strings? For example would
be interpreted as templating the
$identinto the string or would the string be literally"$ident"? If it is in the case of the former would raw strings have an exception?jhpratt commentedon May 26, 2025
@ora-0 It would be the literal string
"$ident". If you wanted it to be a string with the contents of$ident, you'd need to useSamB commentedon Apr 27, 2026
@dtolnay said
See:
proc_macroin non-proc-macrocrates #130856I'm not sure if this should block stabilization or not: while it's not needed to make this work, it does seem like a serious deterrent to testing by actual users, what with the, um, testing difficulties...