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".