-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT #11314
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
Merged
bors
merged 4 commits into
rust-lang:master
from
GuillaumeGomez:needless_ref_mut_async_block
Aug 17, 2023
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
42186af
Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT
GuillaumeGomez 1d01f1b
Update UI test for async blocks for NEEDLESS_PASS_BY_REF_MUT
GuillaumeGomez 7e46217
Add new regression test for `needless_pass_by_ref_mut`
GuillaumeGomez 5875bd2
Use `HirId` from `PlaceWithHirId` rather than using the one provided …
GuillaumeGomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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'm curious how stable
diag_expr_id
is. Is it free to change at any time if, perhaps, only highlighting the arguments of the closure is deemed better? Because using this to determine if it's from a closure feels a bit error-prone.Maybe we need another parameter that's the borrower's
HirId
, or consumer, etc.If it is ok, then the wording in
consume
should probably be updated in rustc since it's likely interpreted as theHirId
for getting spans/the id for linting, not analysis.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.
Sorry I'm a bit lost: what is
diag_expr_id
here? What's the connection withconsume
too?In this case,
async
blocks generate a closure and anExpr
containing a call to aclosure
which has aDefId
and that's what I retrieve with this code. If this is changed in the compiler, the UI test will catch it.Uh oh!
There was an error while loading. Please reload this page.
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.
diag_expr_id
i.e.,id
. That's the default name for it.Its intended use is clarified in
Delegate::consume
's docs, from what I can tell it's not supposed to be used for analysis.That's true, but it'll be annoying for whoever wants to. If this is only supposed to be used pointing at something in diagnostics, then we probably shouldn't use it for this (at least, once we have an alternative). It would be reasonable for it to be changed, since if my assumption is true then code isn't supposed to depend on this (turning what would be a couple line change into adding a stable
HirId
you can use.)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.
Oh ok I see. In this case, it's all generated by the compiler (it doesn't exist in user code). The case of
async block
seems to be special if you look at ExprKind::Closure. So what do you want to do in this case?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's probably fine as is, but once we can we should change it. For now however, we could change this to
cmt.hir_id
which would convey this better (diag_expr_id
is currently alwayscmt.hir_id
forborrow
) ascmt
(place_with_id
) is usually where the binding was introduced I believe (in this case, the closure, though it would realistically be the parameters'HirId
)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.
That makes perfect sense, thanks for the detailed explanation!