You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the FlagSet struct doesn't have a repr attribute on it, which means it's technically not FFI-safe.
When writing an extern fn which takes a FlagSet or a struct with a FlagSet field, I get the following compiler warning:
warning: `extern` fn uses type `FlagSet<ExampleFlags>`, which is not FFI-safe
--> src/lib.rs:16:43
|
16 | pub extern fn do_thing_with_flags(_flags:FlagSet<ExampleFlags>){
| ^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: `#[warn(improper_ctypes_definitions)]` on by default
Here's the complete example code I used to generate that warning:
FlagSet structs can be used in extern functions without improper_ctypes_definitions compiler warnings.
Suggestions for a technical implementation
Add #[repr(transparent)] or #[repr(C)] to the FlagSet struct. I think this would technically be considered a breaking change, although I doubt it makes any difference to the actual memory layout of a tuple struct with a single value.
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Description
Currently, the
FlagSet
struct doesn't have arepr
attribute on it, which means it's technically not FFI-safe.When writing an
extern fn
which takes aFlagSet
or a struct with aFlagSet
field, I get the following compiler warning:Here's the complete example code I used to generate that warning:
lib.rs
:Cargo.toml
:Acceptance Criteria
FlagSet
structs can be used inextern
functions withoutimproper_ctypes_definitions
compiler warnings.Suggestions for a technical implementation
Add
#[repr(transparent)]
or#[repr(C)]
to theFlagSet
struct. I think this would technically be considered a breaking change, although I doubt it makes any difference to the actual memory layout of a tuple struct with a single value.The text was updated successfully, but these errors were encountered: