Repository navigation
Tracking issue for more precise coroutine captures #69663
Copy link
Copy link
Open
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-coroutinesArea: CoroutinesArea: CoroutinesA-type-systemArea: Type systemArea: Type systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
Today, valid programs using coroutines (and async/await) are rejected by the compiler because it thinks certain values may be held across yields when they are not.
Examples / to do: (please add more as they come up)
- async/await: awaiting inside a match block captures borrow too eagerly #57017
- Dropped variables still included in generator type #57478
- Indexing via
indexmethod and[idx]sugar works differently inasyncblocks/functions #72956 - ICE: Broken MIR #72651
- The rules for how non-Send local variables "infect" an async function, making its Future type non-Send also, are stricter than they need to be. #63768
- Moved value is considered as held across an
awaitinasync fn#87309 - New must_not_suspend lint triggers even when value has been moved #89562
- Future non-Send although non-Send local is dropped before .await #104883
Unresolved Questions
How should we implement this?
Are there any programs which could be accepted, but shouldn't be because they would depend too heavily on implementation details of the compiler?
Implementation notes
There's some discussion here: #57017 (comment)
This issue has been assigned to @eholk via this comment.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-coroutinesArea: CoroutinesArea: CoroutinesA-type-systemArea: Type systemArea: Type systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Projects
- StatusShow more project fieldsOn deck
Activity
tmandry commentedon Mar 3, 2020
cc @nikomatsakis @Aaron1011
I've created a "meta-issue" to track these improvements.
jonas-schievink commentedon Mar 8, 2020
I've removed #69672 and moved it over to #69826
[-]More precise generator captures[/-][+]Tracking issue for more precise generator captures[/+]tmandry commentedon Jul 16, 2021
@rustbot assign @eholk
Fix codegen issue for parameters with lifetimes
Fix codegen issue for parameters with lifetimes
Workaround 'rustc' bug, compiling more async code.
eholk commentedon Feb 16, 2022
I think #94067 counts as another instance of this bug.
oxalica commentedon Jun 15, 2023
Is this issue also tracking the case where the reference to the local
Sendis actually used afterawaitpoint? I failed to come up a way to make the following code cause UB.I can imagine that during
await, the self-reference is pretended to be dropped but magically reborrowed fromborrowedafter resumed (derived fromPin<&mut Self>ofGenerator::resumein desugared form). In both before and after theawaitpoint, theborrowedis access in the same thread asowned, and no other thread could alter them in the same time.[-]Tracking issue for more precise generator captures[/-][+]Tracking issue for more precise coroutine captures[/+]thebluetropics commentedon Jan 13, 2024
Will the issue soon be fixed? I am really hoping on this one
Xiretza commentedon Jul 21, 2025
Another issue to be added to the list: #128095 (appears similar to #63768, but I'm not familiar enough with the internals to say for certain)