Skip to content

Commit e3c3511

Browse files
authored
Merge pull request #106 from kmdreko/fix/avoid-where-self-clause-on-gats
fix: avoid where Self: 'a clause on GATs
2 parents ec38eca + 66636b2 commit e3c3511

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/lib.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,13 @@ pub trait SimpleAsyncConnection {
127127
#[async_trait::async_trait]
128128
pub trait AsyncConnection: SimpleAsyncConnection + Sized + Send {
129129
/// The future returned by `AsyncConnection::execute`
130-
type ExecuteFuture<'conn, 'query>: Future<Output = QueryResult<usize>> + Send
131-
where
132-
Self: 'conn;
130+
type ExecuteFuture<'conn, 'query>: Future<Output = QueryResult<usize>> + Send;
133131
/// The future returned by `AsyncConnection::load`
134-
type LoadFuture<'conn, 'query>: Future<Output = QueryResult<Self::Stream<'conn, 'query>>> + Send
135-
where
136-
Self: 'conn;
132+
type LoadFuture<'conn, 'query>: Future<Output = QueryResult<Self::Stream<'conn, 'query>>> + Send;
137133
/// The inner stream returned by `AsyncConnection::load`
138-
type Stream<'conn, 'query>: Stream<Item = QueryResult<Self::Row<'conn, 'query>>> + Send
139-
where
140-
Self: 'conn;
134+
type Stream<'conn, 'query>: Stream<Item = QueryResult<Self::Row<'conn, 'query>>> + Send;
141135
/// The row type used by the stream returned by `AsyncConnection::load`
142-
type Row<'conn, 'query>: Row<'conn, Self::Backend>
143-
where
144-
Self: 'conn;
136+
type Row<'conn, 'query>: Row<'conn, Self::Backend>;
145137

146138
/// The backend this type connects to
147139
type Backend: Backend;
@@ -341,4 +333,14 @@ pub trait AsyncConnection: SimpleAsyncConnection + Sized + Send {
341333
fn transaction_state(
342334
&mut self,
343335
) -> &mut <Self::TransactionManager as TransactionManager<Self>>::TransactionStateData;
336+
337+
// These functions allow the associated types (`ExecuteFuture`, `LoadFuture`, etc.) to
338+
// compile without a `where Self: '_` clause. This is needed the because bound causes
339+
// lifetime issues when using `transaction()` with generic `AsyncConnection`s.
340+
//
341+
// See: https://github.com/rust-lang/rust/issues/87479
342+
#[doc(hidden)]
343+
fn _silence_lint_on_execute_future(_: Self::ExecuteFuture<'_, '_>) {}
344+
#[doc(hidden)]
345+
fn _silence_lint_on_load_future(_: Self::LoadFuture<'_, '_>) {}
344346
}

src/pooled_connection/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,10 @@ where
181181
C::Target: AsyncConnection,
182182
{
183183
type ExecuteFuture<'conn, 'query> =
184-
<C::Target as AsyncConnection>::ExecuteFuture<'conn, 'query>
185-
where C::Target: 'conn, C: 'conn;
186-
type LoadFuture<'conn, 'query> = <C::Target as AsyncConnection>::LoadFuture<'conn, 'query>
187-
where C::Target: 'conn, C: 'conn;
188-
type Stream<'conn, 'query> = <C::Target as AsyncConnection>::Stream<'conn, 'query>
189-
where C::Target: 'conn, C: 'conn;
190-
type Row<'conn, 'query> = <C::Target as AsyncConnection>::Row<'conn, 'query>
191-
where C::Target: 'conn, C: 'conn;
184+
<C::Target as AsyncConnection>::ExecuteFuture<'conn, 'query>;
185+
type LoadFuture<'conn, 'query> = <C::Target as AsyncConnection>::LoadFuture<'conn, 'query>;
186+
type Stream<'conn, 'query> = <C::Target as AsyncConnection>::Stream<'conn, 'query>;
187+
type Row<'conn, 'query> = <C::Target as AsyncConnection>::Row<'conn, 'query>;
192188

193189
type Backend = <C::Target as AsyncConnection>::Backend;
194190

tests/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ mod pooling;
1313
mod sync_wrapper;
1414
mod type_check;
1515

16-
async fn transaction_test(conn: &mut TestConnection) -> QueryResult<()> {
16+
async fn transaction_test<C: AsyncConnection<Backend = TestBackend>>(
17+
conn: &mut C,
18+
) -> QueryResult<()> {
1719
let res = conn
1820
.transaction::<i32, diesel::result::Error, _>(|conn| {
1921
Box::pin(async move {

0 commit comments

Comments
 (0)