Description
Currently when the lint finds a repr(Rust) struct, enum, or union that is not FFI-safe, it generally suggests some repr attributes that could be applied to a struct/enum/union that would make it FFI-safe, which is nice. However, it bases these suggestions only on the kind of data type, without checking whether the attribute could actually be applied to the specific type.
For example, when compiling this code:
struct Rgb(u8, u8, u8);
extern "C" {
fn get_color(name: *const u8) -> Rgb;
}
The compiler suggests repr(transparent)
alongside repr(C)
, but applying this suggestion will cause an error because the struct has multiple non-ZST fields.
Arguably the compiler should first check whether the suggestion "makes sense", and not suggest repr(transparent)
in cases such as this one. Although it probably should continue to suggesting repr(C)
even if that would then lead to another improper_ctypes about a field of the affected type (the user might want to repeatedly apply those suggestions to mark all necessary types as repr(C)
).