async-rs / async-rs/async-std

write_fmt fails inside spawned task

Open
#329 6 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
4.1k
Forks
339
PR merge metrics
No merged PRs in 30d

Description

It turns out that [`Arguments`](https://doc.rust-lang.org/std/fmt/struct.Arguments.html#impl-Send) is non-`Send`, which means passing it to a spawned Future may not work because the future itself is `Send`.

```rust
use async_std::task;
use async_std::prelude::*;
use async_std::io;

fn main() {
task::block_on(async {
task::spawn(async {
// This doesn't compile
io::stderr().write_fmt(format_args!("hello")).await?;
}).await
})
}
```
![2019-10-14-185507_1920x1080](https://user-images.githubusercontent.com/2467194/66768900-ff391b00-eeb3-11e9-9716-19ddbfc33700.png)

This is causing some bugs. Posting this for future reference.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.