Skip to content
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

Closed
jonhoo opened this issue Jan 21, 2019 · 2 comments · Fixed by #68498
Closed

Compiler fails to unify existential associated type #57807

jonhoo opened this issue Jan 21, 2019 · 2 comments · Fixed by #68498
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-type-system Area: Type system F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@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
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
Copy link
Contributor Author

jonhoo commented Jan 21, 2019

I wonder whether this is a dupe of #53984 ?

@Centril Centril added A-type-system Area: Type system A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. labels Jan 22, 2019
@Centril Centril added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. labels Jul 28, 2019
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jan 25, 2020
…Centril

Add some type-alias-impl-trait regression tests

Fixes rust-lang#57611
Fixes rust-lang#57807
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 25, 2020
…Centril

Add some type-alias-impl-trait regression tests

Fixes rust-lang#57611
Fixes rust-lang#57807
@bors bors closed this as completed in 1605276 Jan 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-type-system Area: Type system F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way.
Development

Successfully merging a pull request may close this issue.

2 participants