Skip to content

improper_ctypes lint triggers on valid #[repr(transparent)] types #115457

Open
@madsmtm

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.

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-reprArea: the `#[repr(stuff)]` attributeC-bugCategory: This is a bug.L-improper_ctypesLint: improper_ctypesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions