-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Add support for repetition to proc_macro::quote #140238
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, ..)A-proc-macrosArea: Procedural macrosArea: Procedural macrosC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.F-proc_macro_quote`#![feature(proc_macro_quote)]``#![feature(proc_macro_quote)]`T-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.WG-macrosWorking group: MacrosWorking group: Macros
Description
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, ..)A-proc-macrosArea: Procedural macrosArea: Procedural macrosC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.F-proc_macro_quote`#![feature(proc_macro_quote)]``#![feature(proc_macro_quote)]`T-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.WG-macrosWorking group: MacrosWorking group: Macros
Type
Fields
Give feedbackNo fields configured for issues without a type.
Part 1: complete in #141608
I'm opening a standalone issue to have something with "help wanted" labels in case anyone is interested in picking this up.
Our
proc_macro::quotedoes not support repetition, unlikequotefrom thequotecrate. As mentioned many times on the tracking issue, this is something we should support or at least account for beforeproc_macro::quotecan be stabilized.This should use the syntax:
Where
CONTENTSis the thing to be repeated andSEPis an optional single-character separator. Expansion should work for anything that implementsIntoIterator. This matches the quote crate's logic (except quote::quote uses#rather than$).It's probably easiest to just copy
quote's logic here, which uses an extension trait to facilitate this.quotecrate source repo: https://github.com/dtolnay/quote.quotethat needs to be updated: https://github.com/rust-lang/rust/blob/fa58ce343ad498196d799a7381869e79938e952a/library/proc_macro/src/quote.rstests/ui/proc-macro/quotefor things we should reject)quote!macro inproc_macro#54722Part 2: incomplete
From @dtolnay's comment at #141608 (comment), there are some more minor issues to be resolved before stabilization:
Macro_rules macro:
a << b << cQuote crate:
a << b << cLibproc_macro:
Another example:
The parsing logic will need some more scrutiny in followup PRs before the macro can be stabilized.