Closed
Description
Given the following code:
#![feature(generic_associated_types)]
use std::fmt::Debug;
use std::marker::PhantomData;
#[derive(Debug)]
pub struct TransactionImpl<'db> {
_marker: PhantomData<&'db ()>,
}
#[derive(Debug)]
pub struct CursorImpl<'txn> {
_marker: PhantomData<&'txn ()>,
}
pub trait Cursor<'txn> {}
pub trait Transaction<'db>: Send + Sync + Debug + Sized {
type Cursor<'tx>: Cursor<'tx>
where
'db: 'tx,
Self: 'tx;
fn cursor<'tx>(&'tx self) -> Result<Self::Cursor<'tx>, ()>
where
'db: 'tx;
}
impl<'tx> Cursor<'tx> for CursorImpl<'tx> {}
impl<'db> Transaction<'db> for TransactionImpl<'db> {
type Cursor<'tx> = CursorImpl<'tx>;
fn cursor<'tx>(&'tx self) -> Result<Self::Cursor<'tx>, ()>
where
'db: 'tx,
{
loop {}
}
}
The current output is:
error[E0478]: lifetime bound not satisfied
--> src/lib.rs:32:24
|
32 | type Cursor<'tx> = CursorImpl<'tx>;
| ^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'db` as defined here
--> src/lib.rs:31:6
|
31 | impl<'db> Transaction<'db> for TransactionImpl<'db> {
| ^^^
note: but lifetime parameter must outlive the lifetime `'tx` as defined here
--> src/lib.rs:32:17
|
32 | type Cursor<'tx> = CursorImpl<'tx>;
Error is fixed by adding a where clause to associated type in impl, which is not immediately clear:
impl<'db> Transaction<'db> for TransactionImpl<'db> {
type Cursor<'tx>
where
'db: 'tx,
= CursorImpl<'tx>;
}
Metadata
Metadata
Assignees
Labels
Area: Generic associated types (GATs)Area: Messages for errors, warnings, and lintsDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(generic_associated_types)]` a.k.a. GATsIssues using the `generic_associated_types` feature that have been triagedRelevant to the compiler team, which will review and decide on the PR/issue.