rust-lang / rust-lang/rust-bindgen

C++20 `char8_t[N]` panics (`Not able to resolve array element?: Recurse`); scalar `char8_t` is `u8`

Open
#3,474 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
char8_t S[4];
Bindgen Invocation
$ bindgen input.h -- -x c++ -std=c++20
Actual Results

bindgen 0.72.1 and 0.73.1 abort while parsing the array type:

panicked at bindgen/ir/ty.rs:1196:22:
Not able to resolve array element?: Recurse
panic in a function that cannot unwind
thread caused non-unwinding panic. aborting.

libclang has no CXType_Char8. A char8_t scalar is Unexposed and bindgen canonicalizes it to u8 (char8_t take(char8_t) works). A char8_t array keeps an Unexposed element type; from_clang_ty returns ParseError::Recurse, and the CXType_ConstantArray arm does .expect("Not able to resolve array element?").

The same abort happens for const char8_t S[] = u8"hi";, char8_t a[]; (incomplete), void take(char8_t a[4]);, and char8_t a[2][2];. char16_t S[4] and char32_t S[4] generate [u16; 4] / [u32; 4] and do not abort. A char8_t field or pointer does not abort.

Not #3464 (that is enum class : char8_t enumerator sign). Not #2475 (unicode character macros).

Expected Results

Do not abort. Treat char8_t[N] as [u8; N], matching the scalar char8_tu8 mapping.

Environment
bindgen: 0.72.1 and 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 by reproducing the bindgen input and invocation from the issue, then inspect bindgen/ir/ty.rs around from_clang_ty and the CXType_ConstantArray handling near line 1196. Trace why scalar char8_t becomes u8 while an array element returns ParseError::Recurse. Done means the listed char8_t array forms no longer abort and the fixed-size case generates [u8; 4].

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.