[E0521] coroutine and *FnOnce
closures should own upvars and there shall not be escaping borrows
#140132
Labels
C-bug
Category: This is a bug.
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
I tried this code:
I expected to see this happen:
This should compile. The following is the current MIR of the closure at the analysis phase.
Note that the closure value
_1
has a correct type for aFnOnce
so that it is entirely owned by the closure body.Instead, this happened:
This unfortunately does not compile.
This boils down to a borrow not living long enough due to the
StorageDead(_2)
statement, at which_1
is still alive.A similar situation also applies to coroutines as implemented today. See this test suite
Meta
rustc --version --verbose
:The commit hash should be
49e5e4e3a5610c240a717cb99003a5d5d3356679
.Possible way forward
We could generate a separate body for
FnOnce
variant of closures, when requested, and apply a MIR transformation early to lift the upvars into their own locals. This is a known technique in #135527.Backtrace
The text was updated successfully, but these errors were encountered: