-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 ?
macro repetition
#48075
Comments
cc @mark-i-m |
@nikomatsakis Could you update the checklist? The preliminary impl is available on nightly. |
@Centril I think you need to update the tracking issue in the RFC, too 😛 |
@mark-i-m Already done 🤣 |
Is there any plan to stabilise this soon? |
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? |
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. |
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. |
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! |
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? |
When would anyone ever allow the lint, though? This kinda sounds like "we can't decide, just make it configurable". |
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. |
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), |
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. |
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 |
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 |
One option would be to change the disambiguation strategy. That is, we stop allowing |
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>
.
|
Now that you mention that, maybe a two-character |
Stabilization Report 🎉(Let me know if I missed anything) Description of behavior
Differences from RFC
Documentation and Testing
|
@nikomatsakis @Centril done :) Let me know if I missed anything |
Also, it looks like the checklist in the OP should be updated. |
Well done on the super-meticulous work @mark-i-m. Glad we can finally get this feature stabilised! |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@mark-i-m Since you did the implementation work, could you prepare a PR for the stabilization as well? :) |
Sure, but it might be a few days before I can get to it |
@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? |
Yeah, I think I could do it by the end of the week. |
…lexcrichton Stabilize feature `macro_at_most_once_rep` a.k.a. `?` Kleene operator 🎉 cc rust-lang#48075 r? @Centril
#56245 has merged |
RFC: rust-lang/rfcs#2298
Status
?
macro repetition #47752)?
as a macro separator and Kleene op in 2018 edition #51934)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.The text was updated successfully, but these errors were encountered: