Coroutine/Future `Send` bounds are too restrictive when taking references to `!Sync` values
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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".
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Rust reproducer in the issue and compare it with the version that removes the reference to Cell. Trace how Send bounds are inferred across the async yield point, then determine whether the behavior can be changed without compromising soundness. Done means the reproducer compiles as expected with appropriate compiler coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100