Repository: rust
Issue: Error messages sometimes incorrectly elide `dyn Trait` lifetimes when `dyn Trait` is behind an alias
Labels: A-diagnostics,T-compiler

There's probably a better description but I couldn't think of a short one, sorry.  But the basic setup is that you can have a situation such as:
```rust
type Alias = dyn Trait;
/* ... */ where for<'a> &'a Alias: Bound, /* ... */
```
And rustc will expand this to `&'a (dyn Trait + 'static)`, as the lifetime elision does not penetrate the alias.  But error reporting will report this as `&'a dyn Trait` after normalizing the alias, and this is short for `&'a (dyn Trait + 'a)`.  This happens even when the alias is implicit, e.g., `Self`.

[Examples:](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=13c78dfbe94073e3915628dad3c3a523)
```rust
fn f() {
    trait Marker<'a> {}
    trait Trait where for<'a> &'a Self: Marker<'a> {
        fn usable(&self) {}
    }

    impl<'a> Marker<'a> for &'a () {}
    impl Trait for () {}

    let t: &dyn Trait = &();
    t.usable();
    // error[E0277]: the trait bound `for<'a> &'a dyn Trait: Marker<'a>` is not satisfied
}
```
The actual problem is that `for<'a> &'a (dyn Trait + 'static): Marker<'a>` is not satisfied.  But following the error as reported:

```rust
fn g() {
    trait Marker<'a> {}
    trait Trait where for<'a> &'a Self: Marker<'a> { fn usable(&self) {} }
    impl<'a> Marker<'a> for &'a () {}
    impl Trait for () {}
    let t: &dyn Trait = &();

    impl<'a> Marker<'a> for &'a (dyn Trait /* + 'a */) {}
    t.usable();
    //   |       ^^^^^^ implementation of `g::Marker` is not general enough
    //   |
    //   = note: `g::Marker<'0>` would have to be implemented for the type `&'0 dyn g::Trait`, for any lifetime `'0`...
    //   = note: ...but `g::Marker<'_>` is actually implemented for the type `&'1 (dyn g::Trait + '1)`, for some specific lifetime `'1`
}
```
The first note is counter-factual; we did implement for the type `&'0 dyn g::Trait`, for any lifetime `'0`.  The thing we didn't implement is `&'0 (dyn g::Trait + 'static)`, for any lifetime `'0`.

The second note is inaccurate; we have a blanket implementation, not a specific lifetime implementation.

And a variation involving an associated type:
```rust
fn i() {
    trait Trait where for<'a> &'a Self: IntoIterator<Item=&'a ()> { fn usable(&self) {} }
    impl Trait for Vec<()> {}

    let v = vec![()];
    v.usable();
    let t: &dyn Trait = &v;
    
    impl<'a> IntoIterator for &'a dyn Trait {
        type Item = &'a ();
        type IntoIter = std::slice::Iter<'a, ()>;
        fn into_iter(self) -> Self::IntoIter {
            (&[]).into_iter()
        }
    }

    t.usable();
    //    |       ^^^^^^ the trait `for<'a> IntoIterator` is not implemented for `&'a dyn i::Trait`
    //    |
    //    = help: the following implementations were found:
    //              <&'a (dyn i::Trait + 'a) as IntoIterator>
}
```
The `^^^^^` note is incorrect, and contradicted by the help that follows.

Ideally the output should look like:
```
     error[E0277]: the trait bound `for<'a> &'a (dyn Trait + 'static): Marker<'a>` is not satisfied
```
```
       |       ^^^^^^ implementation of `g::Marker` is not general enough
       |
       = note: `g::Marker<'0>` would have to be implemented for the type `&'0 (dyn g::Trait + 'static)`, for any lifetime `'0`...
       = note: ...but `g::Marker<'_>` is actually implemented for the type `&'1 (dyn g::Trait + '1)`, for any lifetime `'1`
```
```
        |       ^^^^^^ the trait `for<'a> IntoIterator` is not implemented for `&'a (dyn i::Trait + 'static)`
        |
        = help: the following implementations were found:
                  <&'a (dyn i::Trait + 'a) as IntoIterator>
```