dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.84k stars 85 forks source link

Poor error message when argument types mismatch #246

Closed msrd0 closed 1 year ago

msrd0 commented 1 year ago

I forgot to take a reference to a parameter, example (Playground):

use async_trait::async_trait; // 0.1.68

#[async_trait]
trait MyTrait {
    async fn foo<T: Send>(
        &self, s: &String, t: T
    );
}

struct MyType;

#[async_trait]
impl MyTrait for MyType {
    async fn foo<T: Send>(
        &self, s: String, t: T
    ) {}
}

This results in the following error message, which doesn't explain the problem at all:

error[E0195]: lifetime parameters or bounds on method `foo` do not match the trait declaration
  --> src/lib.rs:14:17
   |
5  |     async fn foo<T: Send>(
   |                 --------- lifetimes in impl do not match this method in trait
...
14 |     async fn foo<T: Send>(
   |                 ^^^^^^^^^ lifetimes do not match method in trait

For more information about this error, try `rustc --explain E0195`.
error: could not compile `playground` due to previous error
dtolnay commented 1 year ago

I don't think this is actionable in this crate.