4lDO2 / real-async-trait-rs

A proc macro for real async traits, using nightly-only existential types and generic associated types to work around the need for type erasure
Apache License 2.0
45 stars 3 forks source link

type parameter is part of concrete type but not used in parameter list for the `impl Trait` type alias #8

Open netthier opened 2 years ago

netthier commented 2 years ago

It seems like the macro doesn't support implementing traits for structs with generic parameters like:

trait Foo {}
struct Bar<F: Foo> { f: F }

#[real_async_trait]
trait Bat {
    async fn baz();
}

#[real_async_trait]
impl<F: Foo> Bat for Bar<F> {
    async fn baz() { }
}

Compilation fails with the error

error: type parameter `F` is part of concrete type but not used in parameter list for the `impl Trait` type alias
  --> src/main.rs:13:1
   |
13 | #[real_async_trait]
   | ^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `real_async_trait` (in Nightly builds, run with -Z macro-backtrace for more info)

Manually typing out the async trait definition and implementation works:

trait Foo {}
struct Bar<F: Foo> { f: F }

trait Bat {
    type BazFuture<'a>: Future<Output = ()>;
    fn baz<'a>() -> Self::BazFuture<'a>;
}

impl<F: Foo> Bat for Bar<F> {
    type BazFuture<'a> = impl Future<Output = ()>;
    fn baz<'a>() -> Self::BazFuture<'a> { async move { } }
}