-
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
Wrong Send constraint when using a trait with lifetime + associated type in async #60658
Comments
Expanding the constraint to
gets past this error. I'm not sure why it needs this more general constraint though. |
I suspect one can make a failure of this with |
Deferring -- not blocking stabilization. Would be good to investigate though. |
I hit this in dtolnay/async-trait#34 and minimized to a quite similar looking minimal repro but with the associated type in argument position rather than return position. I believe this code should compile as written, but right now I am totally stuck on what missing bound is being expected. Is there anything similar to @Nemo157's hrtb that would unblock this one? use std::future::Future;
pub trait Trait<'a> {
type Assoc: Send + 'static;
fn f(x: Self::Assoc) -> Box<dyn Future<Output = ()> + Send>
where
'a: 'static,
Self: Sized + 'static,
{
Box::new(f::<Self>(x))
}
}
async fn f<T: Trait<'static>>(_x: T::Assoc) {
async {}.await
} error[E0308]: mismatched types
--> src/main.rs:11:9
|
11 | Box::new(f::<Self>(x))
| ^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected type `std::marker::Send`
found type `std::marker::Send` |
I keep running into this both with and without If I or someone else were to try and investigate the cause, is there any good starting point? |
You can get to this error via the use of edit: an even more straightforward example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3e0b26047b48a0c62db94939556d4538 |
@stephaneyfx pointed out a workaround (using I don't think this helps |
Triage, no change in the output. |
I don't know if it's helpful or to what degree it's related, but I get "one type is more general than the other" error that I fail to understand here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=14c3f1f5a60a8b36a52ab55776ba241e |
I fail to do the mental gymnastics required to be sure, but this might be a dupe of #64552. That the HRTB works lines up well with Aaron1011's analysis over there. |
|
Updated reproducer: (playground) use core::pin::Pin;
use std::future::Future;
pub trait Foo<'a> {
type Future: Future<Output = ()>;
fn foo() -> Self::Future;
}
struct MyType<T>(T);
impl<'a, T> Foo<'a> for MyType<T>
where
T: Foo<'a>,
T::Future: Send,
{
type Future = Pin<Box<dyn Future<Output = ()> + Send + 'a>>;
fn foo() -> Self::Future {
Box::pin(async move {
T::foo().await
})
}
} produces:
as noted in #60658 (comment), replacing |
Update: See #60658 (comment) for the latest reproducer
Minimal:
Out:
Compiler version:
rustc 1.36.0-nightly (2019-05-07)
The text was updated successfully, but these errors were encountered: