Add suggestion to borrow Fn and FnMut params/opaque/closures instead of move#95257
Add suggestion to borrow Fn and FnMut params/opaque/closures instead of move#95257bors merged 3 commits intorust-lang:masterfrom
Fn and FnMut params/opaque/closures instead of move#95257Conversation
|
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
lcnr
left a comment
There was a problem hiding this comment.
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, |
`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