Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Coroutine/Future Send bounds are too restrictive when taking references to !Sync values #132382

Copy link
Copy link
@ds84182

Description

@ds84182
Issue body actions

I tried this code:

fn main() {
    let foo: &dyn Send = &async {
        let cell = &std::cell::Cell::new(1234);
        async {}.await;
        cell.set(5678);
    };
}

I expected to see this happen: Should compile successfully, like it does without the reference to Cell.

Instead, this happened: Compilation fails. Removing the intermediate reference to the Cell allows this to compile.


This is a fundamental limitation between Send and coroutine yield points. A Cell owned by a coroutine will not observe any data races as references to that Cell cannot (soundly) escape the coroutine across yield points. Yield points could use an alternative autotrait that represents "thread pinning".

anatawa12

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coroutinesArea: CoroutinesArea: CoroutinesC-bugCategory: This is a bug.Category: This is a bug.E-needs-investigationCall for partcipation: This issues needs some investigation to determine current statusCall for partcipation: This issues needs some investigation to determine current statusT-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-langRelevant to the language teamRelevant to the language teamWG-asyncWorking group: Async & awaitWorking group: Async & await

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.