dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

Support for impl Trait in associated type (type_alias_impl_trait) #152

Closed dtolnay closed 3 years ago

dtolnay commented 3 years ago

The following async trait fails to compile. This worked prior to #143.

#![feature(type_alias_impl_trait)]

use async_trait::async_trait;

#[async_trait]
trait Trait {
    type Assoc;

    async fn f(&self) -> Self::Assoc;
}

struct Struct;

#[async_trait]
impl Trait for Struct {
    type Assoc = impl Sized;

    async fn f(&self) -> Self::Assoc {}
}
error[E0308]: mismatched types
  --> src/main.rs:18:14
   |
16 |     type Assoc = impl Sized;
   |                  ---------- the expected opaque type
17 | 
18 |     async fn f(&self) -> Self::Assoc {}
   |              ^
   |              |
   |              expected opaque type, found `()`
   |              implicitly returns `()` as its body has no tail or `return` expression
   |
   = note: expected opaque type `impl Sized`
                found unit type `()`

error: could not find defining uses
  --> src/main.rs:16:18
   |
16 |     type Assoc = impl Sized;
   |                  ^^^^^^^^^^