Repository: dtolnay/cxx (language: rust)

Issue:
let_cxx_string blocks async fn's Future from being Send
This error is wrong, std::string is fine to access from across threads.

```rust
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());
}
```

```console
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
```


Discussion / hints:

Fix patch:
diff --git a/src/cxx_string.rs b/src/cxx_string.rs
index 10abbcef9..08a58b11c 100644
--- a/src/cxx_string.rs
+++ b/src/cxx_string.rs
@@ -188,7 +188,7 @@ impl PartialEq<str> for CxxString {
 pub struct StackString {
     // Static assertions in cxx.cc validate that this is large enough and
     // aligned enough.
-    space: MaybeUninit<[*const (); 8]>,
+    space: MaybeUninit<[usize; 8]>,
 }
 
 impl StackString {


Test patch:
diff --git a/tests/cxx_string.rs b/tests/cxx_string.rs
new file mode 100644
index 000000000..be693cd2c
--- /dev/null
+++ b/tests/cxx_string.rs
@@ -0,0 +1,15 @@
+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());
+}