rust-lang / rust-lang/rust-bindgen
std::size_t declared with using ::size_t does not get usize treatment
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
using size_t = decltype(sizeof(0));
namespace std { inline namespace __1 {
#ifdef BROKEN
using ::size_t;
#else
using size_t = ::size_t;
#endif
}}
void foo(std::size_t i);
Bindgen Invocation
$ bindgen usize_issue.h -- -x c++ --std=c++11 -DBROKEN
Actual Results
/* automatically generated by rust-bindgen 0.69.4 */
extern "C" {
#[link_name = "\u{1}__Z3foom"]
pub fn foo(i: ::std::os::raw::c_ulong);
}
Expected Results
/* automatically generated by rust-bindgen 0.69.4 */
extern "C" {
#[link_name = "\u{1}__Z3foom"]
pub fn foo(i: usize);
}
Debugging notes
I ran this on my local m1 macbook pro using Xcode 15.1 toolchain.
Dumping the ast via --emit-clang-ast shows the working version as having a TypeAliasDecl with spelling "size_t", with type.kind = Typedef. The broken version has a UsingDeclaration with spelling "size_t" and type.kind = Invalid. I suspect the UsingDeclaration + Invalid type here is causing some issues within bindgen.
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 C++ header and bindgen command, then compare the emitted AST for the TypeAliasDecl and UsingDeclaration cases. Trace how the UsingDeclaration with an Invalid type is handled and add a regression test; done means std::size_t is emitted as Rust usize for the BROKEN case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100