Skip to content

Rustc can't infer GAT type when used as argument to Fn closure outside of trait #88459

Closed
@geom3trik

Description

@geom3trik

I tried this code:

playgorund

#![feature(generic_associated_types)]

trait Trait {
    type Assoc<'a>;
}

fn f<T: Trait>(_: T, _: impl Fn(T::Assoc<'_>)) {}

struct Type;

impl Trait for Type {
    type Assoc<'a> = ();
}

fn main() {
    f(Type, |_|());
}

I expected to see this happen: compiles with no errors.

Instead, this happened:

error[E0631]: type mismatch in closure arguments
  --> src/main.rs:16:5
   |
16 |     f(Type, |_|());
   |     ^       ----- found signature of `fn(()) -> _`
   |     |
   |     expected signature of `for<'r> fn(<Type as Trait>::Assoc<'r>) -> _`
   |
note: required by a bound in `f`
  --> src/main.rs:7:30
   |
7  | fn f<T: Trait>(_: T, _: impl Fn(T::Assoc<'_>)) {}
   |                              ^^^^^^^^^^^^^^^^ required by this bound in `f`

The error seems to suggest that rustc can't figure out that the associated type is () which should satisfy the bound in f.

Meta

1.56.0-nightly ( 5eacec9 )

This could be related to #85921, but unlike that issue this one does not seem to be fixed on latest nightly.

Activity

b-naber

b-naber commented on Aug 30, 2021

@b-naber
Contributor

This seems related to #88382

jackh726

jackh726 commented on Oct 20, 2021

@jackh726
Member

GATs issue triage: not blocking. Not really a GATs issue, but there's a PR open that will fix this regardless.

added
GATs-triagedIssues using the `generic_associated_types` feature that have been triaged
on Oct 20, 2021
added a commit that references this issue on Nov 6, 2021

Auto merge of rust-lang#88441 - jackh726:closure_norm, r=nikomatsakis

18cae26
added
A-GATsArea: Generic associated types (GATs)
on Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)C-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsGATs-triagedIssues using the `generic_associated_types` feature that have been triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jonas-schievink@geom3trik@fmease@jackh726@b-naber

      Issue actions

        Rustc can't infer GAT type when used as argument to Fn closure outside of trait · Issue #88459 · rust-lang/rust