real-async-trait-rs icon indicating copy to clipboard operation
real-async-trait-rs copied to clipboard

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

Open netthier opened this issue 3 years ago • 0 comments

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 { } }
}

netthier avatar Sep 03 '22 17:09 netthier