diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-02-18 20:08:58 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-02-19 10:54:04 +0100 |
commit | ea39b98f8d0df40e853cd86c973f71a82f75b7cd (patch) | |
tree | f8a10579041b3f7b50680189f935e843907baef6 | |
parent | 0063bf31566971c61d5d1d743fcb946057318776 (diff) |
ir: Parse cursor definitions in unions as children of the union.
-rw-r--r-- | src/ir/comp.rs | 6 | ||||
-rw-r--r-- | tests/expectations/tests/anon_struct_in_union.rs | 92 | ||||
-rw-r--r-- | tests/headers/anon_struct_in_union.h | 7 |
3 files changed, 104 insertions, 1 deletions
diff --git a/src/ir/comp.rs b/src/ir/comp.rs index a4929b7a..e8c8b708 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -630,9 +630,13 @@ impl CompInfo { // anonymous, let's just assume that if the cursor we've // found is a definition it's a valid inner type. // + // Note that doing this could be always ok, but let's just + // keep the union check for now. + // // https://github.com/servo/rust-bindgen/issues/482 let is_inner_struct = cur.semantic_parent() == cursor || - cur.is_definition(); + (kind == CompKind::Union && + cur.is_definition()); if !is_inner_struct { return CXChildVisit_Continue; } diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs new file mode 100644 index 00000000..97a342cf --- /dev/null +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -0,0 +1,92 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>); +impl <T> __BindgenUnionField<T> { + #[inline] + pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } + #[inline] + pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) } +} +impl <T> ::std::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { Self::new() } +} +impl <T> ::std::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { Self::new() } +} +impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } +impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct s { + pub u: s__bindgen_ty_1, +} +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct s__bindgen_ty_1 { + pub field: __BindgenUnionField<s__bindgen_ty_1_inner>, + pub bindgen_union_field: u32, +} +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct s__bindgen_ty_1_inner { + pub b: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_s__bindgen_ty_1_inner() { + assert_eq!(::std::mem::size_of::<s__bindgen_ty_1_inner>() , 4usize , + concat ! ( "Size of: " , stringify ! ( s__bindgen_ty_1_inner ) + )); + assert_eq! (::std::mem::align_of::<s__bindgen_ty_1_inner>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( s__bindgen_ty_1_inner ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const s__bindgen_ty_1_inner ) ) . b as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( s__bindgen_ty_1_inner ) + , "::" , stringify ! ( b ) )); +} +impl Clone for s__bindgen_ty_1_inner { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_s__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<s__bindgen_ty_1>() , 4usize , concat ! ( + "Size of: " , stringify ! ( s__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<s__bindgen_ty_1>() , 4usize , concat ! + ( "Alignment of " , stringify ! ( s__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const s__bindgen_ty_1 ) ) . field as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( s__bindgen_ty_1 ) , + "::" , stringify ! ( field ) )); +} +impl Clone for s__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_s() { + assert_eq!(::std::mem::size_of::<s>() , 4usize , concat ! ( + "Size of: " , stringify ! ( s ) )); + assert_eq! (::std::mem::align_of::<s>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( s ) )); + assert_eq! (unsafe { & ( * ( 0 as * const s ) ) . u as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( s ) , "::" , stringify + ! ( u ) )); +} +impl Clone for s { + fn clone(&self) -> Self { *self } +} diff --git a/tests/headers/anon_struct_in_union.h b/tests/headers/anon_struct_in_union.h new file mode 100644 index 00000000..880a8b54 --- /dev/null +++ b/tests/headers/anon_struct_in_union.h @@ -0,0 +1,7 @@ +struct s { + union { + struct inner { + int b; + } field; + } u; +}; |