-
Notifications
You must be signed in to change notification settings - Fork 13k
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
On irrefutable let pattern lint point only at pattern #81366
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
LL | / const X: usize = { | ||
LL | | let mut x = 0; | ||
LL | | while x != 1000 { | ||
| |_____^ | ||
LL | || | ||
LL | || x += 1; | ||
LL | || } | ||
| ||_____^ exceeded interpreter step limit (see `#[const_eval_limit]`) | ||
LL | | | ||
LL | | x | ||
LL | | }; | ||
| |__- | ||
LL | / const X: usize = { | ||
LL | | let mut x = 0; | ||
LL | | while x != 1000 { | ||
| | ^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`) | ||
LL | | | ||
... | | ||
LL | | x | ||
LL | | }; | ||
| |__- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a regression :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looked fine to me. The span got more precise, so that was good. The interpreter spans never were very good around the resource limits
src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr
Outdated
Show resolved
Hide resolved
src/test/ui/while-let.stderr
Outdated
LL | while let $p = $e $b | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| ^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spans involving macros are sometimes less than ideal :-/
Can you also do this for if-let guards? (Unless they do this already, I forget 😄) |
cd71894
to
b1fb8a7
Compare
I'll check, but I think those are handled elsewhere. Edit: for the Edit: Done. |
b1fb8a7
to
7a0fe2e
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
650104d
to
43118de
Compare
This comment has been minimized.
This comment has been minimized.
43118de
to
d9ccf87
Compare
This comment has been minimized.
This comment has been minimized.
d9ccf87
to
f2db885
Compare
This comment has been minimized.
This comment has been minimized.
f2db885
to
e01275e
Compare
☔ The latest upstream changes (presumably #81993) made this pull request unmergeable. Please resolve the merge conflicts. |
e01275e
to
dbf2f44
Compare
This comment has been minimized.
This comment has been minimized.
dbf2f44
to
07440ae
Compare
r? @oli-obk |
This comment has been minimized.
This comment has been minimized.
Add `Span` to let desugaring `MatchSource` variants to point only at the `let` pattern when linting against irrefutable patterns in `if let` and `while let`.
07440ae
to
b6aa7b1
Compare
Heads up, @rust-lang/clippy. Small changes incoming that would break clippy with fixes in the same PR. |
Seems fine, we have an easy sync process now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like I'm missing something fundamental. Where do the spans that encompass entire if let
or while let
expressions come from? To me it seems that you replaced a lot of (or only?) arm.pat.span
s with let_span
s, which has some regressions, but also some improvements in situations that seem indistinguishable (to me) from situations that were good before. So...
- Are there some
pat.span
s that refer to the entire match? - Do these point to the entire match only after
compute_match_usefulness
- Do these point to the entire match already during lowering?
I think we should first find out where these bad spans come from and if we can address them at the source instead of tracking additional spans.
diag.help("consider instead using a `loop { ... }` with a `let` inside it"); | ||
diag | ||
} | ||
hir::MatchSource::IfLetGuardDesugar { .. }=> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hir::MatchSource::IfLetGuardDesugar { .. }=> { | |
hir::MatchSource::IfLetGuardDesugar { .. } => { |
not sure why rustfmt didn't catch this
LL | while let Some(_y) = foo() { | ||
| ^^^^^^^^ | ||
| ^^^^^^^^^^^^^^^^^^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression. That refutable let binding is not a pattern, the previous span was pointing to a pattern.
☔ The latest upstream changes (presumably #82911) made this pull request unmergeable. Please resolve the merge conflicts. |
@estebank this is waiting for you to resolve conflicts + reply to the above review. Thanks |
Ping again from triage: |
This heavily collides with #80357 to a point where it has probably be redone once that is merged. |
Blocked on #80357 |
needs a rewrite, closing |
Add
Span
to let desugaringMatchSource
variants to point only atthe
let
pattern when linting against irrefutable patterns inif let
and
while let
.