-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Higher ranked lifetime error when checking auto traits of async functions containing calls to async closures which capture a local #134997
Comments
This is likely just a manifestation of #110338. |
unfortunately if you use |
Yep, neither of those are special wrt this issue. The many dozens of issues that #110338 links to also are both trivial to trigger and give terrible error messages. The underlying issue is practically impossible to solve at this point though. |
I see :( |
well then I guess this is one for on the same list 🤷 |
For the record, this doesn't even really have to do with async closures. This is the same bug but written with a manual "async fn" trait and which uses closures that return async blocks: use std::future::Future;
trait CallAsyncFn {
type Fut<'a>: Future
where
Self: 'a;
type Output;
fn call(&self) -> Self::Fut<'_>;
}
impl<F, Fut, T> CallAsyncFn for F
where
F: Fn() -> Fut,
Fut: Future<Output = T>,
{
type Fut<'a>
= Fut
where
Self: 'a;
type Output = T;
fn call(&self) -> Self::Fut<'_> {
self()
}
}
// this function is important, inlining it breaks the poc.
// We also tried replacing it with `identity` but the fact that this is an
// async function calling the closure inside is also relevant.
async fn do_not_inline(f: impl CallAsyncFn) {
f.call().await;
}
fn foo() -> impl Send {
async move {
// just replacing this with unit, leaves the error with `Send` but fixes the
// "higher-ranked lifetime error"
let s = &();
do_not_inline(|| async {
&s;
})
.await;
}
} I'm almost certain that the reason this manifests for |
I tried this code:
I expected to see this happen: compilation succeeds
Instead, this happened:
try it here: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=ab71ed9cfa6f91320c7a24fe7f2bdca9
note, we got here through a bigger example, the
impl Send
used to come from theasync_trait
library where it producedPin<Box<dyn Future<Output=()> + Send>>
but most of that was not relevant for the mcve.Meta
rustc --version --verbose
:cc: @compiler-errors
@rustbot label +F-async_closure +T-compiler +A-auto-traits
The text was updated successfully, but these errors were encountered: