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

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

Closed
geom3trik opened this issue Aug 29, 2021 · 2 comments · Fixed by #88441
Closed

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

geom3trik opened this issue Aug 29, 2021 · 2 comments · Fixed by #88441
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs GATs-triaged Issues using the `generic_associated_types` feature that have been triaged

Comments

@geom3trik
Copy link

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.

@geom3trik geom3trik added the C-bug Category: This is a bug. label Aug 29, 2021
@jonas-schievink jonas-schievink added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Aug 29, 2021
@b-naber
Copy link
Contributor

b-naber commented Aug 30, 2021

This seems related to #88382

@jackh726
Copy link
Member

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

@jackh726 jackh726 added the GATs-triaged Issues using the `generic_associated_types` feature that have been triaged label Oct 20, 2021
@bors bors closed this as completed in 18cae26 Nov 6, 2021
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs GATs-triaged Issues using the `generic_associated_types` feature that have been triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants