rust-lang / rust-lang/rust-bindgen

--generate-block panics on typedef F (^Blk) when F is a function typedef

Open
#3,487 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
typedef void F(int);
typedef F (^Blk);
int take(Blk b, int t);
Bindgen Invocation
$ bindgen input.h --generate-block -- -x c -std=gnu11 -fblocks
Actual Results

bindgen aborts:

panicked at bindgen/codegen/mod.rs:957:25:
invalid block typedef: Item { ... kind: Alias(...) ... }

clang accepts this (-fblocks). Blk is a block pointer whose pointee is the typedef F. --generate-block codegen of TypeKind::BlockPointer resolves the pointee with through_type_refs() only, then requires TypeKind::Function.

typedef void (^Blk)(int); does not panic (inner is already FunctionProto). The same header without --generate-block maps Blk to *mut c_void (the documented default) and does not panic.

tests/headers/blocks.hpp only uses void (^)(void) / typedef bool (^name)(...), where the inner type is already Function.

Expected Results

Do not abort. Peel the typedef (through_type_aliases() / canonical_type()) and emit *const Block<(c_int,), ()> like the direct-syntax form.

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 in bindgen/codegen/mod.rs around line 957 and inspect the TypeKind::BlockPointer path, especially its use of through_type_refs(). Compare this with through_type_aliases() and canonical_type(). Use tests/headers/blocks.hpp and the reported header as regression inputs; done means the typedef-based block no longer panics and produces the expected Block binding.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp, rust
Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.