Closed
Description
This code:
fn main() {}
async fn func<'a>() -> Result<(), &'a str> {
let s = String::new();
let b = &s[..];
Err(b)?;
Ok(())
}
Returns this error:
error[E0597]: `s` does not live long enough
--> src/main.rs:6:14
|
6 | let b = &s[..];
| ^ borrowed value does not live long enough
...
11 | }
| - `s` dropped here while still borrowed
Which is very unhelpful; it should at least in some way point to the line with the ?
. This happens on rustc 1.40.0 (73528e3 2019-12-16).
For reference, this is the equivalent non-async error message (much more helpful):
error[E0515]: cannot return value referencing local variable `s`
--> src/main.rs:8:11
|
6 | let b = &s[..];
| - `s` is borrowed here
7 |
8 | Err(b)?;
| ^ returns a value referencing data owned by the current function
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: Messages for errors, warnings, and lintsAsync-await issues that are part of the "polish" areaAsync-await issues that have been triaged during a working group meeting.Category: An issue proposing an enhancement or a PR with one.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done
Activity
Aaron1011 commentedon Jan 5, 2020
@rustbot claim
Account for 'duplicate' closure regions in borrowck diagnostics
tmandry commentedon Jan 7, 2020
Marking as focus, since improving diagnostics are important to the wg.
Use an 'approximate' universal upper bound when reporting region errors
Rollup merge of rust-lang#73806 - Aaron1011:feature/approx-universal-…
8 remaining items