rust-lang / rust-lang/rust-bindgen
Inner type is generated regardless whether it is needed
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
struct Outer {
struct Inner {};
Inner m;
};
struct Test {
Outer m;
};
Bindgen Invocation
$ bindgen input.hpp --opaque-type Outer --whitelist-type Test
Actual Results
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Outer {
pub _bindgen_opaque_blob: u8,
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Outer_Inner {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Outer_Inner() {
assert_eq!(::std::mem::size_of::<Outer_Inner>() , 1usize , concat ! (
"Size of: " , stringify ! ( Outer_Inner ) ));
assert_eq! (::std::mem::align_of::<Outer_Inner>() , 1usize , concat ! (
"Alignment of " , stringify ! ( Outer_Inner ) ));
}
impl Clone for Outer_Inner {
fn clone(&self) -> Self { *self }
}
#[test]
fn bindgen_test_layout_Outer() {
assert_eq!(::std::mem::size_of::<Outer>() , 1usize , concat ! (
"Size of: " , stringify ! ( Outer ) ));
assert_eq! (::std::mem::align_of::<Outer>() , 1usize , concat ! (
"Alignment of " , stringify ! ( Outer ) ));
}
impl Clone for Outer {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Test {
pub m: Outer,
}
#[test]
fn bindgen_test_layout_Test() {
assert_eq!(::std::mem::size_of::<Test>() , 1usize , concat ! (
"Size of: " , stringify ! ( Test ) ));
assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! (
"Alignment of " , stringify ! ( Test ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const Test ) ) . m as * const _ as usize } ,
0usize , concat ! (
"Alignment of field: " , stringify ! ( Test ) , "::" ,
stringify ! ( m ) ));
}
impl Clone for Test {
fn clone(&self) -> Self { *self }
}
Expected Results
In this case, we only whitelist Test struct, which references Outer. Outer is marked opaque, however, Outer_Inner is still generated while it is neither whitelisted nor referenced by anything.
Inner type should probably not be generated unless it (or probably its outer type) is whitelisted or it is referenced.
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 input.hpp and the shown bindgen invocation, then inspect the generated Rust bindings for Outer_Inner. Confirm the behavior around the whitelisted Test and opaque Outer types; done means the unneeded Outer_Inner definition and its layout test are no longer generated.
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
- 25/100