improper_ctypes
lint triggers on valid #[repr(transparent)]
types #115457
Open
Description
Code
#[repr(C)]
pub struct Foo {
inner: [u8; 0]
}
extern "C" {
// Lint does not trigger, as expected
pub fn foo(_: &Foo);
}
#[repr(transparent)]
pub struct Bar(Foo);
extern "C" {
// Lint triggers unexpectedly
pub fn bar(_: &Bar);
}
Current output
warning: `extern` block uses type `Bar`, which is not FFI-safe
--> <source>:16:19
|
16 | pub fn bar(_: &Bar);
| ^^^^ not FFI-safe
|
= note: this struct contains only zero-sized fields
note: the type is defined here
--> <source>:12:1
|
12 | pub struct Bar(Foo);
| ^^^^^^^^^^^^^^
= note: `#[warn(improper_ctypes)]` on by default
warning: 1 warning emitted
Desired output
The lint should not fire
Rationale and extra context
Reproducible from Rust 1.57.0 (where #[repr(transparent)]
on a zero-sized struct was made valid) to the current nightly-2023-08-31
.