Repository: dtolnay/cxx (rust)

Issue:
[Feature Request] Support Vec<bool>
Can we please add support for Vec<bool>? There shouldn't be any special magic required, and though #169 claims to have fixed it, the snippet below doesn't work in any post-`1.0.0` version of `cxx` I tried.

```
#[cxx::bridge]
mod ffi {
    unsafe extern "C++" {
        fn gimme_vecbool() -> Vec<bool>;
    }
}
```

Currently, the only workaround I know about is wrapping the `bool` in a structure, which works but is annoying to work with.

Pull request:
Allow Vec<bool>
#169 should have been sufficient for this but mistakenly wasn't.

Closes #1103.

Patch:
diff --git a/syntax/check.rs b/syntax/check.rs
index 698782f9..b203ca1f 100644
--- a/syntax/check.rs
+++ b/syntax/check.rs
@@ -123,10 +123,9 @@ fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) {
             }
 
             match Atom::from(&ident.rust) {
-                None | Some(Char) | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize)
-                | Some(I8) | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32)
-                | Some(F64) | Some(RustString) => return,
-                Some(Bool) => { /* todo */ }
+                None | Some(Bool) | Some(Char) | Some(U8) | Some(U16) | Some(U32) | Some(U64)
+                | Some(Usize) | Some(I8) | Some(I16) | Some(I32) | Some(I64) | Some(Isize)
+                | Some(F32) | Some(F64) | Some(RustString) => return,
                 Some(CxxString) => {}
             }
         }


Test patch:
diff --git a/tests/ffi/lib.rs b/tests/ffi/lib.rs
index c3174bbc..9286cf7a 100644
--- a/tests/ffi/lib.rs
+++ b/tests/ffi/lib.rs
@@ -114,10 +114,11 @@ pub mod ffi {
         fn c_return_unique_ptr_vector_opaque() -> UniquePtr<CxxVector<C>>;
         fn c_return_ref_vector(c: &C) -> &CxxVector<u8>;
         fn c_return_mut_vector(c: Pin<&mut C>) -> Pin<&mut CxxVector<u8>>;
-        fn c_return_rust_vec() -> Vec<u8>;
+        fn c_return_rust_vec_u8() -> Vec<u8>;
         fn c_return_ref_rust_vec(c: &C) -> &Vec<u8>;
         fn c_return_mut_rust_vec(c: Pin<&mut C>) -> &mut Vec<u8>;
         fn c_return_rust_vec_string() -> Vec<String>;
+        fn c_return_rust_vec_bool() -> Vec<bool>;
         fn c_return_identity(_: usize) -> usize;
         fn c_return_sum(_: usize, _: usize) -> usize;
         fn c_return_enum(n: u16) -> Enum;
diff --git a/tests/ffi/tests.cc b/tests/ffi/tests.cc
index 4a94f4a7..3398c073 100644
--- a/tests/ffi/tests.cc
+++ b/tests/ffi/tests.cc
@@ -158,7 +158,7 @@ const std::vector<uint8_t> &c_return_ref_vector(const C &c) {
 
 std::vector<uint8_t> &c_return_mut_vector(C &c) { return c.get_v(); }
 
-rust::Vec<uint8_t> c_return_rust_vec() {
+rust::Vec<uint8_t> c_return_rust_vec_u8() {
   rust::Vec<uint8_t> vec{2, 0, 2, 0};
   return vec;
 }
@@ -177,6 +177,10 @@ rust::Vec<rust::String> c_return_rust_vec_string() {
   return {"2", "0", "2", "0"};
 }
 
+rust::Vec<bool> c_return_rust_vec_bool() {
+  return {true, true, false};
+}
+
 size_t c_return_identity(size_t n) { return n; }
 
 size_t c_return_sum(size_t n1, size_t n2) { return n1 + n2; }
diff --git a/tests/ffi/tests.h b/tests/ffi/tests.h
index 10cb37ae..dc02e4ff 100644
--- a/tests/ffi/tests.h
+++ b/tests/ffi/tests.h
@@ -111,10 +111,11 @@ std::unique_ptr<std::vector<Shared>> c_return_unique_ptr_vector_shared();
 std::unique_ptr<std::vector<C>> c_return_unique_ptr_vector_opaque();
 const std::vector<uint8_t> &c_return_ref_vector(const C &c);
 std::vector<uint8_t> &c_return_mut_vector(C &c);
-rust::Vec<uint8_t> c_return_rust_vec();
+rust::Vec<uint8_t> c_return_rust_vec_u8();
 const rust::Vec<uint8_t> &c_return_ref_rust_vec(const C &c);
 rust::Vec<uint8_t> &c_return_mut_rust_vec(C &c);
 rust::Vec<rust::String> c_return_rust_vec_string();
+rust::Vec<bool> c_return_rust_vec_bool();
 size_t c_return_identity(size_t n);
 size_t c_return_sum(size_t n1, size_t n2);
 Enum c_return_enum(uint16_t n);
diff --git a/tests/test.rs b/tests/test.rs
index 3c6ffa5e..bcf0a2cd 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -71,6 +71,8 @@ fn test_c_return() {
             .map(|o| o.z)
             .sum(),
     );
+    assert_eq!(b"\x02\0\x02\0"[..], ffi::c_return_rust_vec_u8());
+    assert_eq!([true, true, false][..], ffi::c_return_rust_vec_bool());
     assert_eq!(2020, ffi::c_return_identity(2020));
     assert_eq!(2021, ffi::c_return_sum(2020, 1));
     match ffi::c_return_enum(0) {