NLL: temps in block tail expression diagnostic#54782
Conversation
|
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc_mir/build/block.rs
Outdated
There was a problem hiding this comment.
oops this binding of kind2 (and associated clone) wasn't supposed to be part of the PR. Will fix.
57b9ad5 to
eb37f5f
Compare
|
I just realized that I included the updates to the existing tests but forgot to include the unit tests I made specifically for this. I'll add a commit with them onto the end of this after I sanity-check their output (very soon). |
src/librustc/mir/mod.rs
Outdated
There was a problem hiding this comment.
Might be nice to explain briefly what this is used for
|
@bors r+ So from a technical perspective, I feel good about this. I'm not sure 100% about the wording but it seems like a solid improvement from what we had. Perhaps we can iterate after landing. |
|
📌 Commit 3b17f1bfe38f6257ea12c7d5e5d236ffcf70615a has been approved by |
|
☔ The latest upstream changes (presumably #54666) made this pull request unmergeable. Please resolve the merge conflicts. |
…bexpr a block tail expression. Slightly refactored the `LocalDecl` construction API in the process.
…lanation_to_diagnostic`. (I found it confusing to have calls to an `emit` method in our error_reporting module where that `emit` method *wasn't* the `DiagnosticBuffer::emit` method.)
This is preparation for allowing the `BorrowExplanation` carry things like `mir::Location` or `mir::Local` and still be able to generate usable diagnostic text.
… temporary r-values. Changed `BorrowExplanation::UsedLaterWhenDropped` to handle both named locals and also unnamed (aka temporaries). If the dropped temporary does not implement `Drop`, then we print its full type; but when the dropped temporary is itself an ADT `D` that implements `Drop`, then diagnostic points the user directly at `D`.
3b17f1b to
056cfff
Compare
|
@bors r=nikomatsakis |
|
📌 Commit 704877f has been approved by |
|
⌛ Testing commit 704877f with merge ec3d08835a74038c0f549035b37d8b7ec6f42a99... |
|
💔 Test failed - status-travis |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
@bors retry |
…r=nikomatsakis NLL: temps in block tail expression diagnostic This change adds a diagnostic that explains when temporaries in a block tail expression live longer than block local variables that they borrow, and attempts to suggest turning the tail expresion into a statement (either by adding a semicolon at the end, when its result value is clearly unused, or by introducing a `let`-binding for the result value and then returning that). Fix #54556
|
☀️ Test successful - status-appveyor, status-travis |
This change adds a diagnostic that explains when temporaries in a block tail expression live longer than block local variables that they borrow, and attempts to suggest turning the tail expresion into a statement (either by adding a semicolon at the end, when its result value is clearly unused, or by introducing a
let-binding for the result value and then returning that).Fix #54556