Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format_args temporary across await point leads to a non-Sync future #182

Closed
dtolnay opened this issue Nov 4, 2021 · 0 comments · Fixed by #183
Closed

Format_args temporary across await point leads to a non-Sync future #182

dtolnay opened this issue Nov 4, 2021 · 0 comments · Fixed by #183

Comments

@dtolnay
Copy link
Owner

dtolnay commented Nov 4, 2021

This looks like our version of rust-lang/rust#64856. I expect the same fix will work.

use anyhow::anyhow;
use std::future;

fn assert_sync<T: Sync>(_: T) {}

fn main() {
    assert_sync(async {
        future::ready(anyhow!("...")).await;
    });
}

This is fine with the current most recent published version of anyhow (1.0.45) but on master due to #180 it fails as follows:

error: future cannot be shared between threads safely
 --> src/main.rs:7:5
  |
7 |     assert_sync(async {
  |     ^^^^^^^^^^^ future created by async block is not `Sync`
  |
  = help: within `impl Future`, the trait `Sync` is not implemented for `core::fmt::Opaque`
note: future is not `Sync` as this value is used across an await
 --> src/main.rs:8:9
  |
8 |         future::ready(anyhow!("...")).await;
  |         ^^^^^^^^^^^^^^--------------^^^^^^^- `$crate::private::format_args!($msg)` is later dropped here
  |         |             |
  |         |             has type `[ArgumentV1<'_>; 0]` which is not `Sync`
  |         await occurs here, with `$crate::private::format_args!($msg)` maybe used later
note: required by a bound in `assert_sync`
 --> src/main.rs:4:19
  |
4 | fn assert_sync<T: Sync>(_: T) {}
  |                   ^^^^ required by this bound in `assert_sync`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant