rust-lang / rust-lang/rust-bindgen
Error when using unicode character literals
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
bindgen panics when it encounters a character literal with a Unicode escape sequence representing a codepoint greater than 128.
Input C/C++ Header
#define OK 'a'
#define PANIC_CHAR_16 u'\uAC00'
#define PANIC_CHAR_32 U'\uAC00'
Bindgen Invocation
$ bindgen input.h -- -x c++
$ cargo run -p bindgen-cli -- input.h -- -x c++
Actual Results
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `3`,
right: `1`', /Users/paxbun/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/ir/var.rs:235:33
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: core::panicking::assert_failed_inner
3: core::panicking::assert_failed
4: <bindgen::ir::var::Var as bindgen::parse::ClangSubItemParser>::parse
5: <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::parse
6: bindgen::parse_one
7: bindgen::clang::visit_children
8: __ZN5clang8cxcursor13CursorVisitor5VisitE8CXCursorb
9: __ZN5clang8cxcursor13CursorVisitor25visitPreprocessedEntitiesINS_19PreprocessingRecord8iteratorEEEbT_S5_RS3_NS_6FileIDE
10: __ZN5clang8cxcursor13CursorVisitor13VisitChildrenE8CXCursor
11: _clang_visitChildren
12: clang_sys::clang_visitChildren
13: bindgen::Builder::generate
14: std::panicking::try
15: bindgen::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Expected Results
/* automatically generated by rust-bindgen 0.64.0 */
pub const OK: u8 = 97u8;
pub const PANIC_CHAR_16: u16 = 44032; // u16 because its counterpart is char16_t
pub const PANIC_CHAR_32: u32 = 44032; // u32 similarly
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
Reproduce the panic with the C++ header and bindgen invocation in the issue, then inspect src/ir/var.rs around the reported assertion at line 235. Trace how the u'\uAC00' and U'\uAC00' literals are parsed; done means generation completes and produces u16 and u32 constants with value 44032, without regressing the plain 'a' case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100