Tweak opaque type repr for slightly more evocative errors

This commit is contained in:
David Tolnay 2021-05-01 14:17:32 -07:00
parent 9f0e67d98f
commit 248994aa51
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 13 additions and 9 deletions

View File

@ -486,3 +486,6 @@ chars! {
a b c d e f g h i j k l m n o p q r s t u v w x y z
__ // underscore
}
#[repr(transparent)]
struct void(core::ffi::c_void);

View File

@ -1,5 +1,6 @@
#![allow(missing_docs)]
use crate::void;
use core::marker::{PhantomData, PhantomPinned};
use core::mem;
@ -11,7 +12,7 @@ use core::mem;
// . !Unpin
#[repr(C, packed)]
pub struct Opaque {
_private: [*const u8; 0],
_private: [*const void; 0],
_pinned: PhantomData<PhantomPinned>,
}

View File

@ -1,14 +1,14 @@
error[E0277]: `*const u8` cannot be sent between threads safely
error[E0277]: `*const cxx::void` cannot be sent between threads safely
--> $DIR/opaque_autotraits.rs:13:5
|
8 | fn assert_send<T: Send>() {}
| ---- required by this bound in `assert_send`
...
13 | assert_send::<ffi::Opaque>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const u8` cannot be sent between threads safely
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const cxx::void` cannot be sent between threads safely
|
= help: within `ffi::Opaque`, the trait `Send` is not implemented for `*const u8`
= note: required because it appears within the type `[*const u8; 0]`
= help: within `ffi::Opaque`, 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 `ffi::Opaque`
--> $DIR/opaque_autotraits.rs:4:14
@ -16,17 +16,17 @@ note: required because it appears within the type `ffi::Opaque`
4 | type Opaque;
| ^^^^^^
error[E0277]: `*const u8` cannot be shared between threads safely
error[E0277]: `*const cxx::void` cannot be shared between threads safely
--> $DIR/opaque_autotraits.rs:14:5
|
9 | fn assert_sync<T: Sync>() {}
| ---- required by this bound in `assert_sync`
...
14 | assert_sync::<ffi::Opaque>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const u8` cannot be shared between threads safely
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const cxx::void` cannot be shared between threads safely
|
= help: within `ffi::Opaque`, the trait `Sync` is not implemented for `*const u8`
= note: required because it appears within the type `[*const u8; 0]`
= help: within `ffi::Opaque`, the trait `Sync` 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 `ffi::Opaque`
--> $DIR/opaque_autotraits.rs:4:14