-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
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
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".
anatawa12
Metadata
Metadata
Assignees
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