forked from mozilla/uniffi-rs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Send + Sync for object types
Without this, it is possible to send types that contain non-threadsafe constructs like `RefCell` over FFI, and call methods that use them from multiple threads. Both Send and Sync are required on the inner type for Arc to implement Send itself, which is what we must guarantee to be able to move an Arc over FFI, since we can't guarantee it is kept on the same thread inside the calling code.
- Loading branch information
Showing
3 changed files
with
37 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 28 additions & 28 deletions
56
fixtures/uitests/tests/ui/interface_trait_not_sync_and_send.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
error[E0277]: `dyn Trait` cannot be shared between threads safely | ||
error[E0277]: `(dyn Trait + 'static)` cannot be shared between threads safely | ||
--> $OUT_DIR[uniffi_uitests]/trait.uniffi.rs | ||
| | ||
| ::uniffi::expand_trait_interface_support!(r#Trait); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Trait` cannot be shared between threads safely | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Trait + 'static)` cannot be shared between threads safely | ||
| | ||
= help: the trait `Sync` is not implemented for `dyn Trait` | ||
note: required by a bound in `_::{closure#0}::assert_impl_all` | ||
--> $OUT_DIR[uniffi_uitests]/trait.uniffi.rs | ||
= help: the trait `Sync` is not implemented for `(dyn Trait + 'static)` | ||
note: required by a bound in `FfiConverterArc` | ||
--> $WORKSPACE/uniffi_core/src/ffi_converter_traits.rs | ||
| | ||
| ::uniffi::expand_trait_interface_support!(r#Trait); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` | ||
| pub unsafe trait FfiConverterArc<UT>: Send + Sync { | ||
| ^^^^ required by this bound in `FfiConverterArc` | ||
= note: this error originates in the macro `::uniffi::expand_trait_interface_support` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: `dyn Trait` cannot be sent between threads safely | ||
error[E0277]: `(dyn Trait + 'static)` cannot be sent between threads safely | ||
--> $OUT_DIR[uniffi_uitests]/trait.uniffi.rs | ||
| | ||
| ::uniffi::expand_trait_interface_support!(r#Trait); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Trait` cannot be sent between threads safely | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Trait + 'static)` cannot be sent between threads safely | ||
| | ||
= help: the trait `Send` is not implemented for `dyn Trait` | ||
note: required by a bound in `_::{closure#0}::assert_impl_all` | ||
--> $OUT_DIR[uniffi_uitests]/trait.uniffi.rs | ||
= help: the trait `Send` is not implemented for `(dyn Trait + 'static)` | ||
note: required by a bound in `FfiConverterArc` | ||
--> $WORKSPACE/uniffi_core/src/ffi_converter_traits.rs | ||
| | ||
| ::uniffi::expand_trait_interface_support!(r#Trait); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` | ||
| pub unsafe trait FfiConverterArc<UT>: Send + Sync { | ||
| ^^^^ required by this bound in `FfiConverterArc` | ||
= note: this error originates in the macro `::uniffi::expand_trait_interface_support` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: `dyn ProcMacroTrait` cannot be shared between threads safely | ||
error[E0277]: `(dyn ProcMacroTrait + 'static)` cannot be shared between threads safely | ||
--> tests/ui/interface_trait_not_sync_and_send.rs:11:1 | ||
| | ||
11 | #[uniffi::export] | ||
| ^^^^^^^^^^^^^^^^^ `dyn ProcMacroTrait` cannot be shared between threads safely | ||
| ^^^^^^^^^^^^^^^^^ `(dyn ProcMacroTrait + 'static)` cannot be shared between threads safely | ||
| | ||
= help: the trait `Sync` is not implemented for `dyn ProcMacroTrait` | ||
note: required by a bound in `_::{closure#0}::assert_impl_all` | ||
--> tests/ui/interface_trait_not_sync_and_send.rs:11:1 | ||
= help: the trait `Sync` is not implemented for `(dyn ProcMacroTrait + 'static)` | ||
note: required by a bound in `FfiConverterArc` | ||
--> $WORKSPACE/uniffi_core/src/ffi_converter_traits.rs | ||
| | ||
11 | #[uniffi::export] | ||
| ^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` | ||
| pub unsafe trait FfiConverterArc<UT>: Send + Sync { | ||
| ^^^^ required by this bound in `FfiConverterArc` | ||
= note: this error originates in the attribute macro `uniffi::export` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: `dyn ProcMacroTrait` cannot be sent between threads safely | ||
error[E0277]: `(dyn ProcMacroTrait + 'static)` cannot be sent between threads safely | ||
--> tests/ui/interface_trait_not_sync_and_send.rs:11:1 | ||
| | ||
11 | #[uniffi::export] | ||
| ^^^^^^^^^^^^^^^^^ `dyn ProcMacroTrait` cannot be sent between threads safely | ||
| ^^^^^^^^^^^^^^^^^ `(dyn ProcMacroTrait + 'static)` cannot be sent between threads safely | ||
| | ||
= help: the trait `Send` is not implemented for `dyn ProcMacroTrait` | ||
note: required by a bound in `_::{closure#0}::assert_impl_all` | ||
--> tests/ui/interface_trait_not_sync_and_send.rs:11:1 | ||
= help: the trait `Send` is not implemented for `(dyn ProcMacroTrait + 'static)` | ||
note: required by a bound in `FfiConverterArc` | ||
--> $WORKSPACE/uniffi_core/src/ffi_converter_traits.rs | ||
| | ||
11 | #[uniffi::export] | ||
| ^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` | ||
| pub unsafe trait FfiConverterArc<UT>: Send + Sync { | ||
| ^^^^ required by this bound in `FfiConverterArc` | ||
= note: this error originates in the attribute macro `uniffi::export` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters