Skip to content

Unhelpful error messages from borrow checker with async/await #67765

Closed
@Kestrer

Description

@Kestrer
Contributor

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

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Dec 31, 2019
Aaron1011

Aaron1011 commented on Jan 5, 2020

@Aaron1011
Member

@rustbot claim

added a commit that references this issue on Jan 6, 2020
ced109f
added
AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.
AsyncAwait-PolishAsync-await issues that are part of the "polish" area
on Jan 7, 2020
tmandry

tmandry commented on Jan 7, 2020

@tmandry
Member

Marking as focus, since improving diagnostics are important to the wg.

added a commit that references this issue on Jun 27, 2020
517d361
added a commit that references this issue on Jun 29, 2020

Rollup merge of rust-lang#73806 - Aaron1011:feature/approx-universal-…

2fef102

8 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

    Participants

    @Centril@Aaron1011@jonas-schievink@tmandry@Kestrer

    Issue actions

      Unhelpful error messages from borrow checker with async/await · Issue #67765 · rust-lang/rust