-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closure-like blocks capture all generic type and const parameters #65442
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
Comments
I suspect the answer is no -- cc @rust-lang/wg-async-await -- this might contribute to "not Send/Sync" errors if we're capturing what we shouldn't be |
I think my expectation is that the explicit |
Assigning to myself to investigate and document the cause of the issue, at least. |
Related to / dupe of #42940 |
I hate bumping issues but... any movement on this? Just ran into it myself in a very similar context |
No progress I know of |
Note that this bug does not require async to trigger. Playground where this triggered using |
Reproduced with a more minimal example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=319e66180308bede359b022cda8ed0bf #![feature(type_alias_impl_trait)]
type Ty = impl Fn();
fn run<E>(_: E) -> Ty {
|| ()
}
|
Here's the minimum #![feature(type_alias_impl_trait)]
use std::future::Future;
type Deferred = impl Future<Output = ()> + 'static;
fn future_out<F>(_: F) -> Deferred {
async move { }
}
|
I'd like to write the following code:
In particular, I would like to have the
impl Trait
returned bybaz
not be tied to the lifetime of its&str
argument. Sinceimpl Trait
captures the lifetimes of all generic arguments (as per RFC 1951), I can't write the code this way though. So instead, I triedHowever, with this, I get the error:
This seems odd, since
Q
is (intentionally) not used in theasync
block. I can work around this by adding anasync fn
and calling that instead of usingasync move
, but that seems like an odd hack:Is it intentional that the
async
block "captures"Q
here, even though it never contains aQ
?The text was updated successfully, but these errors were encountered: