Skip to content

Don't allow array types in extern "C" functions. #24578

Closed
@pnkfelix

Description

@pnkfelix

(imported from improperly closed bug #16221)

You cannot pass an array to or return an array from a C function.
The signature f(char x[N]) is equivalent to f(char *x) for every N in C. Therefore it is meaningless to write this in Rust, (or rather, it does not mean what a C programmer and/or FFI generation tool likely thinks it means):

    extern "C" fn f(x: [i32, ..4]); // void f(int x[4])

Option for dealing with this:

  • We can extend our existing lint to detect cases like this and warn about them.
  • We could make the extern "C" fn form reject this signature, since the expected correspondence between Rust and C does not hold here.
  • If the Rust FFI binding generation scripts/programs out there are generating this sort of code, they need to be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.P-lowLow priorityT-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