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: declarative macros 2.0 #39412
Comments
nrc
added
A-macros
B-RFC-approved
B-unstable
T-lang
labels
Jan 30, 2017
This comment has been minimized.
This comment has been minimized.
|
@nrc Typo in Issue Name: "issuse" |
nikomatsakis
changed the title
Tracking issuse: declarative macros 2.0
Tracking issue: declarative macros 2.0
Jan 30, 2017
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.
Tasks(dtolnay edit: moved the checklist up to the OP) |
This comment has been minimized.
This comment has been minimized.
|
We need to RFC a whole bunch of stuff here. In particular, I would like to propose some new syntax for declaring macros and we should RFC the changes to matchers. |
This was referenced Feb 8, 2017
This was referenced Feb 27, 2017
This comment has been minimized.
This comment has been minimized.
|
Can the hygiene RFC mention pattern hygiene? This in particular scares me: // Unsuspecting user's code
#[allow(non_camel_case_types)]
struct i(i64);
macro_rules! ignorant_macro {
() => {
let i = 0;
println!("{}", i);
};
}
fn main() {
// oh no!
ignorant_macro!();
} |
This comment has been minimized.
This comment has been minimized.
|
@tikue I'm not sure patterns need special treatment with respect to hygiene. For example, on the hygiene prototype, #[allow(non_camel_case_types)]
struct i(i64);
macro ignorant_macro() {
let i = 0; // ERROR: let bindings cannot shadow tuple structs
println!("{}", i);
}
fn main() {
ignorant_macro!(); // NOTE: in this macro invocation
}This makes sense to me since Note the symmetry to this example: #[allow(non_camel_case_types)]
struct i(i64);
fn ignorant_fn() {
let i = 0; // ERROR: let bindings cannot shadow tuple structs
println!("{}", i);
}If the tuple struct mod foo {
pub macro ignorant_macro() {
let i = 0;
println!("{}", i); // Without `let i = 0;`, there would be no `i` in scope here.
}
}
// Unsuspecting user's code
#[allow(non_camel_case_types)]
struct i(i64);
fn main() {
foo::ignorant_macro!();
} |
jseyfried
referenced this issue
Mar 17, 2017
Merged
macros: improve `Span`'s expansion information #40597
kennytm
referenced this issue
Jun 29, 2017
Merged
Only match a fragment specifier if it starts with certain tokens. #42913
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
Has there been any progress on Macros 2.0 lately? |
jan-hudec
referenced this issue
Oct 5, 2017
Closed
Tracking issue for RFC 1566: Procedural macros #38356
dtolnay
referenced this issue
Jan 27, 2018
Closed
Using Macros 2.0 to generate a module does not allow access to items #47797
This comment has been minimized.
This comment has been minimized.
|
Note for those who haven't seen yet: macros 2.0 is apparently slated to be stable later this year, according to the proposed roadmap (rust-lang/rfcs#2314)... On the one hand, that's pretty exciting On the other hand, I was really surprised that the feature is so close to being done and so little is known about it by the broader community... The RFC is really vague. The unstable book only has a link to this issue. This issue(s) in the issue tracker mostly have detailed technical discussions. And I can't find that much info anywhere about what's changed or how stuff works. I don't mean to complain, and I really truly appreciate all the hard work by those implementing, but I would also appreciate more transparency on this. |
This comment has been minimized.
This comment has been minimized.
|
@marcbowes Yeah, I'm kind of worried too. It seems like there's quite a lot of work left for stabilisation this year. I offered to work on opt-out hygiene for identifiers myself, but have received no response yet... Some greater transparency would be nice, as you say. |
This comment has been minimized.
This comment has been minimized.
|
Macros 2.0 are not even in the RFC stage yet - the @jseyfried's RFC linked in the issue was never submitted, there's only very high level RFC 1584.
The problem is that no work happen right now, so there's nothing to reveal :( |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov Ah, fair enough. I mean, that's a shame, but it makes sense at least. I guess this is an open call to anyone who might be able to take ownership of this feature, since no one comes to mind? I could still have a go at a little sub-feature, but I'm certainly in no position to take ownership of this. |
This comment has been minimized.
This comment has been minimized.
Yes, please do! IIRC, two questions will need to be decided on during implementation:
|
This comment has been minimized.
This comment has been minimized.
Yeah, this was the plan. :-)
What's your inclination? I'm leaning towards the context of m's invocation, but curious to hear your thoughts... |
This comment has been minimized.
This comment has been minimized.
|
@pierzchalski Yeah, that's not a bad idea at all. Thoughts, @jseyfried / @petrochenkov? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@pierzchalski I'll give that RFC a read tomorrow. Anyway, I certainly won't be including this Incidentally, you seem to have a good knowledge of macro expansion and hygiene. Could I tempt you to contribute to rust-lang/rustc-guide#15? :-) |
This was referenced Feb 3, 2018
This comment has been minimized.
This comment has been minimized.
|
@alexreg Unfortunately my understanding of expansion and hygiene is a bit abstract - you'll notice the reference-level explanation in the RFC was rather thin! But if the RFC is accepted and I end up implementing it then I'd definitely like to document what I discover along the way. |
smangelsdorf
referenced this issue
Feb 18, 2018
Open
Path extractors don't check path strings have correct names #145
This comment has been minimized.
This comment has been minimized.
|
I filed #49629 to consider dropping support for |
SimonSapin
referenced this issue
Apr 4, 2018
Closed
Tracking issue for "macro naming and modularisation" (RFC #1561) #35896
alexreg
referenced this issue
Jul 13, 2018
Open
Hygiene opt-out (escaping) for declarative macros 2.0 #2498
This comment has been minimized.
This comment has been minimized.
isiahmeadows
commented
Aug 30, 2018
|
Stylistic question: why is it |
This comment has been minimized.
This comment has been minimized.
|
I believe the question mark isn't considered part of the name. |
This comment has been minimized.
This comment has been minimized.
isiahmeadows
commented
Aug 31, 2018
|
@mark-i-m You mean exclamation point, not question mark, right? Also, in the docs, it usually refers to macros including the exclamation point as if it were part of the name, such as |
This comment has been minimized.
This comment has been minimized.
|
Oh, yes, I meant exclamation mark. I might be wrong, but I believe the compiler itself doesn't count the exclamation mark as party of the ident. |
This comment has been minimized.
This comment has been minimized.
isiahmeadows
commented
Aug 31, 2018
|
@mark-i-m I would expect the compiler not to, but I'm speaking of the language itself, not the implementation. I'm suggesting matching what people think, not what computers process. |
This comment has been minimized.
This comment has been minimized.
|
That said, I don't see any reason why we cannot do something different from the internal representation. If we did want to make ! part of the name, we would also want to do it in macro imports in the 2018 edition. |
This comment has been minimized.
This comment has been minimized.
isiahmeadows
commented
Aug 31, 2018
|
@mark-i-m If you change how you do it in imports, you could even integrate them into
Even as recently as a couple days ago, I had to google how to import a macro from a peer module, and this would make it a million times simpler. It also wouldn't require any special attribute or whatever - it'd just work. Similarly, exporting macros could be simply |
This comment has been minimized.
This comment has been minimized.
|
@isiahmeadows you can do Long term IIUC, the plan is to get rid of the attributes altogether (currently, you still need them to export macros). I strongly prefer not to conflate functions and macros. They are very different. |
This comment has been minimized.
This comment has been minimized.
The But of course if |
This comment has been minimized.
This comment has been minimized.
|
Macros live in another namespace. You can have a macro |
This comment has been minimized.
This comment has been minimized.
Ekleog
commented
Sep 9, 2018
|
This makes me wonder. If I have a crate Adding the Assuming it's still time to do it, though… otherwise, add the |
This comment has been minimized.
This comment has been minimized.
|
@Ekleog yes, both (along with potentially a module |
This comment has been minimized.
This comment has been minimized.
You cannot do that today: error: `proc-macro` crate types cannot export any items other than functions tagged with `#[proc_macro_derive]` currently
--> src/lib.rs:1:1
|
1 | pub fn some_public_function() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous errorHowever in an hypothetical future Rust where that restriction is lifted somehow, or if a non-proc-macro crate re-exports a proc macro and also a function of the same name, then yes |
Centril
referenced this issue
Sep 23, 2018
Open
Strange behavior decl_macro + try_blocks + type_ascription #54455
This was referenced Oct 8, 2018
This comment has been minimized.
This comment has been minimized.
|
Should small proposals for Macros2.0 be brought up here or in a separate issue? |
nrc commentedJan 30, 2017
•
edited by mbrubeck
Tracking issue for declarative macros 2.0 (aka
macroaka decl_macro aka macros-by-example).RFC: https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md
RFC PR: rust-lang/rfcs#1584
cc @rust-lang/compiler
Tasks
macroin blocks as well as modules.macros.macros (pending macro def encoding).private_in_publichygienic.unsafeand lints hygienic (if appropriate).ast::ItemKind::MacroDefformacro_rules!items andmacroitems (PR #40220).macros in the crate metadata usingTokenStream, notString.private_in_publicdetails).macrobehind a feature gate (PR #40847).$e:expr) by employing a simpler, more general grammar.$ewhere$e:expr) to be parsed in more contexts (c.f. #26361).