rust-lang / rust-lang/libc

Warning: <type> is not FFI-safe, after recent changes involving `#[non_exhaustive]`

Open
#4,651 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
2.6k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
69

Description

After the recent commit (9ee2d2a0f6180e092ada3f9a5960a31b290fa755) in which I added #[non_exhaustive] to kproc_info on FreeBSD 15, I get warnings like the following when I run libc-test:

warning: `extern` block uses type `libc::kinfo_proc`, which is not FFI-safe
      --> /home/jn/libc/target/debug/build/libc-test-9d66e31a05563bd6/out/ctest_output.rs:132002:62
       |
132002 |             fn ctest_field_ptr__kinfo_proc__ki_structsize(a: *const kinfo_proc) -> *mut u8;
       |                                                              ^^^^^^^^^^^^^^^^^ not FFI-safe
       |
       = note: this struct is non-exhaustive
       = note: `#[warn(improper_ctypes)]` on by default

This seems to point to a larger problem with using #[non_exhaustive] in the libc crate.

cc @tgross35

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing commit 9ee2d2a0f6180e092ada3f9a5960a31b290fa755 and reproducing the warning with libc-test. Inspect the generated ctest_output.rs references to kinfo_proc and determine how #[non_exhaustive] affects the FFI bindings. Done means establishing and implementing an FFI-safe resolution for the reported warnings, though the issue does not define a specific fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.