Skip to content

Compiler fails to unify existential associated type #57807

Closed
@jonhoo

Description

@jonhoo

The following code fails to compile (playground):

#![feature(existential_type)]

trait Bar {
    type A;
}

impl Bar for () {
    type A = ();
}

trait Foo {
    type A;
    type B: Bar<A = Self::A>;
    
    fn foo() -> Self::B;
}

impl Foo for () {
    type A = ();
    existential type B: Bar<A = Self::A>;
    
    fn foo() -> Self::B {
        ()
    }
}

with the following error

error[E0271]: type mismatch resolving `<() as Bar>::A == <() as Foo>::A`
  --> src/lib.rs:20:5
   |
20 |     existential type B: Bar<A = Self::A>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found associated type
   |
   = note: expected type `()`
              found type `<() as Foo>::A`
   = note: the return type of a function must have a statically known size

If you make this modification, it compiles fine:

-    existential type B: Bar<A = Self::A>;
+    existential type B: Bar<A = ()>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-type-systemArea: Type systemF-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions