Skip to content

The improper_ctypes lint is too noisy to be useful #66373

Closed
@alexcrichton

Description

@alexcrichton

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language 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