Repository: rust
Issue: argument requires that [...] is borrowed for [...]
Labels: A-diagnostics,T-compiler

Hi 👋.  I was instructed to create an issue here at a [users.rust-lang.org post](https://users.rust-lang.org/t/incomplete-lifetimes-error-message/80281).

Given the following code: [Rust Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=use+std%3A%3Async%3A%3AArc%3B%0Ause+tokio%3A%3Async%3A%3ARwLock%3B%0A%0Astruct+Context+%7B%0A++++field%3A+Arc%3CRwLock%3C%28%29%3E%3E%2C%0A%7D%0A%0Afn+blocking_fn%28_guard%3A+%26mut+tokio%3A%3Async%3A%3ARwLockWriteGuard%3C%28%29%3E%29+%7B%7D%0A%0Aasync+fn+async_fn%28ctx%3A+Context%29+%7B%0A++++let+mut+field_guard%3A+tokio%3A%3Async%3A%3ARwLockWriteGuard%3C_%3E+%3D+ctx.field.write%28%29.await%3B%0A++++tokio%3A%3Atask%3A%3Aspawn_blocking%28move+%7C%7C+blocking_fn%28%26mut+field_guard%29%29.await%3B%0A%7D%0A%0Afn+main%28%29+%7B%7D%0A) (the "Run" button seems to be broken ATM though)

```rust
use std::sync::Arc;
use tokio::sync::RwLock;

struct Context {
    field: Arc<RwLock<()>>,
}

fn blocking_fn(_guard: &mut tokio::sync::RwLockWriteGuard<()>) {}

async fn async_fn(ctx: Context) {
    let mut field_guard: tokio::sync::RwLockWriteGuard<_> = ctx.field.write().await;
    tokio::task::spawn_blocking(move || blocking_fn(&mut field_guard)).await;
}

fn main() {}
```

**The current output is:**

```
   Compiling playground v0.0.1 (/playground)
error[E0597]: `ctx.field` does not live long enough
  --> src/main.rs:12:65
   |
12 |         let mut field_guard: tokio::sync::RwLockWriteGuard<_> = ctx.field.write().await;
   |                                                                 ^^^^^^^^^^^^^^^^^------ argument requires that `ctx.field` is borrowed for `'static`
   |                                                                 |
   |                                                                 borrowed value does not live long enough
...
15 | }
   | - `ctx.field` dropped here while still borrowed

For more information about this error, try `rustc --explain E0597`.
error: could not compile `playground` due to previous error
```

What is meant by **"argument"** in the error message above?  Is it the implicit `self` parameter to `ctx.field.write()`?  Or is it the closure argument to `spawn_blocking()` below?  The error message is ambiguous on that IMO.  If it's the former, could we have `self` in the error message for clarity?

<!-- The following is not always necessary. -->
**Ideally the output should look like:**

If it's the `self`, then:
```
error[E0597]: `ctx.field` does not live long enough
  --> src/main.rs:12:65
   |
12 |         let mut field_guard: tokio::sync::RwLockWriteGuard<_> = ctx.field.write().await;
   |                                                                 ^^^^^^^^^^^^^^^^^------ argument `self` requires that `ctx.field` is borrowed for `'static`
   |                                                                 |
   |                                                                 borrowed value does not live long enough
...
15 | }
   | - `ctx.field` dropped here while still borrowed
```

If it's the argument to `spawn_blocking()`, then:

```
12 |         let mut field_guard: tokio::sync::RwLockWriteGuard<_> = ctx.field.write().await;
   |                                                                 ^^^^^^^^^^^^^^^^^------ `ctx.field` needs to be valid for `'static`
18 |     fn_taking_closure(move || blocking_fn(&mut field_guard));
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument is required to be valid for `'static`
```

<!--
If the problem is not self-explanatory, please provide a rationale for the
change.
-->

EDIT: Since creating the issue, I've learned of [three-point error messages](https://github.com/nikomatsakis/nll-rfc/blob/master/0000-nonlexical-lifetimes.md#leveraging-intuition-framing-errors-in-terms-of-points) and that causally-linked error messages is a subject of ongoing research ([1](https://ethz.ch/content/dam/ethz/special-interest/infk/chair-program-method/pm/documents/Education/Theses/David_Blaser_BA_Report.pdf) so I've removed the related portions of the issue)).