Skip to content

ir: Treat char8_t as a u8 builtin - #3542

Open
ck0i wants to merge 1 commit into
rust-lang:mainfrom
ck0i:char8-t-array
Open

ck0i wants to merge 1 commit into
rust-lang:mainfrom
ck0i:char8-t-array

Conversation

@ck0i

@ck0i ck0i commented Nov 3, 2026

Copy link
Copy Markdown

Fixes #3474
Fixes #3464

Root cause

libclang has no CXType_Char8, so a char8_t type reaches build_builtin_ty as CXType_Unexposed and gets no builtin mapping. Scalar uses still came out as u8 through the fallback path, but an array element type returned ParseError::Recurse and the CXType_ConstantArray arm panicked with Not able to resolve array element?. Enum::from_ty also could not resolve the underlying type and treated it as signed, so enum class E : char8_t { HEX = u8'\xFF' } produced pub type E = i8 and E_HEX = -1.

Fix

  • In build_builtin_ty, map an unexposed type whose canonical spelling is char8_t (ignoring const/volatile) to IntKind::U8.
  • Add a char8_t.hpp test covering fixed, incomplete and nested arrays, a struct field array, a function parameter and an enum with a char8_t underlying type.
  • Add a CHANGELOG entry.

Testing

Ubuntu (WSL), libclang 21.1.8, rustc 1.99.1.

  • Before: cargo test -p bindgen-tests -- char8_t aborts with Not able to resolve array element?: Recurse.
  • After: the new test passes. The arrays come out as [u8; N] and the enum as pub type Char8Enum = u8 with Char8Enum_High = 255.
  • cargo test -p bindgen-tests -p bindgen leaves every other expectation file unchanged, and cargo +nightly fmt -- --check is clean.

libclang has no CXType_Char8, so char8_t reaches build_builtin_ty as
CXType_Unexposed and is not recognized. Array element types then fail
to resolve and bindgen panics with "Not able to resolve array
element?", and enums with a char8_t underlying type are emitted as
signed.

Map an unexposed type whose canonical spelling is char8_t to u8.

Fixes rust-lang#3474.
Fixes rust-lang#3464.
@rustbot rustbot added the A-C++ label Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants