Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 1566: Procedural macros #38356
Comments
aturon
added
A-macros
A-plugin
B-RFC-approved
labels
Dec 13, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @nrc @jseyfried |
This comment has been minimized.
This comment has been minimized.
|
I'd love for Prototype: https://github.com/abonander/anterofit/blob/proc_macro/macros/src/lib.rs |
This comment has been minimized.
This comment has been minimized.
Tasks(dtolnay edit: moved the checklist up to the OP) |
This comment has been minimized.
This comment has been minimized.
|
@jseyfried I ran into an issue where if a legacy macro and an attribute with the same name are imported into the same scope, trying to use the attribute throws an error that macros cannot be used as attributes. Can we make this work so that both can be in the same scope and can be used as intended? |
This comment has been minimized.
This comment has been minimized.
|
@abonander All macros (bang, attribute, and derive) share the same namespace, so we can't use two different macros with the same name in the same scope. However, we could improve that error message -- could you open an issue? |
jseyfried
referenced this issue
Jan 27, 2017
Closed
macros: don't `cfg`-process items before applying attribute proc macros #39336
keeperofdakeys
referenced this issue
Jan 29, 2017
Closed
[WIP] Expand `#[derive(..)]`s in the InvocationCollector #39391
jseyfried
referenced this issue
Jan 31, 2017
Merged
Simplify `TokenTree` and fix `macro_rules!` bugs #39419
This comment has been minimized.
This comment has been minimized.
|
Sorry I’m late to the party. I’m happy with the direction to expose tokens rather than an AST, but I have some concerns about the specific pub enum TokenKind {
Sequence(Delimiter, TokenStream),
// The content of the comment can be found from the span.
Comment(CommentKind),
// `text` is the string contents, not including delimiters. It would be nice
// to avoid an allocation in the common case that the string is in the
// source code. We might be able to use `&'codemap str` or something.
// `raw_markers` is for the count of `#`s if the string is a raw string. If
// the string is not raw, then it will be `None`.
String { text: Symbol, raw_markers: Option<usize>, kind: StringKind },
// char literal, span includes the `'` delimiters.
Char(char),
// These tokens are treated specially since they are used for macro
// expansion or delimiting items.
Exclamation, // `!`
Dollar, // `$`
// Not actually sure if we need this or if semicolons can be treated like
// other punctuation.
Semicolon, // `;`
Eof, // Do we need this?
// Word is defined by Unicode Standard Annex 31 -
// [Unicode Identifier and Pattern Syntax](http://unicode.org/reports/tr31/)
Word(Symbol),
Punctuation(char),
}
pub enum StringKind {
Regular,
Byte,
}It’s not clear if this API was intended as a complete plan that was accepted when the RFC was merged, or just an example to be worked out later. Generally, this seems far from the "normal" Rust syntax accepted by the compiler outside of macros. While some macros will want to parse some ad-hoc domain-specific language, others will want to parse "actual Rust" syntax and make sense of it.
|
jseyfried
referenced this issue
Feb 2, 2017
Closed
Tracking issue for "Macros 1.1" (RFC #1681) #35900
abonander
added a commit
to abonander/rust
that referenced
this issue
Feb 2, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Feb 4, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Feb 4, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Feb 5, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Feb 5, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Feb 5, 2017
jseyfried
referenced this issue
Feb 6, 2017
Merged
macros: fix inert attributes from `proc_macro_derives` with `#![feature(proc_macro)]` #39572
This comment has been minimized.
This comment has been minimized.
porky11
commented
Feb 21, 2017
|
another way to write high level macros would be using lisp like macros, but this would need a s-expression representation for the whole rust ast. |
jseyfried
referenced this issue
Feb 27, 2017
Closed
Macros 1.2: Fast-track to stabilize function-like procedural macros #1913
abonander
referenced this issue
Feb 28, 2017
Merged
Implement function-like procedural macros ( `#[proc_macro]`) #40129
This comment has been minimized.
This comment has been minimized.
Ekleog
commented
Aug 21, 2018
|
@jan-hudec Oh, I thought |
This comment has been minimized.
This comment has been minimized.
Ideally, fresh issues need be filed for all individual remaining issues and not stabilized features, and then this issue can be closed (in the same way like it was done for #44660). |
This comment has been minimized.
This comment has been minimized.
IIUC, Spans are the primary way of tracking hygiene context. |
This comment has been minimized.
This comment has been minimized.
|
@mark-i-m Kind of. They include both source code location information (for user-facing messages/diagnostics) and syntax context (i.e. hygiene information). |
CAD97
referenced this issue
Aug 24, 2018
Closed
Put the include_str into generated code rather than require users to write down it #260
Arnavion
referenced this issue
Sep 2, 2018
Closed
Nightly regression from stable - macro_rules macros collide with custom derive attributes #53898
aturon
removed this from the Rust 2018 RC milestone
Sep 5, 2018
This comment has been minimized.
This comment has been minimized.
|
Given the amount of discussion/traffic this issue gets, does it make sense to move |
SergioBenitez
referenced this issue
Sep 11, 2018
Open
Tracking Issue: Procedural Macro Diagnostics (RFC 1566) #54140
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
xd009642
commented
Sep 17, 2018
|
So I'm interesting in helping to stabilise the methods in Span and the LineColumn struct. I'll look at the open issues in the first comment, but if anyone wants to point a newbie to the compiler in a particular direction I'd appreciate it |
This comment has been minimized.
This comment has been minimized.
jjpe
commented
Sep 28, 2018
•
|
The |
This comment has been minimized.
This comment has been minimized.
|
@jjpe it's probably best at this time that we spin off dedicated tracking issues for those feature gates, this issue was largely dedicated to the initial wave of stabilizations |
This comment has been minimized.
This comment has been minimized.
jjpe
commented
Sep 30, 2018
|
@alexcrichton I'm perfectly fine with that, it's more that in the process of looking at the @xieyuheng What would |
This comment has been minimized.
This comment has been minimized.
|
The extended API for |
This comment has been minimized.
This comment has been minimized.
CodeSandwich
commented
Sep 30, 2018
•
|
It seems that since I understand, that this is necessary in order to preserver spans, hygiene and consistency with processed code. Is there or will be any way to work with content of modules in separate files? Its lack may be confusing for end users when trivial refactoring of module organization causes change in macro behavior. |
This was referenced Oct 1, 2018
This comment has been minimized.
This comment has been minimized.
|
Ok this issue is massive and has gotten to the point that I don't think it's too useful to keep open any more and track APIs. To that end I've opened #54728 which splits this issue into a number of more fine-grained tracking issues:
At this point I'm going to close this, but if I've forgotten to split off any other tracking issues please let me know! I can certainly open up some more follow-ups |
alexcrichton
closed this
Oct 1, 2018
pietroalbini
added a commit
to pietroalbini/rust
that referenced
this issue
Oct 2, 2018
pietroalbini
added a commit
to pietroalbini/rust
that referenced
this issue
Oct 2, 2018
This comment has been minimized.
This comment has been minimized.
XX
commented
Nov 23, 2018
•
|
@alexcrichton What about of sub-attributes for attribute-like macro? |
This comment has been minimized.
This comment has been minimized.
|
@XX (Beside that classic legacy unstable custom attributes mentioned in #38356 (comment) are now compatible with proc macros.) |
This comment has been minimized.
This comment has been minimized.
XX
commented
Nov 23, 2018
|
@petrochenkov Yes, thanks for the clarification. |
aturon commentedDec 13, 2016
•
edited by alexcrichton
Current Status
This issue has been closed in favor of more fine-grained tracking issues
~~~Updated Description~~~
Next steps:
use_extern_macrosproc_macrofeaturePossible Stabilization Showstoppers
Hygiene is weirdermacro_rules!and also having pre-1.29 compat is hardOriginal Description
RFC.
Roadmap: #38356 (comment).
Tasks
#[proc_macro_attribute](PR #38842).#[proc_macro](PR #40129).proc_macro_derives in theInvocationCollector(PR #39391).proc_macro_deriveimports.proc_macro_derives (PR #48465).#[macro_use]imports (PR #39060).TokenStreamin preparation for further refactoring (PR #39173).TokenTree::Sequence(PR #39419).TokenStreams instead ofVec<TokenTree>intokenstream::TokenTree'sDelimitedvariant (PR #40202).Paths andTokenStreams inast::Attributes (PR #40346).#[foo::bar],#[derive(foo::Bar)]).proc_macro::TokenStreamas outlined in the RFC (PR #40939).TokenStreams for interpolated AST fragments inToken::Interpolatedtokens.TokenStreamquoterproc_macro::quote!behind theproc_macrofeature gate.proc_macroauthors to create expansions that use items in a predetermined cratefoowithout requiring the macro user to includeextern crate foo;at the crate root (PR #40939).TokenStreams for items in the AST.proc_macro::quote!(issue #47315).