Open
Listed in
Description
Reproduction:
use std::any::Any;
use std::future::Future;
trait Foo<'a>: Sized {
type Error;
fn foo(x: &'a str) -> Result<Self, Self::Error>;
}
impl<'a> Foo<'a> for &'a str {
type Error = ();
fn foo(x: &'a str) -> Result<Self, Self::Error> {
Ok(x)
}
}
async fn get_foo<'a, T>(x: &'a str) -> Result<T, <T as Foo<'a>>::Error>
where
T: Foo<'a>,
{
Foo::foo(x)
}
fn bar<'a>(x: &'a str) -> Box<dyn Future<Output = Result<&'a str, ()>> + Send + 'a> {
Box::new(async move { get_foo(x).await })
}
Output on stable and nightly:
error: implementation of `Foo` is not general enough
--> src/lib.rs:25:5
|
25 | Box::new(async move { get_foo(x).await })
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
|
= note: `Foo<'1>` would have to be implemented for the type `&'0 str`, for any two lifetimes `'0` and `'1`...
= note: ...but `Foo<'2>` is actually implemented for the type `&'2 str`, for some specific lifetime `'2
Interestingly, the code compiles without the + Send
. It also compiles without the async move block. This may be related to #61949.
@rustbot label +A-async-await
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Claimed
Milestone
Relationships
Development
No branches or pull requests
Activity
compiler-errors commentedon Jan 1, 2022
This is actually probably related to #60658 (and other issues) instead of #61949, and seems to be fixed under #92449.
eholk commentedon Jan 10, 2022
This does sound similar to several other issues. Glad to see #92449 seems to fix it.
@rustbot label +AsyncAwait-Triaged +AsyncAwait-Polish
higher-ranked lifetime error
in an async block #102211vincenzopalazzo commentedon Sep 23, 2023
@rustbot claim
OK this needs to be fixed in some way, I will try to see what it is going on
vincenzopalazzo commentedon Sep 23, 2023
Ah ok this looks like a well-known issue with lifetimes, ok I think this is related to #110338 (comment)
Putting this in our board btw