dtolnay / async-trait

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

Clippy lint `async_returns_async` fails if you return an awaitable type #236

Closed danya02 closed 1 year ago

danya02 commented 1 year ago

I was making an API that returns a tokio::sync::oneshot::Receiver from an async function when I noticed that the clippy::async_returns_async lint doesn't like me doing this. Originally I thought that this is in fact a poor API design choice, but this doesn't happen in normal async fns. It turns out that this lint error comes from the async_trait macro's expansion.

Here's my code example. The error ultimately comes from the fact that the function's code gets wrapped in an async move block, which according to Clippy shouldn't be returning a future.

I think just putting a #[allow(clippy::async_yields_async)] on the generated function should be sufficient to deal with this.