-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Fix closure migration suggestion when the body is a macro. #87956
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @Aaron1011 do you want to take this? |
// invocation, as the body is not contained inside the | ||
// closure span. In that case, we walk up the expansion | ||
// until we find the span before the expansion. | ||
while !closure_body_span.is_dummy() && !closure_span.contains(closure_body_span) { |
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.
If we end with a dummy span, then the overall diagnostic will end up worse than it currently is. Can you restore closure_body_span
to its original value if the loop ends up setting it to DUMMY_SP
?
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 kept the dummy span for the suggestion part. Otherwise .span_to_snippet
is going to return the wrong snippet and the suggestion will be wrong and confusing. The fallback span now uses the entire closure, which chas the highest chance of pointing to the place where modifications need to be made.
| in Rust 2018, closure captures all of `a`, but in Rust 2021, it only captures `a.0` | ||
... | ||
LL | } | ||
| - in Rust 2018, `a` would be dropped here, but in Rust 2021, only `a.0` would be dropped here alongside the closure |
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.
Pre-existing: I think saying 'as part as the closure' would make more sense than 'alongside the closure'.
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.
r=me, unless you want to change the note I mentioned in this PR as well. |
@bors r=Aaron1011 |
📌 Commit 26c590d has been approved by |
☀️ Test successful - checks-actions |
Fixes #87955
Before:
After: