-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)Area: Lazy normalization (tracking issue: #60471)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
The compiler seems unable to determine that two types are equal.
I tried this code:
trait Factory {
type Product;
}
impl Factory for () {
type Product = ();
}
trait ProductConsumer<P> {
fn consume(self, product: P);
}
impl <P> ProductConsumer<P> for () {
fn consume(self, product: P) {}
}
fn make_product_consumer<F: Factory>(f: F) -> impl ProductConsumer<F::Product> {
()
}
fn main() {
let consumer = make_product_consumer(());
consumer.consume(());
}
I expected the program to compile and run without issue, because <() as Factory>::Product>
is ()
, so the consume
call should be fine.
Instead, I got this error message:
error[E0308]: mismatched types
--> src/main.rs:25:22
|
25 | consumer.consume(());
| ^^ expected associated type, found `()`
|
= note: expected associated type `<() as Factory>::Product`
found unit type `()`
The problem exists on stable 1.42 and nightly 1.44
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)Area: Lazy normalization (tracking issue: #60471)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.