Open frederikhors opened 1 year ago
simplified a bit using perses, still need to eliminate the dependency though.
use futures::future::{BoxFuture, FutureExt};
trait Executor: Send {
type Executor<'this>: sqlx::PgExecutor<'this>
where
Self: 'this;
fn as_executor(&mut self) -> Self::Executor<'_>;
}
struct Store {}
#[derive(sqlx::FromRow)]
struct Team {}
fn query_teams(user: &str, db: impl Executor, store: Store) -> BoxFuture<Store> {
async move {
let query = sqlx::QueryBuilder::new(r#"SELECT "teams".*" FROM "teams"#);
query
.build_query_as::<Team>()
.fetch_all(db.as_executor())
.await;
store
}
.boxed()
}
Here is, what I believe is, the root cause/MCVE of this issue (play):
trait G: Send {
type Gat<'l>: Send
where
Self: 'l;
fn as_gat(&self) -> Self::Gat<'_>;
}
fn a(g: impl G) {
let _: &dyn Send = &async move {
let _gat = g.as_gat();
async{}.await
};
}
It looks like this is what happens:
async{}: Send
requires that typeof(_gat): Send
(because it lives across an .await
point)typeof(_gat): Send
requires Self: 'l
impl G: 'l
is the problemRemoving where Self: 'l
from the GAT works around the issue.
@QuineDot note that this is not always possible, sometimes such bound is required.
REPRODUCTION: https://www.rustexplorer.com/b/oe3uh4
error:
Some code:
Meta