rust-lang / rust-lang/rust-bindgen

--wrap-static-fns emits incomplete struct _bindgen_ty_N for anonymous record parameters

Open
#3,480 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

Input C/C++ Header
static int take(struct { int x; int y; } s, int t) { return s.x + t; }
Bindgen Invocation
$ bindgen input.h --wrap-static-fns --wrap-static-fns-path wrap -- -x c -std=gnu11
Actual Results

bindgen exits 0. The generated wrapper is:

#include "input.h"

int take__extern(struct _bindgen_ty_1 s, int t) { return take(s, t); }

struct _bindgen_ty_1 is not in the header. clang:

wrap.c:5:25: warning: declaration of 'struct _bindgen_ty_1' will not be visible outside of this function
wrap.c:5:39: error: variable has incomplete type 'struct _bindgen_ty_1'

codegen/serialize.rs prints struct {canonical_name} for TypeKind::Comp. For an anonymous record that name is _bindgen_ty_N. A named struct S { int x; int y; } wrapper prints struct S and compiles.

Same thing for an anonymous union (union _bindgen_ty_1).

This is not #3403 (pointer-to-array declarators) or #2805 (_Bool vs bool).

Expected Results

The wrapper should use a C type that is complete after #include "input.h" (the original anonymous type, or a tag defined in the wrapper).

Environment
bindgen: 0.73.1 (rust-lang/rust-bindgen 77cbc723)
clang/libclang: Homebrew clang 21.1.8
rustc: 1.97.1
target: aarch64-apple-darwin
OS: macOS

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 with codegen/serialize.rs, especially the TypeKind::Comp handling that emits struct or union names, and reproduce the issue with the bindgen command in the report. Check the generated wrapper for anonymous struct and union parameters; done means the wrapper uses a complete type after including input.h while named-record wrapping continues to compile.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.