-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
NLL: temps in block tail expression diagnostic #54782
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
@@ -91,8 +91,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { | |||
let source_info = this.source_info(span); | |||
for stmt in stmts { | |||
let Stmt { kind, opt_destruction_scope } = this.hir.mirror(stmt); | |||
let kind2 = kind.clone(); |
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.
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). |
/// expression is ignored by the block's expression context. | ||
/// | ||
/// Examples include `{ ...; tail };` and `let _ = { ...; tail };` | ||
/// but not e.g. `let _x = { ...; tail };` |
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.
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