Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition to E0582 explanation #124744

Open
OliverKillane opened this issue May 5, 2024 · 0 comments
Open

Addition to E0582 explanation #124744

OliverKillane opened this issue May 5, 2024 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@OliverKillane
Copy link
Contributor

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

@OliverKillane OliverKillane added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 5, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this issue May 14, 2024
…types-improvement, r=pnkfelix

`rustc --explain E0582` additional example

## Context
*From rust-lang#124744*

Expands the example for E0582, an error ensuring that lifetime in a function's return type is sufficiently constrained (e.g. actually tied to some input type), to show an additional example where one sees the lifetime occurring syntactically among the relevant function input types, but is nonetheless rejected by rustc because a syntactic occurrence is not always sufficient.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 5, 2024
…types-improvement, r=pnkfelix

`rustc --explain E0582` additional example

## Context
*From rust-lang#124744*

Expands the example for E0582, an error ensuring that lifetime in a function's return type is sufficiently constrained (e.g. actually tied to some input type), to show an additional example where one sees the lifetime occurring syntactically among the relevant function input types, but is nonetheless rejected by rustc because a syntactic occurrence is not always sufficient.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2024
Rollup merge of rust-lang#124746 - OliverKillane:E0582-explain-assoc-types-improvement, r=pnkfelix

`rustc --explain E0582` additional example

## Context
*From rust-lang#124744*

Expands the example for E0582, an error ensuring that lifetime in a function's return type is sufficiently constrained (e.g. actually tied to some input type), to show an additional example where one sees the lifetime occurring syntactically among the relevant function input types, but is nonetheless rejected by rustc because a syntactic occurrence is not always sufficient.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant