You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This, of course, does not match the generated trait definition which has only a single lifetime generic in f. The "correct" implementation would look like:
This, of course, would require async-trait to know that the placeholdered generic lifetime in the trait corresponds to the elided lifetime in the implementation. In general, it's clear that async-trait can't do this as it doesn't have type information nor access to the AST of the definition.
I believe that async-trait should likely error when trait generics are placeholdered. At least then the user gets a nice error message as opposed to incorrect code being generated.
The text was updated successfully, but these errors were encountered:
This, of course, would require async-trait to know that the placeholdered generic lifetime in the trait corresponds to the elided lifetime in the implementation.
Note that rustc for ordinary traits does nothing like this either. Instead, the reason why the analogous situation compiles successfully for ordinary traits is merely because the following code compiles, too:
simply desugars to something like the impl in the first code block, not to an implementation where 'b and 'a are restricted to be the same; but the compiler doesn’t complain if a trait impl’s method is slightly more generic than necessary.
Of course, the suggested improvement of adding some errors still seems potentially reasonable. It should almost always be the case that a trait Foo<'a>actually uses the lifetime 'a in some method signature, so most trait implementations using '_ there would fail. On the other hand, '_ lifetimes in the Self type are probably quite common in working trait impls, so those should probably be exempt.
And of course the fact that the lifetime appearing nowhere, or only in non-async methods, makes for some use-cases that a new error could break means that adding an “error when trait generics are placeholdered” is likely too breaking a change for a semver-minor update. So unless a 0.2 version ever comes out, things should probably stay as-is?
Consider the following, where the lifetime for
&
is elided in the trait implementation and a placeholder is used for the generic in the trait:This generates the following implementation:
This, of course, does not match the generated trait definition which has only a single lifetime generic in
f
. The "correct" implementation would look like:This, of course, would require
async-trait
to know that the placeholdered generic lifetime in the trait corresponds to the elided lifetime in the implementation. In general, it's clear thatasync-trait
can't do this as it doesn't have type information nor access to the AST of the definition.I believe that
async-trait
should likely error when trait generics are placeholdered. At least then the user gets a nice error message as opposed to incorrect code being generated.The text was updated successfully, but these errors were encountered: