dtolnay / async-trait

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

Move bounds from generic param list to where-clause after 'async_trait bound #194

Closed dtolnay closed 2 years ago

dtolnay commented 2 years ago

I experimented with this as an alternative to #191. There are a few diagnostics that this still makes worse, but I think this one is an improvement often enough that I think it's worth trying.

Here is what it does to the expanded code from the ui test:

-  fn publish<'life0, 'async_trait, T: IntoUrl>(
+  fn publish<'life0, 'async_trait, T>(
       &'life0 self,
       url: T,
   ) -> ::core::pin::Pin<Box<dyn ::core::future::Future<Output = ()> + ::core::marker::Send + 'async_trait>>
   where
-      T: 'async_trait,
+      T: 'async_trait + IntoUrl,
       'life0: 'async_trait,
       Self: 'async_trait,
   {…}

Since we've inserted 'async_trait + at the beginning of the bounds list, instead of + 'async_trait at the end, when rustc goes to add more bounds they'll appear correctly after the last user-written bound in the source code.