rust-lang / rust-lang/rust-bindgen
--generate-block panics on typedef F (^Blk) when F is a function typedef
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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