Skip to content

FnOnce with GAT argument with HRTB is misinterpreted by the type system #107572

Open
@Eliah-Lakhin

Description

@Eliah-Lakhin

I tried this code:

trait GAT {
    type Assoc<'a>;
}

fn foo<A: GAT>(
    f: impl for<'a> FnOnce(<A as GAT>::Assoc<'a>) -> <A as GAT>::Assoc<'a>,
) {}

And it fails to compile:

error[[E0582]](https://doc.rust-lang.org/stable/error-index.html#E0582): binding for associated type `Output` references lifetime `'a`, which does not appear in the trait input types
 --> src/lib.rs:7:54
  |
7 |     f: impl for<'a> FnOnce(<A as GAT>::Assoc<'a>) -> <A as GAT>::Assoc<'a>,
  |                                                      ^^^^^^^^^^^^^^^^^^^^^

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

Even if it's not a bug, but the current type system limitations, the error description E0582 seems to be misleading(or is not well descriptive).

Meta

Checked with rustc:

  • 1.67.0
  • 1.68.0-beta.1
  • 2023-01-30 001a77f

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-lifetimesArea: Lifetimes / regionsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions