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

Compiler fails to unify existential associated type #57807

Open
jonhoo opened this Issue Jan 21, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@jonhoo
Copy link
Contributor

jonhoo commented Jan 21, 2019

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 = ()>;
@jonhoo

This comment has been minimized.

Copy link
Contributor Author

jonhoo commented Jan 21, 2019

I think maybe cc @petrochenkov or @nikomatsakis ?

@jonhoo jonhoo changed the title Compiler fais to unify existential associated type Compiler fails to unify existential associated type Jan 21, 2019

@jonhoo

This comment has been minimized.

Copy link
Contributor Author

jonhoo commented Jan 21, 2019

I wonder whether this is a dupe of #53984 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment