4lDO2/real-async-trait-rs

Multiple impl in one module do not compile

Closed this issue · 1 comments

If I have two implementations for async traits in one module, I get a compiler error:

error[E0428]: the name `__real_async_trait_impl` is defined multiple times
  --> src/lib.rs:22:1
   |
13 | #[real_async_trait]
   | ------------------- previous definition of the module `__real_async_trait_impl` here
...
22 | #[real_async_trait]
   | ^^^^^^^^^^^^^^^^^^^ `__real_async_trait_impl` redefined here
   |
   = note: `__real_async_trait_impl` must be defined only once in the type namespace of this module
   = note: this error originates in the attribute macro `real_async_trait` (in Nightly builds, run with -Z macro-backtrace for more info)

I used this code:

#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]

use real_async_trait::real_async_trait;

#[real_async_trait]
trait X {
    async fn nop<'a>(&'a self) -> ();
}

struct T {}

#[real_async_trait]
impl X for T {
    async fn nop<'a>(&'a self) -> () {
        ()
    }
}

struct T2 {}

#[real_async_trait]
impl X for T2 {
    async fn nop<'a>(&'a self) -> () {
        ()
    }
}

I used real-async-trait version 0.0.2 and rustc 1.57.0-nightly (485ced56b 2021-10-07).

The following workaround has been suggested to me:

const _: () = {
    #[real_async_trait]
    impl X for T2 {
        …
    }
};