dtolnay / async-trait

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

Macro-expanded usages of `Box` should use the fully-qualified path #271

Closed shepmaster closed 2 months ago

shepmaster commented 2 months ago

It turns out that some crate decided to create a type called Box... ooof.

struct Box;

#[async_trait::async_trait]
trait Demo {
    async fn oops(&self);
}

#[async_trait::async_trait]
impl Demo for () {
    async fn oops(&self) {}
}
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
 --> src/lib.rs:3:1
  |
3 | #[async_trait::async_trait]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: remove these generics
  | |
  | expected 0 generic arguments
  |
note: struct defined here, with 0 generic parameters
 --> src/lib.rs:1:8
  |
1 | struct Box;
  |        ^^^
  = note: this error originates in the attribute macro `async_trait::async_trait` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
 --> src/lib.rs:8:1
  |
8 | #[async_trait::async_trait]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: remove these generics
  | |
  | expected 0 generic arguments
  |
note: struct defined here, with 0 generic parameters
 --> src/lib.rs:1:8
  |
1 | struct Box;
  |        ^^^
  = note: this error originates in the attribute macro `async_trait::async_trait` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no function or associated item named `pin` found for struct `Box` in the current scope
  --> src/lib.rs:10:26
   |
1  | struct Box;
   | ---------- function or associated item `pin` not found for this struct
...
10 |     async fn oops(&self) {}
   |                          ^^ function or associated item not found in `Box`
taiki-e commented 2 months ago

Duplicate of https://github.com/dtolnay/async-trait/issues/132, https://github.com/dtolnay/async-trait/issues/163, https://github.com/dtolnay/async-trait/issues/214.

shepmaster commented 2 months ago

Fair enough. I searched for the error messages before opening this issue, but didn't think to search for related terms.