Skip to content

Tracking issue for the quote! macro in proc_macro #54722

Open

Description

@alexcrichton

View all comments

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

Unresolved questions

From #54722 (comment):

Activity

  1. added
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    T-libs-api[DEPRECATED; DO NOT USE]
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    on Oct 1, 2018
  2. alexcrichton commented on Oct 1, 2018

    @alexcrichton
    MemberAuthor

    Ah, and this is also tracking the proc_macro_quote feature.

  3. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Oct 1, 2018
  4. eddyb commented on Nov 3, 2018

    @eddyb
    Contributor

    We need to avoid .clone()-ing the variables interpolated by quote!, we should have &T -> TokenStream (or, better, an append taking &T, &mut TokenStream, like the quote crate).

    EDIT: thinking more about it, I think we should support TokenStream, all the proc_macro types that convert to TokenStream, including references of all of those, and, on top of that, anything that .extend(...) on a TokenStream would take (I haven't checked, do we implement Extend for 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 quote crate has a version of the macro that also takes Span, but I'd prefer pointing to the proc macro source where quote! was used.

    For this, we can use an unstable Span constructor that takes a SourceFile reference and a byte range into that, and an unstable constructor for SourceFile that provides all the per-file SourceMap information (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

  5. alercah commented on Jan 9, 2019

    @alercah
  6. alercah commented on Jan 9, 2019

    @alercah
  7. alexreg commented on Jan 9, 2019

    @alexreg
    Contributor

    I don't like $$ used for escaping $, I'd prefer if \$ was used (we could make $$ an error for now).

    Yes please.

  8. jjpe commented on Jan 9, 2019

    @jjpe

    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.

  9. alexreg commented on Jan 9, 2019

    @alexreg
    Contributor

    @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.

  10. jan-hudec commented on Jan 9, 2019

    @jan-hudec

    @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.

  11. alexreg commented on Jan 10, 2019

    @alexreg
    Contributor

    @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.

  12. 37 remaining items

  13. GoldsteinE commented on Aug 21, 2024

    @GoldsteinE
    Contributor

    I’d argue that # is better, since it lets you generate declmacros without escaping. I’m not sure what are the advantages of $ here.

  14. traviscross commented on Aug 21, 2024

    @traviscross
    Contributor

    Apropos of proposed RFC 3607, we're considering an .#tag syntax 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.

  15. workingjubilee commented on Aug 30, 2024

    @workingjubilee
    Member

    So concretely, the hardest blockers seem to be:

    1. Stabilize Span::def_site() OR make quote! use Span::{call,mixed}_site() OR otherwise address the span issue so that we don't compromise diagnostics
    2. (ahem) hash out any details about the unquoting syntax
    3. bjorn3's remark about hygiene which might be 1 again (I haven't expanded the tokens fully yet)

    At 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...

    1. deciding on including repetition or not
  16. added a commit that references this issue on Jan 10, 2025
  17. added a commit that references this issue on Jan 10, 2025
  18. added a commit that references this issue on Mar 11, 2025
  19. ora-0 commented on May 26, 2025

    @ora-0

    What's the behavior with strings? For example would

    quote! {
        println!("$ident")
    }

    be interpreted as templating the $ident into the string or would the string be literally "$ident"? If it is in the case of the former would raw strings have an exception?

  20. jhpratt commented on May 26, 2025

    @jhpratt
    Member

    @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 use

    let ident = ident.to_string();
    quote! {
        println!($ident)
    }
  21. SamB commented on Apr 27, 2026

    @SamB

    @dtolnay said

    One other difference besides repetitions and $ vs # is that the external quote is unit testable -- the proc_macro quote produces a proc_macro::TokenStream which can only exist within the context of a procedural macro, so any functions or helper libraries that you write using proc_macro quote will panic when called from a unit test.

    See:

    I'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...

  22. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  23. added
    I-libs-radarLibs issues that are tracked on the team's radar.
    and removed
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-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.T-langRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions