-
-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
References or lifetimes in generic types results in lifetimes in impl do not match this method in trait
#175
Comments
Workaround: using an explicit lifetime: #[async_trait(?Send)]
- impl DbOpDelete<&str> for DbCustomer {
+ impl<'a> DbOpDelete<&'a str> for DbCustomer {
- async fn delete(pool: &sqlx::PgPool, id: &str) -> Result<Option<Self>, bool> {
+ async fn delete(pool: &sqlx::PgPool, id: &'a str) -> Result<Option<Self>, bool> {
Err(false) |
proc-macro cannot recognize that the anonymous lifetime in the method argument and the anonymous lifetime in the trait parameter are the same, so IIUC there is no way to automatically resolve this on the proc-macro side. |
Thank you for the fast response! With this I run into another problem (both on nightly & stable): Code: pub struct OwO;
#[async_trait(?Send)]
pub trait Trait<IdT>: Sized {
async fn test(id: IdT) -> Self;
}
#[async_trait(?Send)]
impl<'a> Trait<&'a str> for OwO {
async fn test(id: &'a str) -> Self {
todo!()
}
} Error:
However this seems like a separate issue, if this is not just me missing something obvious would you like me to open a new issue? |
That seems related to #8. Workaround is: #[async_trait(?Send)]
pub trait Trait<IdT>: Sized {
- async fn test(id: IdT) -> Self;
+ async fn test(id: IdT) -> Self
+ where
+ IdT: 'async_trait;
} |
that worked, thanks! I'm unsure if you want me to mark this as closed or not so I will just leave it, please feel free to mark it as closed 🖤 |
Hi!
Seemingly providing references or lifetimes in generic types breaks
async-trait
.Tested on:
rustc 1.56.0-nightly (ad981d58e 2021-08-08)
&rustc 1.54.0 (a178d0322 2021-07-26)
Code used to replicate this:
Error:
🖤
The text was updated successfully, but these errors were encountered: