Ensure opaque types are !Unpin
diff --git a/src/cxx_string.rs b/src/cxx_string.rs
index 5010175..7ee8987 100644
--- a/src/cxx_string.rs
+++ b/src/cxx_string.rs
@@ -1,6 +1,7 @@
use alloc::borrow::Cow;
use alloc::string::String;
use core::fmt::{self, Debug, Display};
+use core::marker::{PhantomData, PhantomPinned};
use core::slice;
use core::str::{self, Utf8Error};
@@ -26,6 +27,7 @@
#[repr(C)]
pub struct CxxString {
_private: [u8; 0],
+ _pinned: PhantomData<PhantomPinned>,
}
impl CxxString {
diff --git a/src/cxx_vector.rs b/src/cxx_vector.rs
index 5fb0807..d25ea91 100644
--- a/src/cxx_vector.rs
+++ b/src/cxx_vector.rs
@@ -1,7 +1,7 @@
use crate::cxx_string::CxxString;
use core::ffi::c_void;
use core::fmt::{self, Display};
-use core::marker::PhantomData;
+use core::marker::{PhantomData, PhantomPinned};
use core::mem;
use core::ptr;
use core::slice;
@@ -17,6 +17,7 @@
#[repr(C, packed)]
pub struct CxxVector<T> {
_private: [T; 0],
+ _pinned: PhantomData<PhantomPinned>,
}
impl<T> CxxVector<T>
diff --git a/src/opaque.rs b/src/opaque.rs
index bad57e7..3c8f536 100644
--- a/src/opaque.rs
+++ b/src/opaque.rs
@@ -1,3 +1,4 @@
+use core::marker::{PhantomData, PhantomPinned};
use core::mem;
// . size = 0
@@ -5,9 +6,11 @@
// . ffi-safe
// . !Send
// . !Sync
+// . !Unpin
#[repr(C, packed)]
pub struct Opaque {
_private: [*const u8; 0],
+ _pinned: PhantomData<PhantomPinned>,
}
const_assert_eq!(0, mem::size_of::<Opaque>());
diff --git a/tests/ui/opaque_autotraits.stderr b/tests/ui/opaque_autotraits.stderr
index 7ce8ae4..61e9179 100644
--- a/tests/ui/opaque_autotraits.stderr
+++ b/tests/ui/opaque_autotraits.stderr
@@ -25,3 +25,16 @@
= note: required because it appears within the type `[*const u8; 0]`
= note: required because it appears within the type `cxx::private::Opaque`
= note: required because it appears within the type `ffi::Opaque`
+
+error[E0277]: `PhantomPinned` cannot be unpinned
+ --> $DIR/opaque_autotraits.rs:17:5
+ |
+12 | fn assert_unpin<T: Unpin>() {}
+ | ----- required by this bound in `assert_unpin`
+...
+17 | assert_unpin::<ffi::Opaque>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `ffi::Opaque`, the trait `Unpin` is not implemented for `PhantomPinned`
+ |
+ = note: required because it appears within the type `PhantomData<PhantomPinned>`
+ = note: required because it appears within the type `cxx::private::Opaque`
+ = note: required because it appears within the type `ffi::Opaque`