Repository: rust
Issue: show reason why bound is nessesary
Labels: A-diagnostics,T-compiler,D-terse

### Code

```Rust
struct TypedFunction<'gc, I, O> {
    f: &'gc i32,
    _phantom: std::marker::PhantomData<fn(I) -> O>,
}
#[derive(Clone, Copy)]
struct Context<'gc> {
    f: &'gc i32,
}
pub trait UserDataMethodsCollector<'gc, X> {}
pub trait UserData<'gc> {
    fn add_methods<Collector: UserDataMethodsCollector<'gc, Self>>(
        collector: Collector,
    ) -> Collector
    where
        Self: Sized;
}


pub struct RuntimeCollector<'gc> {
    context: Context<'gc>,
}

impl<'gc> RuntimeCollector<'gc> {
    pub fn finalize<X: UserData<'gc> + 'gc>(ctx: Context<'gc>, _value: X) {
        let this = Self {
            context: ctx
        };
        //this line ends up causing the error
        let _this = X::add_methods(this);
    }
}

//because of the bound here. Would be nice if that got shown in the error message
impl<'gc, X: UserData<'gc> + 'static> UserDataMethodsCollector<'gc, X> for RuntimeCollector<'gc> {}
```


### Current output

```Shell
error[E0310]: the parameter type `X` may not live long enough
  --> src/lib.rs:29:21
   |
29 |         let _this = X::add_methods(this);
   |                     ^^^^^^^^^^^^^^
   |                     |
   |                     the parameter type `X` must be valid for the static lifetime...
   |                     ...so that the type `X` will meet its required lifetime bounds
   |
help: consider adding an explicit lifetime bound
   |
24 |     pub fn finalize<X: UserData<'gc> + 'gc + 'static>(ctx: Context<'gc>, _value: X) {
   |                                            +++++++++

For more information about this error, try `rustc --explain E0310`.
error: could not compile `playground` (lib) due to 1 previous error
```


### Desired output

```Shell
error[E0310]: the parameter type `X` may not live long enough
  --> src/lib.rs:29:21
   |
29 |         let _this = X::add_methods(this);
   |                     ^^^^^^^^^^^^^^
   |                     |
   |                     the parameter type `X` must be valid for the static lifetime...
   |                     ...so that the type `X` will meet its required lifetime bounds
   |

because of `'static` bound here
   |
34 | impl<'gc, X: UserData<'gc> + 'static> UserDataMethodsCollector<'gc, X> for RuntimeCollector<'gc> {}
   |
help: consider adding an explicit lifetime bound
   |
24 |     pub fn finalize<X: UserData<'gc> + 'gc + 'static>(ctx: Context<'gc>, _value: X) {
   |                                            +++++++++


For more information about this error, try `rustc --explain E0310`.
error: could not compile `playground` (lib) due to 1 previous error
```


### Rationale and extra context

It is sometimes hard to track down where a lifetime requirement comes from. Adding a line that points in the right direction would help track it down.

### Other cases

_No response_

### Rust Version

```Shell
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7
```


### Anything else?

playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d8fc4728e68d1f4e7e504543d536db50