third_party_rust_cxx/tests/cxx_string.rs
David Tolnay dcc1db841e
Add regression test of let_cxx_string in async fn
error: future cannot be sent between threads safely
      --> tests/cxx_string.rs:14:5
       |
    13 |     fn assert_send(_: impl Send) {}
       |                            ---- required by this bound in `assert_send`
    14 |     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
      --> tests/cxx_string.rs:9:9
       |
    6  |         let_cxx_string!(s = "...");
       |         --------------------------- has type `StackString` which is not `Send`
    ...
    9  |         g(&s).await;
       |         ^^^^^^^^^^^ await occurs here, with `mut $var` maybe used later
    10 |     }
       |     - `mut $var` is later dropped here
2021-01-27 11:25:48 -08:00

16 lines
306 B
Rust

use cxx::{let_cxx_string, CxxString};
#[test]
fn test_async_cxx_string() {
async fn f() {
let_cxx_string!(s = "...");
async fn g(_: &CxxString) {}
g(&s).await;
}
// https://github.com/dtolnay/cxx/issues/693
fn assert_send(_: impl Send) {}
assert_send(f());
}