Open
Description
This is intended to be a tracking issue for enabling procedural macros to have "more hygiene" than the copy/paste hygiene they have today. This is a very vague tracking issue and there's a very long and storied history to this. The intention here though is to create a fresh tracking issue to collect the current state of play, in hopes that we can close some of the much older and very long issues which contain lots of outdated information.
Metadata
Metadata
Assignees
Labels
Area: Macro hygieneArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: Procedural macrosBlocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Relevant to the language teamWorking group: Macros
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Span::def_site()
#54724petrochenkov commentedon Oct 1, 2018
To give some background,
feature(proc_macro_hygiene)
tracked by this issue was merged from multiple features (proc_macro_mod
,proc_macro_expr
,proc_macro_non_items
,proc_macro_gen
) in #52121.So, it's pretty heterogeneous and is not even entirely about hygiene.
petrochenkov commentedon Oct 1, 2018
Copypasting what I wrote in #52121:
None of these features is blocked on hygiene, except for
proc_macro_gen
.proc_macro_mod
is, IIRC, about expanding inner attributes and expanding non-inline modules (mod foo;
). I'm not sure why#[my_macro] mod m { ... }
with outer attribute and inline module is still gated, I'm not aware of any reasons to not stabilize it.proc_macro_expr
/proc_macro_non_items
have no reasons to be gated as well and can be stabilized after some implementation audit. Proc macros have well-defined "copy-paste"Span::call_site()
hygiene, this includes "unhygienic" use of local variables.IIRC, @nrc assumed that additional feature gates would prevent interactions of that copy-paste hygiene with local variables, but that's not true - you can easily expand an item and inject tokens from the outside into its body (e.g. TokenStream::parse does not resolve with Span::call_site() #50050), causing exactly the same interactions.
What is really blocked on hygiene is
Span::def_site()
anddecl_macro
(which is also blocked on a ton of other stuff).petrochenkov commentedon Oct 1, 2018
proc_macro_gen
is more about interactions betweenSpan::call_site
hygiene (entirely unhygienic) andmacro_rules
hygiene (unhygienic except for local variables and labels).Extra proc macro gates are now at rust-lang#54727
CodeSandwich commentedon Oct 1, 2018
This looks like the right branch for this question. Sorry about copy-paste, but I really need to know.
It seems that since
rustc 1.30.0-nightly (63d51e89a 2018-09-28)
it is no longer possible to traverse code inside module in separate file. If you processmod module;
, you getTokenStream
containingmod module;
, WYSIWYG.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.
petrochenkov commentedon Oct 2, 2018
@CodeSandwich
This may be a regression from #52319 perhaps?
cc @tinco
113 remaining items