rust-lang / rust-lang/rust

Addition to E0582 explanation

Open
#124,744 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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.

  • While 'a appears in the parameter for the associated type, there is no guarantee that an impl for the associated type actually uses the parameter, therefore 'a is not guaranteed to be used in the input for any impl Foo
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the E0582 entry used by rustc --explain E0582 and compare it with the reported associated-type example. Clarify whether the accepted scope is an explanation update or a diagnostic change; done means the explanation covers why the lifetime is not guaranteed and the relevant tests or documentation checks pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.