rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
93.58k stars 12.05k forks source link

Addition to E0582 explanation #124744

Open OliverKillane opened 1 week ago

OliverKillane commented 1 week ago

Code

trait Foo {
    type Assoc<'a>;
}

#[allow(dead_code)]
struct Bar<X, F>
where
    X: Foo,
    F: for<'a> Fn(X::Assoc<'a>) -> &'a i32
{
    x: X,
    f: F
}

Current output

error[E0582]: binding for associated type `Output` references lifetime `'a`, which does not appear in the trait input types
  --> src/lib.rs:23:42
   |
23 |         F: for<'a> Fn(X::Content<'a>) -> &'a i32
   |                                          ^^^^^^^

For more information about this error, try `rustc --explain E0582`.

Desired output

No response

Rationale and extra context

Problem

This error message could be more helpful.

Suggestion

  1. Either add extra explanation to the error when with regards to associated type usage (e.g. the above problem annotating the X::Assoc<'a> (requires time to implement
  2. Update the rustc --explain E0582 to include this example.
  3. No changes, skill issue

Other cases

No response

Rust Version

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2

Anything else?

No response