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

let_cxx_string blocks async fn's Future from being Send #693

Closed
dtolnay opened this issue Jan 27, 2021 · 0 comments · Fixed by #694
Closed

let_cxx_string blocks async fn's Future from being Send #693

dtolnay opened this issue Jan 27, 2021 · 0 comments · Fixed by #694

Comments

@dtolnay
Copy link
Owner

dtolnay commented Jan 27, 2021

This error is wrong, std::string is fine to access from across threads.

use cxx::{let_cxx_string, CxxString};

async fn f() {
    let_cxx_string!(s = "...");

    async fn g(_: &CxxString) {}
    g(&s).await;
}

fn main() {
    fn assert_send(_: impl Send) {}
    assert_send(f());
}
error: future cannot be sent between threads safely
  --> src/main.rs:12:5
   |
11 |     fn assert_send(_: impl Send) {}
   |                            ---- required by this bound in `assert_send`
12 |     assert_send(f());
   |     ^^^^^^^^^^^ future returned by `f` is not `Send`
   |
   = help: within `impl Future`, the trait `Send` is not implemented for `*const ()`
note: future is not `Send` as this value is used across an await
  --> src/main.rs:7:5
   |
4  |     let_cxx_string!(s = "...");
   |     --------------------------- has type `StackString` which is not `Send`
...
7  |     g(&s).await;
   |     ^^^^^^^^^^^ await occurs here, with `mut $var` maybe used later
8  | }
   | - `mut $var` is later dropped here
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