Repository: rust
Issue: confusing "borrowed data escapes outside of closure/function" with nll
Labels: A-diagnostics,T-compiler,D-confusing

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.

If you cannot produce a minimal reproduction case (something that would work in
isolation), please provide the steps or even link to a repository that causes
the problematic output to occur.
-->

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f1da9fd81d99e0b07d5bd390b7133b84 <!-- Please provide a link to play.rust-lang.org -->

```rust
#![feature(ptr_metadata)]
use std::ptr::metadata;
trait Tr<'a> {}
fn f<'a>(r1: &mut dyn Tr<'a>) {
    |r2: &mut dyn Tr<'_>| metadata(r1) == metadata(r2);
}
```

The current output is:

```
error[[E0521]](https://doc.rust-lang.org/nightly/error-index.html#E0521): borrowed data escapes outside of closure
 --> src/lib.rs:5:27
  |
4 | fn f<'a>(r1: &mut dyn Tr<'a>) {
  |          -- `r1` declared here, outside of the closure body
5 |     |r2: &mut dyn Tr<'_>| metadata(r1) == metadata(r2);
  |      --                   ^^^^^^^^^^^^ `r2` escapes the closure body here
  |      |
  |      `r2` is a reference that is only valid in the closure body

error[[E0521]](https://doc.rust-lang.org/nightly/error-index.html#E0521): borrowed data escapes outside of function
 --> src/lib.rs:5:27
  |
4 | fn f<'a>(r1: &mut dyn Tr<'a>) {
  |      --  -- `r1` is a reference that is only valid in the function body
  |      |
  |      lifetime `'a` defined here
5 |     |r2: &mut dyn Tr<'_>| metadata(r1) == metadata(r2);
  |                           ^^^^^^^^^^^^
  |                           |
  |                           `r1` escapes the function body here
  |                           argument requires that `'a` must outlive `'static`
```

I think this is very confusing because nothing is "escaping" from anywhere here, neither from the closure (it just returns bool! nothing is going anywhere!) not from the enclosing function (it doesn't even _do_ anything).

Before nll, the error used to look like (arbitrarily my previously installed nightly-2022-04-14, if you add `#![feature(nll)]` you get the above output again):

```
error[E0308]: mismatched types
 --> src/lib.rs:5:43
  |
5 |     |r2: &mut dyn Tr<'_>| metadata(r1) == metadata(r2);
  |                                           ^^^^^^^^^^^^ lifetime mismatch
  |
  = note: expected struct `DynMetadata<dyn Tr<'a>>`
             found struct `DynMetadata<dyn Tr<'_>>`
note: the anonymous lifetime #2 defined here...
 --> src/lib.rs:5:5
  |
5 |     |r2: &mut dyn Tr<'_>| metadata(r1) == metadata(r2);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...does not necessarily outlive the lifetime `'a` as defined here
 --> src/lib.rs:4:6
  |
4 | fn f<'a>(r1: &mut dyn Tr<'a>) {
  |      ^^

error[E0308]: mismatched types
 --> src/lib.rs:5:43
  |
5 |     |r2: &mut dyn Tr<'_>| metadata(r1) == metadata(r2);
  |                                           ^^^^^^^^^^^^ lifetime mismatch
  |
  = note: expected struct `DynMetadata<dyn Tr<'a>>`
             found struct `DynMetadata<dyn Tr<'_>>`
note: the lifetime `'a` as defined here...
 --> src/lib.rs:4:6
  |
4 | fn f<'a>(r1: &mut dyn Tr<'a>) {
  |      ^^
note: ...does not necessarily outlive the anonymous lifetime #2 defined here
 --> src/lib.rs:5:5
  |
5 |     |r2: &mut dyn Tr<'_>| metadata(r1) == metadata(r2);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

I found that a lot more immediately clear.

I'm sure this can be minimized to avoid `ptr_metadata` but I'm already super confused as-is and can't really wrap my head around how all the metadata stuff is defined right now.