Repository: rust
Issue: Confusing lifetime error with `'static` bound in `?` implicit `From`
Labels: A-diagnostics,T-compiler

A responce to [this tweet](https://twitter.com/ekuber/status/1373305373197623299) from @estebank 

Given the following code: ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=4a9dea98c22879421c6a46d8a1973772))

```rust
#[derive(Debug)]
struct StringErr<'a>(&'a str);
impl std::error::Error for StringErr<'_> {}
impl std::fmt::Display for StringErr<'_> {
    fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        Ok(())
    }
}

struct BoxError(Box<dyn std::error::Error + 'static>);
impl<E: std::error::Error + 'static> From<E> for BoxError {
    fn from(e: E) -> Self {
        Self(Box::new(e))
    }
}

fn parse<'a>(x: &'a str) -> Result<&'a str, StringErr<'a>> {
    Ok(x)
}

fn my_main() -> Result<(), BoxError> {
    let s = String::new();
    parse(&s)?;
    Ok(())
}

```

The current output is: (with `rustc +nightly foo.rs --crate-type lib`)

```
error[E0597]: `s` does not live long enough
  --> src/lib.rs:23:11
   |
23 |     parse(&s)?;
   |     ------^^-
   |     |     |
   |     |     borrowed value does not live long enough
   |     argument requires that `s` is borrowed for `'static`
24 |     Ok(())
25 | }
   | - `s` dropped here while still borrowed

error: aborting due to previous error
```

The problem is this is that it is super inclear why the `'static` bound is needed, as the arrows point to the `parse` function,
which does not require `'static`


Ideally the output should look like:

```
error[E0597]: `s` does not live long enough
  --> src/lib.rs:23:11
   |
23 |     parse(&s)?;
   |           ^^ ^
   |           |  |
   |           |  argument requires that `s` is borrowed for `'static`
   |           |
   |           borrowed value does not live long enough
24 |     Ok(())
25 | }
   | - `s` dropped here while still borrowed

Note: Required by the bound in the conversion from `StringErr` to `BoxError`
impl<E: std::error::Error + 'static> From<E> for BoxError {
                            ^^^^^^^
                            |

error: aborting due to previous error
```

Here we instead point to the `?` as the source of the `static` bound, and also point out that it exists in the conversion impl

This actualy came up when using `eyre`/`anyhow`, and a `lalrpop` parser that returns an error that references into the input string, but I've removed them to make the report self contained.

<!--
If the problem is not self-explanatory, please provide a rationale for the
change.
-->

<!--
If dramatically different output is caused by small changes, consider also
adding them here.

If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions. The output might also be
different depending on the Edition.
-->

```
rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-unknown-linux-gnu
release: 1.51.0
LLVM version: 11.0.1
```