Closed
Description
This code [playground]
#![feature(generic_associated_types)]
trait Trait {
type Assoc<'a>;
fn with_assoc(f: impl FnOnce(Self::Assoc<'_>));
}
impl Trait for () {
type Assoc<'a> = i32;
fn with_assoc(f: impl FnOnce(Self::Assoc<'_>)) {
f(5i32)
}
}
produces these errors:
error[E0308]: mismatched types
--> src/lib.rs:13:7
|
10 | type Assoc<'a> = i32;
| --------------------- expected this associated type
...
13 | f(5i32)
| ^^^^ expected associated type, found `i32`
|
= note: expected associated type `<() as Trait>::Assoc<'_>`
found type `i32`
error[E0277]: expected a `FnOnce<(i32,)>` closure, found `impl FnOnce(Self::Assoc<'_>)`
--> src/lib.rs:13:5
|
13 | f(5i32)
| ^^^^^^^ expected an `FnOnce<(i32,)>` closure, found `impl FnOnce(Self::Assoc<'_>)`
|
help: consider further restricting this bound
|
12 | fn with_assoc(f: impl FnOnce(Self::Assoc<'_>) + std::ops::FnOnce<(i32,)>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
in 1.54.0-nightly (2021-05-27 1c6868a)
Note that you get one of these errors even if you allow Rust to infer the type by producing a value from thin air, implying that the compiler first infers that Assoc<'_>
is i32
, then complains that Assoc<'_>
and i32
are different.
Metadata
Metadata
Assignees
Labels
Area: Generic associated types (GATs)Area: Associated items (types, constants & functions)Area: Closures (`|…| { … }`)Category: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(generic_associated_types)]` a.k.a. GATsIssues using the `generic_associated_types` feature that have been triagedRelevant to the compiler team, which will review and decide on the PR/issue.