-
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
Add suggestion to borrow Fn
and FnMut
params/opaque/closures instead of move
#95257
Conversation
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
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.
your change looks good to me, can you add a comment why this has to happen only if needs_note
is true? Or potentially even experiment with always adding this new suggestion?
fn report_use_of_moved_or_uninitialized
sure is a horrible function '^^ would be nice to extract all of this into separate functions. While I don't expect you to do that in this PR, can you move your new changes into a separate one?
ae0b69c
to
4d03058
Compare
Yeah, |
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 after the formatting fix for let chains
@bors delegate+
`needs_note` is false if we've already suggested why the type is Copy... but that has nothing to do with the diagnostic.
4d03058
to
ac95e80
Compare
I formatted the let chains with a patched rustfmt (rust-lang/rustfmt#5203), and also applied the let-else suggestions asked for. @bors r=lcnr |
📌 Commit ac95e80 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (abf0ec8): comparison url. Summary: This benchmark run did not return any relevant results. 5 results were found to be statistically significant but too small to be relevant. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
I think that Closure/ParamTy/Opaque are all "opaque" enough that it's meaningful to suggest borrowing them instead of moving them at their usage sites when we see a move error. See the attached issue for example.
Is this suggestion too general? I could perhaps use the move site information to limit this to places like fn calls, but I don't know enough about mir borrowck to know if that's an easy change.
Fixes #90828