Skip to content

Tracking issue for more precise coroutine captures #69663

Open

Description

@tmandry

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)

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.

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Mar 3, 2020
  2. tmandry commented on Mar 3, 2020

    @tmandry
    MemberAuthor

    cc @nikomatsakis @Aaron1011

    I've created a "meta-issue" to track these improvements.

  3. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    E-hardCall 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.
    AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.
    and removed
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Mar 3, 2020
  4. jonas-schievink commented on Mar 8, 2020

    @jonas-schievink
    Contributor

    I've removed #69672 and moved it over to #69826

  5. changed the title [-]More precise generator captures[/-] [+]Tracking issue for more precise generator captures[/+] on Apr 21, 2020
  6. tmandry commented on Jul 16, 2021

    @tmandry
    MemberAuthor
  7. self-assigned this
    on Jul 16, 2021
  8. assigned and unassigned on Jan 27, 2022
  9. eholk commented on Feb 16, 2022

    @eholk
    Contributor

    I think #94067 counts as another instance of this bug.

  10. moved this to On deck in wg-async workon Dec 8, 2022
  11. oxalica commented on Jun 15, 2023

    @oxalica
    Contributor

    Is this issue also tracking the case where the reference to the local Send is actually used after await point? I failed to come up a way to make the following code cause UB.

    struct SendButNotSync(std::cell::RefCell<String>);
    
    async fn work() {}
    
    fn more_work(owned: SendButNotSync) -> impl std::future::Future<Output = ()> + Send {
        async move {
            // Keeps a reference of `owned`.
            let borrowed = owned.0.borrow();
            // During the context switch, no one can mutate either `owned` or `borrowed`.
            work().await;
            // Regain `owned` and `borrowed` BOTH on the same but possibly another thread.
            println!("{borrowed}");
        }
    }

    I can imagine that during await, the self-reference is pretended to be dropped but magically reborrowed from borrowed after resumed (derived from Pin<&mut Self> of Generator::resume in desugared form). In both before and after the await point, the borrowed is access in the same thread as owned, and no other thread could alter them in the same time.

  12. changed the title [-]Tracking issue for more precise generator captures[/-] [+]Tracking issue for more precise coroutine captures[/+] on Jan 9, 2024
  13. thebluetropics commented on Jan 13, 2024

    @thebluetropics

    Will the issue soon be fixed? I am really hoping on this one

  14. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Dec 21, 2024
  15. Xiretza commented on Jul 21, 2025

    @Xiretza
    Contributor

    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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-coroutinesArea: CoroutinesA-type-systemArea: Type systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-hardCall 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.T-typesRelevant to the types team, which will review and decide on the PR/issue.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions