-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking issue for RFC 1566: Procedural macros #38356
Comments
cc @nrc @jseyfried |
I'd love for Prototype: https://github.com/abonander/anterofit/blob/proc_macro/macros/src/lib.rs |
Tasks(dtolnay edit: moved the checklist up to the OP) |
@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? |
@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? |
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.
|
…, r=jseyfried Change tracking issue for `proc_macro` feature to rust-lang#38356 r? @jseyfried
…, r=jseyfried Change tracking issue for `proc_macro` feature to rust-lang#38356 r? @jseyfried
…, r=jseyfried Change tracking issue for `proc_macro` feature to rust-lang#38356 r? @jseyfried
…, r=jseyfried Change tracking issue for `proc_macro` feature to rust-lang#38356 r? @jseyfried
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. |
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). |
IIUC, Spans are the primary way of tracking hygiene context. |
@mark-i-m Kind of. They include both source code location information (for user-facing messages/diagnostics) and syntax context (i.e. hygiene information). |
Given the amount of discussion/traffic this issue gets, does it make sense to move |
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 👍 |
The |
@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 |
@alexcrichton I'm perfectly fine with that, it's more that in the process of looking at the @xieyuheng What would |
The extended API for |
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. |
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 |
…omatsakis Renumber `proc_macro` tracking issues Lots of issue links in the compiler still point to rust-lang#38356 which is a bit of a monster issue that isn't serving much purpose any more. I've split the issue into a number of more fine-grained tracking issues to track stabilizations.
…omatsakis Renumber `proc_macro` tracking issues Lots of issue links in the compiler still point to rust-lang#38356 which is a bit of a monster issue that isn't serving much purpose any more. I've split the issue into a number of more fine-grained tracking issues to track stabilizations.
@alexcrichton What about of sub-attributes for attribute-like macro? |
@XX (Beside that classic legacy unstable custom attributes mentioned in #38356 (comment) are now compatible with proc macros.) |
@petrochenkov Yes, thanks for the clarification. |
Current Status
This issue has been closed in favor of more fine-grained tracking issues
~~~Updated Description~~~
Next steps:
use_extern_macros
proc_macro
featurePossible 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 Implement#[proc_macro_attribute]
#38842).proc_macro_derives
with#![feature(proc_macro)]
#39572).cfg
-process items before applying attribute proc macros #39336 (PR Apply attr proc macros before cfg processing #44528).#[proc_macro]
(PR Implement function-like procedural macros (#[proc_macro]
) #40129).proc_macro_derive
s in theInvocationCollector
(PR [WIP] Expand#[derive(..)]
s in the InvocationCollector #39391).proc_macro_derive
imports.proc_macro_derive
s (PR Expand items before their derives #48465).#[macro_use]
imports (PR Improve unusedextern crate
and unused#[macro_use]
warnings #39060).TokenStream
in preparation for further refactoring (PR RefactorTokenStream
#39173).TokenTree::Sequence
(PR SimplifyTokenTree
and fixmacro_rules!
bugs #39419).TokenStream
s instead ofVec<TokenTree>
intokenstream::TokenTree
'sDelimited
variant (PR syntax: integrateTokenStream
#40202).Path
s andTokenStream
s inast::Attribute
s (PRTokenStream
-based attributes, paths in attribute and derive macro invocations #40346).#[foo::bar]
,#[derive(foo::Bar)]
).Span
's expansion information #40597).proc_macro::TokenStream
as outlined in the RFC (PR proc_macro: implementTokenTree
,TokenKind
, hygienicquote!
, and other API #40939).TokenStream
s for interpolated AST fragments inToken::Interpolated
tokens.TokenStream
quoterproc_macro::quote!
behind theproc_macro
feature gate.proc_macro
authors to create expansions that use items in a predetermined cratefoo
without requiring the macro user to includeextern crate foo;
at the crate root (PR proc_macro: implementTokenTree
,TokenKind
, hygienicquote!
, and other API #40939).TokenStream
s for items in the AST.proc_macro::quote!
(issue Improve error from invalid syntax insideproc_macro::quote!
#47315).The text was updated successfully, but these errors were encountered: