Skip to content

Zero-sized structs should be FFI-safe #17679

Closed
@mzabaluev

Description

@mzabaluev

If I get a struct by pointer from a foreign library, and I know the structure cannot safely be copied because the actual object is larger than the struct, I want to declare it as something like this:

#[repr(C)]
struct A {
    // ...
    no_copy: std::kinds::marker::NoCopy;
}

Now the compiler complains at use site that the struct is not foreign-function-safe.
As the markers are zero-sized, they have no bearing on the layout and no consequences for the structure data, so they, as long as any other zero-sized structures, should not waive FFS.

@thestinger suggests the same should apply to structures with one field as well, but I'm not so certain about that: there could be optimizations regarding alignment which would not be compatible with the (default) C ABI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions