Closed EliseZeroTwo closed 3 years ago
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)
related: #106 #64
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:
error[E0276]: impl has stricter requirements than trait
--> src/main.rs:12:5
|
7 | async fn test(id: IdT) -> Self;
| ------------------------------- definition of `test` from trait
...
12 | async fn test(id: &'a str) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'a: 'async_trait`
For more information about this error, try `rustc --explain E0276`.
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:
🖤