-
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
Lint on incorrect unseparated repetition #55373
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
@bors try |
⌛ Trying commit 5c5fca01e7afa4060e1d5910dc259db470afb4ed with merge a7b077cffd907eec053b7d79dbe723dd94548c08... |
This comment has been minimized.
This comment has been minimized.
cc @nikomatsakis @durka @joshtriplett
This will need a crater run to see how much this would break. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7139c6b
to
2915cc7
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@nikomatsakis I fully expect this change to wreak havoc. I wouldn't want to make it a lint because the logic to accomplish that would be much more involved than this change. Is it ok for us to start generating an unsilenceable warning all of a sudden? |
This comment has been minimized.
This comment has been minimized.
cc @kennytm |
@dtolnay added deprecation message, changed to allow by default and rebased. |
This comment has been minimized.
This comment has been minimized.
Sigh, the following token restrictions exist to prevent breakage from extending Rust syntax, but this change alone breaks more code than syntax extensions ever did. |
It looks like the warning may be reported both at definition crate (when the macro is defined) and at use crate when the macro is loaded? |
Also a test making sure that |
Otherwise LGTM. |
We discussed this in the lang team meeting today. Overall, we're uncertain that this is worth the churn it will cause. The point of these restrictions is to avoid a lot of breakage when we do extend the expression syntax: are we just frontloading that breakage by adopting this change, defeating the point of the restriction in the first place? Contrarily, one could argue that if we do ever extend expressions in the future, after Rust's adoption has continued to grow, we might end up breaking a lot more people than this lint will cause problems for. But overall we were uncertain, so we're throwing it back to the people invested in the PR: this change is definitely correct, but is it worth the breakage to become more correct? Why or why not? |
This is exactly the camp where I would fall on. Getting a lint in at the earliest possible moment, even if it is disabled by default for several releases and warn only until the next edition makes it much more likely that breaking this in 2021 will be possible.
I feel that merging as an allow by default lint is the clear right choice. That way projects that care about it can enable it selectively or opt out of it completely (indefinitely). After that we can work with crates to move away from exploiting this loophole. I don't think this lint should be deny-by-default unless it is part of a new edition. Alternatively, we could explicitly allow some particular use cases, like repeated bare |
☔ The latest upstream changes (presumably #56203) made this pull request unmergeable. Please resolve the merge conflicts. |
Triage; @estebank Hello, have you been able to get back to this PR? |
@Aaronepower I'll clean this up this weekend. |
Ping from triage @estebank: What is the status of this PR? |
@TimNN I have bene quite busy and unable to get back to this, but will try to do so soonish. If you wish to close in the meantime, go ahead and I'll reopen once I'm ready.
Does anyone have thoughts on this point? |
Thank you for your understanding and contributions! |
Macro pattern
($a:expr $b:expr)
is invalid, for good reason.Correctly reject pattern
($($a:expr)*)
, as it is functionally thesame.
This PR adds a warn by default lint that checks for any repeatable
pattern that would be rejected by the parser if it had been written
as independent arguments:
expr
andstmt
variables may only be followed by one of:=>
,
;
ty
andpath
variables may only be followed by one of:=>
,
=
|
;
:
>
[
{
as
where
pat
variables may only be followed by one of:=>
,
=
|
if
in
Fix #44975, fix #48220.