-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
I was trying to implement a generic SelfBorrowingClosure
based on https://users.rust-lang.org/t/why-closure-cannot-return-a-reference-to-data-moved-into-closure/72655/6 but got a problem compiling the following piece of code:
pub trait LifetimizedOutputFamily {
type Output<'a>
where
Self::Output<'a>: 'a;
}
pub struct RefTFamily<T>(core::marker::PhantomData<*const T>);
impl<T> LifetimizedOutputFamily for RefTFamily<T>
{
type Output<'a> = &'a T
where
T: 'a;
}
pub struct SelfBorrowingClosure<State, F, OutputFam>
where
OutputFam: LifetimizedOutputFamily,
F: Fn(&'_ State) -> <OutputFam as LifetimizedOutputFamily>::Output<'_>,
{
pub state: State,
pub call: F,
pub output_family: core::marker::PhantomData<*const OutputFam>,
}
impl<State, F, OutputFam> SelfBorrowingClosure<State, F, OutputFam>
where
OutputFam: LifetimizedOutputFamily,
F: Fn(&'_ State) -> <OutputFam as LifetimizedOutputFamily>::Output<'_>,
{
pub fn new(state: State, call: F) -> Self {
Self {
state,
call,
output_family: core::marker::PhantomData,
}
}
pub fn call(&self) -> <OutputFam as LifetimizedOutputFamily>::Output<'_> {
(self.call)(&self.state)
}
}
Minimal Reproducible Example (MRE):
pub trait LifetimizedOutputFamily {
type Output<'a>
where
Self::Output<'a>: 'a;
}
pub struct RefTFamily<T>(core::marker::PhantomData<*const T>);
impl<T> LifetimizedOutputFamily for RefTFamily<T>
{
type Output<'a> = &'a T
where
T: 'a;
}
Error:
error[E0275]: overflow evaluating the requirement `<RefTFamily<T> as LifetimizedOutputFamily>::Output<'a> == _`
--> src\lib.rs:11:5
|
11 | type Output<'a> = &'a T
| ^^^^^^^^^^^^^^^
Metadata
Metadata
Assignees
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.