Closed
Description
From https://www.reddit.com/r/rust/comments/bv90s7/temporary_value_dropped_while_borrowed/
We currently supply the following diagnostic:
let mut words = con.unwrap().split_whitespace().peekable();
^^^^^^^^^^^^ - temporary value is freed at the
| end of this statement
| |
| creates a temporary which is freed while still in use
|
| while words.peek().is_some() {
| ----- borrow later used here
|
= note: consider using a `let` binding to create a longer lived value
The note should be a structured suggestion that looks at the current line, figures out the indentation, finds the span for the beginning of the line and suggests adding a line above with a let
binding. This should make it clearer what we're suggesting. Additionally, it'd be nice if we could add either a succinct explanation or a link to the book with an explanation of what might be happening here.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.