Closed
Description
Recent changes appear to generate new warnings for the improper_ctypes
lint. Code such as this:
struct Internals {
// ...
}
#[repr(C)]
pub struct internals_t {
internals: Internals,
}
pub extern "C" fn internals_new() -> *mut internals_t {
loop {}
}
now generates the warning:
warning: `extern` fn uses type `Internals`, which is not FFI-safe
--> src/lib.rs:10:38
|
10 | pub extern "C" fn internals_new() -> *mut internals_t {
| ^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: `#[warn(improper_ctypes)]` on by default
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
note: type defined here
--> src/lib.rs:1:1
|
1 | / struct Internals {
2 | |
3 | | }
| |_^
This pattern can be quite common if a Rust library is exposing a C interface. Many pointer types moving across the boundary are intentionally opaque to the C side of the interface, so there's no need for #[repr(C)]
The lint, however, now generates thousands of warnings on these crates and has to basically be shut off entirely, removing the usefulness of the lint in the first place.