-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AFIT does not fulfill the required lifetime, manual RPITIT does #133676
Comments
For the record, the minimization you provided is a totally different issue than the original issue. |
I don't expect the "minimized example" to pass (trait impls are not "covariant" over their output associated types), but I'm a bit surprised the original example doesn't pass. |
Actually, this is a valid error. The RPIT in the trait definition ( There's no implied outlives bound between |
Oh, mhh so the fix I'm looking for is just this? use std::{borrow::Cow, future::Future};
trait Deserializer<'s> {
fn pop<'this>(&'this mut self) -> impl Future<Output = Cow<'s, str>> + 'this
where
's: 'this;
}
struct Works;
struct AlsoWorks;
struct Journal {
items: Vec<Cow<'static, str>>,
}
impl<'s> Deserializer<'s> for (Journal, Works) {
// works
fn pop<'this>(&'this mut self) -> impl Future<Output = Cow<'s, str>> + 'this
where
's: 'this,
{
async move { self.0.items.pop().unwrap_or_default() }
}
}
impl<'s> Deserializer<'s> for (Journal, AlsoWorks) {
// also work
async fn pop<'this>(&'this mut self) -> Cow<'s, str>
where
's: 'this,
{
self.0.items.pop().unwrap_or_default()
}
}
fn main() {
// mhhh
} |
If that bound makes sense in the design of your API, then sure. |
Fantastic! Thanks for helping me get out of this one. |
(For the casual reader: "AFIT" = Async Fn In Trait, "RPITIT" = Return Position Impl Trait In Trait")
I tried this code: (playground)
I expected to see this happen: everything typechecks.
Instead, this happened:
Minimal repro (edit: that's a different issue, see below)
We don't need to bring AFIT into it: (playground)
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: