Open
Description
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".
Metadata
Metadata
Assignees
Labels
Area: CoroutinesCategory: This is a bug.Call for partcipation: This issues needs some investigation to determine current statusRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.Working group: Async & await