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 upAdd a `literal` fragment specifier to `macro_rules!`. #1576
Conversation
LeoTestard
force-pushed the
LeoTestard:master
branch
4 times, most recently
from
5fa69f4
to
5c67bc0
Apr 8, 2016
pnkfelix
reviewed
Apr 8, 2016
|
|
||
| # Drawbacks | ||
|
|
||
| This is a bit inconsistent since it does not include all literal constants (in this context, I mean ‶literals that do not require any computation″): indeed it does not include compound literals, for example struct literals `Foo { x: some_literal, y: some_literal }` or arrays `[some_literal ; N]`, where `some_literal` can itself be a compound literal. See in alternatives why this is disallowed. |
This comment has been minimized.
This comment has been minimized.
pnkfelix
Apr 8, 2016
Member
The Design section should be expanded to specify what is the set of literal constants that you are adding here.
(I.e. the fact that you are adding the clarifying aside "in this context, I mean ..." in the drawbacks section is a bad sign -- the design section should have enough information for someone to deduce what you mean by "literal".)
LeoTestard
force-pushed the
LeoTestard:master
branch
2 times, most recently
from
8d9a531
to
7e55f54
Apr 8, 2016
This comment has been minimized.
This comment has been minimized.
bluss
commented
Apr 11, 2016
|
I've been missing this, for example in a macro that uses consecutive integer literals like |
This comment has been minimized.
This comment has been minimized.
DanielKeep
commented
Apr 11, 2016
|
Aye; there's an important alternative not mentioned in the RFC: use The problem I can see with this proposal is that it doesn't really simplify existing macros, nor open up new ones. The lack of backtracking means that even if this matcher is more specific than This will probably give better error messages on matching failures, but nothing else I can think of. No, wait, it does have one advantage over |
nrc
added
the
T-lang
label
Apr 17, 2016
nikomatsakis
assigned
pnkfelix
Apr 21, 2016
nikomatsakis
referenced this pull request
Apr 22, 2016
Closed
Allow lifetimes to be passed to macros #33135
bluss
referenced this pull request
Apr 23, 2016
Merged
Add a `lifetime` specifier to `macro_rules!` #1590
This comment has been minimized.
This comment has been minimized.
|
@DanielKeep The weight should be that big. And backtracking is coming with rust-lang/rust#33840. The better error messages are a big gain. :/ |
LeoTestard
force-pushed the
LeoTestard:master
branch
from
7e55f54
to
8d29a57
Jun 2, 2016
LeoTestard
force-pushed the
LeoTestard:master
branch
from
8d29a57
to
09aa1d6
Jun 2, 2016
This comment has been minimized.
This comment has been minimized.
|
(Edited to mention the possibility of using |
aturon
added
the
I-nominated
label
Jul 28, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @jseyfried in case you have an opinion on this |
This comment has been minimized.
This comment has been minimized.
|
also cc @cswords |
This comment has been minimized.
This comment has been minimized.
|
I'm in favour of this, though slightly (and vaguely) worried about the implementation details |
This comment has been minimized.
This comment has been minimized.
jseyfried
commented
Aug 4, 2016
•
|
I'm also in favour of this. I don't think implementation will be a problem, but I'm not too familiar with the details of how fragments are implemented. n.b. the reparse trick is no longer needed, so that's no longer an advantage over |
This comment has been minimized.
This comment has been minimized.
|
Hear ye, hear ye! This RFC is now entering final comment period. We discussed this at the most recent @rust-lang/lang meeting and decided that we are currently inclined to accept (of course no final decision has been reached). To summarize the discussion so far:
|
nikomatsakis
added
the
final-comment-period
label
Aug 8, 2016
This comment has been minimized.
This comment has been minimized.
|
I like this RFC. Would it make sense to also have more specific versions for specific kinds of literals? Several times, I've wanted to have a macro accept a string literal specifically. |
This comment has been minimized.
This comment has been minimized.
It's actually very simple, it just calls the parse_whatever() functions from libsyntax::parse::parser.
And the future-proofing is less good too. Using a more specific matcher restricts the FIRST sets, which is good.
I guess it would make sense, though the gain in terms of error messages is small. I'm not sure if it's possible though, since I think the libsyntax parser has a single parsing function for all literal types. It can surely be refactored and split into several functions, but I'm not sure it's worth it. |
This comment has been minimized.
This comment has been minimized.
Yeah, I wondered the same. Could be useful, but I guess there is value in "any literal" as well, and it's something we could easily add later. |
nrc
removed
the
I-nominated
label
Aug 11, 2016
This comment has been minimized.
This comment has been minimized.
|
@nrc Absolutely! To clarify, I'd love to see the proposed RFC accepted, and I don't want to bikeshed it. I'd also love to see specifiers for specific types of literals, which could either go in this RFC or a future RFC. |
This comment has been minimized.
This comment has been minimized.
|
Huzzah! The @rust-lang/lang team has decided to accept this RFC. |
nikomatsakis
referenced this pull request
Aug 12, 2016
Closed
Tracking issue for `literal` fragment specifier (RFC 1576) #35625
This comment has been minimized.
This comment has been minimized.
|
Tracking issue: rust-lang/rust#35625 If you'd like to keep following the development of this feature, please subscribe to that issue, thanks! :) |
nikomatsakis
merged commit 09aa1d6
into
rust-lang:master
Aug 12, 2016
This comment has been minimized.
This comment has been minimized.
|
Dear all, the implementation is now in |
Centril
added
A-macros
A-syntax
labels
Nov 23, 2018
This comment was marked as resolved.
This comment was marked as resolved.
pravic
commented
Jan 17, 2019
|
Is there any link to a rendered version? |
LeoTestard commentedApr 8, 2016
•
edited by Centril
Add a
literalfragment specifier formacro_rules!patterns that matches literal constants.Rendered