Add a new
FFISafe trait that is implemented exclusively for FFI-safe types.
In an earlier variadics PR,
I was trying to implement
VaList::arg::<T> for the set of all FFI-safe types, i.e.,
the types allowed by the
improper_ctypes lint, and exclude FFI-unsafe types like fat pointers.
The issue I ran into is that the lint runs before monomorphization and does not
handle type parameters, so it would never complain about using
a FFI-unsafe type.
One solution would be for the compiler and
libcore to provide a
trait implemented exclusively for all FFI-safe types. If that were available,
VaList::arg could be implemented as
libcore would provide a
FFISafe auto trait which is implemented for the
following types (same as the types supported by
- FFI-safe primitive types:
bool, integers, floats, never-type
- Pointers, references and arrays of FFI-safe types
- FFI-safe function pointers
- Foreign types (more specifically, pointers to foreign types are FFI-safe thin pointers)
#[repr(C)]or transparent structures, unions and enums containing only FFI-safe fields (with a few edge cases)
FFISafe is implemented for foreign types and has a few additional
restrictions, e.g., checking for
#[repr(C)], it requires compiler support.
The trait would be automatically implemented by the compiler in the same way as
Other than implementing
VaList::arg, it's unclear what other uses this could
have. I wrote this pre-RFC to get some feedback on this, and see if anyone else
could use it.