rust-lang / rust-lang/rust-bindgen
Inconsistent opaque type representation
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
template <class a> class Range { a b, c; };
typedef Range<const char *> StringPiece;
typedef Range<char> MutableStringPiece;
Range<char const *> d() {}
Bindgen Invocation
$ bindgen input.h --whitelist-type '(Mutable)?StringPiece' --generate=types --opaque-type '(Mutable)?StringPiece' --no-layout-tests -- -x c++ -std=gnu++14
Actual Results
/* automatically generated by rust-bindgen */
pub type StringPiece = [u64; 2usize];
pub type MutableStringPiece = u8;
Expected Results
pub type StringPiece = [u64; 2usize];
pub type MutableStringPiece = [u64; 2usize];
StringPiece has a Rust type which correctly reflects its representation: [u64; 2size], which allows the Rust version of the type to be moved around etc. The MutableStringPiece is misrepresented by u8, which results in runtime errors because only the first byte is moved.
It looks like the d() function is what makes the difference; if I remove this then both StringPiece and MutableStringPiece get the same incorrect u8 representation.
This seems to be a regression introduced about 0.31, but I haven't checked specifically.
cc @kulshrax
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 issue with the shown input.h contents and bindgen invocation, then compare the generated StringPiece and MutableStringPiece aliases. Trace the opaque-type representation path, including the effect of d(), and verify that both aliases preserve the expected [u64; 2usize] representation without the first-byte-only behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100