rust-lang / rust-lang/rust-bindgen

Struct/union forward-declaration in a field definition gets misinterpreted as a definition

Open
#2,691 1 comment 1 reaction 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
//union forward_declared; <-- uncommenting this prevents the bug from manifesting
struct some_struct {
	union forward_declared *ptr_field;
};
Bindgen Invocation
$ RUST_BACKTRACE=1 bindgen input.h
Actual Results
panicked at bindgen/codegen/mod.rs:2148:17:
Unable to get layout information?
Expected Results

"union forward_declared" should be codegen'd into an opaque struct:

pub struct forward_declared {
    _unused: [u8; 0],
}

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

Reproduce the issue with the shown input.h and bindgen invocation, then inspect bindgen/codegen/mod.rs:2148:17 where the layout-information panic occurs. Trace how the forward-declared union used only as a pointer field is classified, and verify that generation produces an opaque forward_declared struct rather than panicking.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.