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 `?` macro repetition #48075
Comments
nikomatsakis
added
T-lang
B-unstable
C-tracking-issue
labels
Feb 8, 2018
This comment has been minimized.
This comment has been minimized.
|
cc @mark-i-m |
This was referenced Feb 8, 2018
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis Could you update the checklist? The preliminary impl is available on nightly. |
kennytm
referenced this issue
Feb 27, 2018
Closed
Tracking issue for RFC 2298, `?` repetition in macro rules #48591
Centril
closed this
Feb 27, 2018
Centril
reopened this
Feb 27, 2018
Centril
added a commit
to rust-lang/rfcs
that referenced
this issue
Feb 27, 2018
This comment has been minimized.
This comment has been minimized.
|
@Centril I think you need to update the tracking issue in the RFC, too |
This comment has been minimized.
This comment has been minimized.
|
@mark-i-m Already done |
This comment has been minimized.
This comment has been minimized.
|
Is there any plan to stabilise this soon? |
This comment has been minimized.
This comment has been minimized.
|
I think it depends on experience if this is the right way to solve the problems involved... Frankly, I haven't really written any macros since I implemented this I think there is still the one problem that was pointed out in the RFC thread: this doesn't provide a clean solution for trailing commas in We could conceivably stabilize this anyway if people find it really useful. Any thoughts? |
This comment has been minimized.
This comment has been minimized.
|
I personally see it more ergonomic to have rules for Considering how it also allows optional arguments as well, I think it's pretty much a win here. |
This comment has been minimized.
This comment has been minimized.
|
As far as the one unresolved question (following separators) goes, I'm in favour of allowing it for the sake of a simpler grammar, but linting it in rustc (not clippy). That seems pretty ergonomic to me, and the compiler internally would have to accept it with a separator anyways to provide useful error messages. |
Centril
added a commit
to Centril/rfcs
that referenced
this issue
Apr 2, 2018
petrochenkov
referenced this issue
Apr 5, 2018
Closed
Hygiene opt-out for idents in expansion of declarative macros #47992
This comment has been minimized.
This comment has been minimized.
|
I don’t see the point of allowing the trailing separator even with a lint. It’s totally meaningless as you point out, so its existence in code would probably just perplex readers! |
This comment has been minimized.
This comment has been minimized.
Hmm... I guess this is a good point. It means that probably the code complexity (in the compiler) of keeping or not keeping the separator is about the same. Still, having a simpler grammar is nice, especially if libsyntax2.0 ever actually intends have something auto-generated. What about a deny-by-default lint? |
This comment has been minimized.
This comment has been minimized.
|
When would anyone ever allow the lint, though? This kinda sounds like "we can't decide, just make it configurable". |
This comment has been minimized.
This comment has been minimized.
My guess: probably never. On the other hand, when is anyone likely to actually use a separator for a single item? Will anyone ever run into the lint? The tradeoff is between a mildly simpler grammar and mildly simpler UX. |
This comment has been minimized.
This comment has been minimized.
|
The changes if we want disallow it are pretty minimal: diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs
index f324ede..a6fb782 100644
--- a/src/libsyntax/ext/tt/quoted.rs
+++ b/src/libsyntax/ext/tt/quoted.rs
@@ -470,8 +470,11 @@ where
GateIssue::Language,
explain,
);
+ } else {
+ sess.span_diagnostic
+ .span_err(span, "`?` macro repetition does not allow a separator");
}
- return (Some(tok), op);
+ return (None, op);
}
Ok(Ok(op)) => return (Some(tok), op), |
This comment has been minimized.
This comment has been minimized.
I think this is really "designer's/developer's motivation" vs. "user's motivation". And making the user happy should always win, I think. After all, there's a fair bit of ugly stuff in most compilers (including the Rust one), but most people don't care about it, because they don't touch it, and if they do they expect a significant learning curve. A compiler's end goal is to support a language rather than have an elegant internal structure (which is more of a bonus). The fact is, if you want to go messing with the compiler or libsyntax, taking the time to learn the slight difference between ? and */+ is no big deal. If you're a user, especially one new to Rust, that could be a real gotcha. Now, since from the Rust user's perspective this feature adds literally nothing, and adding an error (as @mark-i-m's diff shows) is very straightforward, I maintain we disallow it. @durka's point and the article he links to is also a good one. Configuration is only a good thing when it's absolutely needed. Convention over it any other time. |
This comment has been minimized.
This comment has been minimized.
|
I went back and re-read part of the RFC thread, and this comment stuck out to me: rust-lang/rfcs#2298 (comment) There is the question of what this matches:
Allowing the separator actually allows us to disambiguate:
But at the same time, this seems really dubious, since removing the separator seems like it should not change the pattern matched. If we disallow separator on
Admittedly, this is all a bit contrived, but it does seem to throw the balance in favor of disallowing a separator on EDIT: corrected typo |
This comment has been minimized.
This comment has been minimized.
|
Agreed that if removing the separator changes things that seems weird and bad. But it's a shame that in the latter scenario you can't match |
This comment has been minimized.
This comment has been minimized.
|
One option would be to change the disambiguation strategy. That is, we stop allowing |
This comment has been minimized.
This comment has been minimized.
|
We could allow precisely one separator, namely `?`, for this edge case:
`$(a)?? +` matches `a+` or `aa+`. That eliminates the trouble where an
unrelated separator has effects. Getting a little hacky though.
…On Thu, Apr 5, 2018 at 4:20 PM, Who? Me?! ***@***.***> wrote:
One option would be to change the disambiguation strategy. That is, we
stop allowing ? as a separator for any of the Kleene operators. This
would be a breaking change, but perhaps it might not be that bad?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#48075 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n2Z5dotnKZCdGgLKn_SW42RzRPboks5tlnyqgaJpZM4R-yf0>
.
|
This comment has been minimized.
This comment has been minimized.
|
Now that you mention that, maybe a two-character |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Stabilization Report
|
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis @Centril done :) Let me know if I missed anything |
This comment has been minimized.
This comment has been minimized.
|
Also, it looks like the checklist in the OP should be updated. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Well done on the super-meticulous work @mark-i-m. Glad we can finally get this feature stabilised! |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 20, 2018
|
|
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Nov 20, 2018
This comment has been minimized.
This comment has been minimized.
|
@mark-i-m Since you did the implementation work, could you prepare a PR for the stabilization as well? :) |
This comment has been minimized.
This comment has been minimized.
|
Sure, but it might be a few days before I can get to it |
This comment has been minimized.
This comment has been minimized.
|
@mark-i-m Ah; there's no great rush; 1.32 goes into beta on the 7th. Do you think you can get it landed by then? |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I think I could do it by the end of the week. |
mark-i-m
referenced this issue
Nov 26, 2018
Merged
Stabilize feature `macro_at_most_once_rep` #56245
bors
added a commit
that referenced
this issue
Nov 28, 2018
pietroalbini
added a commit
to pietroalbini/rust
that referenced
this issue
Nov 28, 2018
pietroalbini
added a commit
to pietroalbini/rust
that referenced
this issue
Nov 28, 2018
bors
added a commit
that referenced
this issue
Nov 29, 2018
This comment has been minimized.
This comment has been minimized.
|
#56245 has merged |
nikomatsakis commentedFeb 8, 2018
•
edited by cramertj
RFC: rust-lang/rfcs#2298
Status
Known bugs
None.
Unresolved questions to be answered before stabilization
?Kleene operator accept a separator? Adding a separator is completely meaningless (since we don't accept trailing separators, and ? can accept "at most one" repetition), but allowing it is consistent with+and*. Currently, we allow a separator. We could also make it an error or lint.