Open
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