Closed
Description
I tried this code:
#![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.