Skip to content

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

@netthier

Description

@netthier

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions