dtolnay / async-trait

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

Want way to detect recursive impls #247

Closed ijackson closed 1 year ago

ijackson commented 1 year ago

Hi. Coincidentally, we had an accidentally-always-recursive async fn impl in a trait, leading to stack overflow (https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1197), and I just read about someone else who had the same problem (https://github.com/juspay/hyperswitch/wiki/Ask-not-what-the-compiler-can-do-for-you).

I think it might be possible to detect this situation, using the following technique: move the body of the trait method implementation into a separate inherent method (with a derived name, and returning impl Future or just being async, and then have the trait method call it.

But, this might make the error messages worse in other cases. I thought I would suggest it for your consideration. Thanks!

dtolnay commented 1 year ago

Your suggestion used to be how async_trait was implemented prior to #143 and there were serious downsides with that.

ijackson commented 1 year ago

Your suggestion used to be how async_trait was implemented prior to #143 and there were serious downsides with that.

Oh dear. Thanks for the reply and sorry for the noise.