Merge pull request #858 from dtolnay/stdvectorautotrait

Add ui test of CxxVector autotrait impls
This commit is contained in:
David Tolnay 2021-05-01 14:40:29 -07:00 committed by GitHub
commit 78c0c688b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,21 @@
use cxx::CxxVector;
#[cxx::bridge]
mod ffi {
extern "C++" {
type ThreadSafe;
type NotThreadSafe;
}
impl CxxVector<ThreadSafe> {}
impl CxxVector<NotThreadSafe> {}
}
unsafe impl Send for ffi::ThreadSafe {}
fn assert_send<T: Send>() {}
fn main() {
assert_send::<CxxVector<ffi::ThreadSafe>>();
assert_send::<CxxVector<ffi::NotThreadSafe>>();
}

View File

@ -0,0 +1,19 @@
error[E0277]: `*const cxx::void` cannot be sent between threads safely
--> $DIR/vector_autotraits.rs:20:5
|
16 | fn assert_send<T: Send>() {}
| ---- required by this bound in `assert_send`
...
20 | assert_send::<CxxVector<ffi::NotThreadSafe>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const cxx::void` cannot be sent between threads safely
|
= help: within `CxxVector<NotThreadSafe>`, the trait `Send` is not implemented for `*const cxx::void`
= note: required because it appears within the type `[*const cxx::void; 0]`
= note: required because it appears within the type `cxx::private::Opaque`
note: required because it appears within the type `NotThreadSafe`
--> $DIR/vector_autotraits.rs:7:14
|
7 | type NotThreadSafe;
| ^^^^^^^^^^^^^
= note: required because it appears within the type `[NotThreadSafe; 0]`
= note: required because it appears within the type `CxxVector<NotThreadSafe>`