Refere to a referecence in an associated type

I got this simple trait:

pub trait Delete<C> {
    type Error;

    /// Delete the row in the database.
    fn delete(&self, conn: C) -> impl Future<Output = Result<(), Self::Error>>;
}

And I want to implement it directly for the corresponding pool object in SQLx:

impl<T> Delete<sqlx::SqlitePool> for T
where
    T: for<'a> Delete<&'a mut sqlx::SqliteConnection>,
{
    type Error = <T as Delete<&mut sqlx::SqliteConnection>>::Error;

    async fn delete(&self, conn: sqlx::SqlitePool) -> Result<(), Self::Error> {
        let mut conn = conn.acquire().await?;
        self.delete(&mut *conn).await
    }
}

However rust want me to specify the lifetime of the reference in the associated type Error... Which I don't have. And if I add a reference to the implementation, rust tell me that the variable conn doesn't live long enough due to the lifetime being referenced in the output type

error[E0597]: `conn` does not live long enough
  --> src/table/delete.rs:17:27
   |
15 |     async fn delete(&self, conn: sqlx::SqlitePool) -> Result<(), Self::Error> {
   |                                                       ----------------------- return type of async function is Result<(), <T as delete::Delete<&'1 mut SqliteConnection>>::Error>
16 |         let mut conn = conn.acquire().await.unwrap();
   |             -------- binding `conn` declared here
17 |         self.delete(&mut *conn).await
   |         ------------------^^^^-
   |         |                 |
   |         |                 borrowed value does not live long enough
   |         argument requires that `conn` is borrowed for `'1`
18 |     }
   |     - `conn` dropped here while still borrowed

Is there any trickery I can use to fix that?

the problem with this statement is there is not a single associated <T as Delete<...>>::Error type, but possibly infinitely many of them.

thus, rust does not support projection to associated types using higher ranked trait bounds, something like <T as for<'a> Delete<'a, ...>>::AssociatedType.

but if you disallow Delete<C>::Error to depend on C, then it's possible to write this blanket implementation, you just use an equality constrains for the associated type Error, something like this should work:

impl<T, E> Delete<sqlx::SqlitePool> for T
where
    T: for<'a> Delete<&'a mut sqlx::SqliteConnection, Error = E>,
{
    type Error = E;
    //...
}

Another option is to convert to a different error type that doesn’t have a lifetime. This can be seen as the complement to the SqlitePool -> SqliteConnection conversion you are already doing in this implementation.

struct MyDeleteError {
    // whatever fields suit your needs here ...
}

impl<T> Delete<sqlx::SqlitePool> for T
where
    T: for<'a> Delete<&'a mut sqlx::SqliteConnection>,
{
    type Error = MyDeleteError;

    async fn delete(&self, conn: sqlx::SqlitePool) -> Result<(), Self::Error> {
        let mut conn = conn.acquire().await?;
        self.delete(&mut *conn).await.map_err(|e| MyDeleteError { ... })
        //                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    }
}