-
-
Notifications
You must be signed in to change notification settings - Fork 9
Closed
Description
As you known, when we declare a foreign type that implements Send
and Sync
foreign_type! {
/// A Foo.
pub unsafe type Foo
: Sync + Send // optional
{
type CType = foo_sys::FOO;
fn drop = foo_sys::FOO_free;
fn clone = foo_sys::FOO_duplicate; // optional
}
}
It will generate a type that wrap the NonNull<T>
.
pub struct FooRef(Opaque);
unsafe impl ForeignTypeRef for FooRef {
type CType = foo_sys::FOO;
}
pub struct Foo(NonNull<foo_sys::FOO>);
unsafe impl Sync for FooRef {}
unsafe impl Send for FooRef {}
unsafe impl Sync for Foo {}
unsafe impl Send for Foo {}
Then the nightly clippy
will give a non_send_fields_in_send_ty
warning, because NonNull<T>
is !Send
and !Sync
.
|
13 | / foreign_type! {
14 | | /// A compiled pattern database that can then be used to scan data.
15 | | pub unsafe type Database<T>: Send + Sync {
16 | | type CType = ffi::hs_database_t;
... |
20 | | }
21 | | }
| |_^
|
= note: `#[warn(clippy::non_send_fields_in_send_ty)]` on by default
note: the type of field `0` is `!Send`
We need a Send
/Sync
wrapper instead of NonNull<T>
, maybe change to use UnsafeCell<NonNull<T>>
?
Metadata
Metadata
Assignees
Labels
No labels