rust-lang / rust-lang/rust-bindgen

Disallow passing `_Complex` by value

Open
#3,255 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

As seen in https://github.com/rust-lang/rfcs/issues/793 and https://github.com/rust-lang/libc/issues/355, C’s _Complex has a different ABI (but not layout) to what Bindgen currently generates, which is:

#[derive(PartialEq, Copy, Clone, Hash, Debug, Default)]
#[repr(C)]
pub struct __BindgenComplex<T> {
    pub re: T,
    pub im: T,
}

As a soundness fix, I suggest erroring when the user attempts to use _Complex by value. Maybe this could be done with a flag to disable it if the user really wants the potentially-unsound behaviour?

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 tracing bindgen's handling of C _Complex and read the referenced Rust RFC and libc issue for the ABI distinction. Determine where by-value uses are represented and how related diagnostics are tested. Done means such uses are rejected, with the issue's proposed opt-out behavior resolved explicitly.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.