diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-08-17 01:43:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-17 01:43:41 -0500 |
commit | f64606fbddecefe681ac2d29a1bb5253d50befbf (patch) | |
tree | 577b7daaaf03f0cac349e88239b3b215c50761a8 | |
parent | eab08be8164bb37ff52bfcb5e739dec58ce9434b (diff) | |
parent | ed92708c1ab8b46eab62c0d96ab498784fc9f8c1 (diff) |
Auto merge of #33 - emilio:union-dtor, r=Manishearth
Unions with destructors.
r? @Manishearth
-rw-r--r-- | src/types.rs | 12 | ||||
-rw-r--r-- | tests/expectations/union_dtor.rs | 47 | ||||
-rw-r--r-- | tests/headers/union_dtor.hpp | 5 |
3 files changed, 60 insertions, 4 deletions
diff --git a/src/types.rs b/src/types.rs index 30a4f454..9eaa3eb8 100644 --- a/src/types.rs +++ b/src/types.rs @@ -681,13 +681,17 @@ impl CompInfo { if self.no_copy { return false; } + + // NOTE: Take into account that while unions in C and C++ are copied by + // default, the may have an explicit destructor in C++, so we can't + // defer this check just for the union case. + if self.has_destructor() { + return false; + } + match self.kind { CompKind::Union => true, CompKind::Struct => { - if self.has_destructor() { - return false; - } - // With template args, use a safe subset of the types, // since copyability depends on the types itself. self.ref_template.as_ref().map_or(true, |t| t.can_derive_copy()) && diff --git a/tests/expectations/union_dtor.rs b/tests/expectations/union_dtor.rs new file mode 100644 index 00000000..c1e260da --- /dev/null +++ b/tests/expectations/union_dtor.rs @@ -0,0 +1,47 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[derive(Copy, Debug)] +#[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() } +} +#[repr(C)] +#[derive(Debug)] +pub struct Union_UnionWithDtor { + pub mFoo: __BindgenUnionField<::std::os::raw::c_int>, + pub mBar: __BindgenUnionField<*mut ::std::os::raw::c_void>, + pub _bindgen_data_: u64, +} +impl Union_UnionWithDtor { + pub unsafe fn mFoo(&mut self) -> *mut ::std::os::raw::c_int { + let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); + ::std::mem::transmute(raw.offset(0)) + } + pub unsafe fn mBar(&mut self) -> *mut *mut ::std::os::raw::c_void { + let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); + ::std::mem::transmute(raw.offset(0)) + } +} +#[test] +fn bindgen_test_layout_Union_UnionWithDtor() { + assert_eq!(::std::mem::size_of::<Union_UnionWithDtor>() , 8usize); + assert_eq!(::std::mem::align_of::<Union_UnionWithDtor>() , 8usize); +} diff --git a/tests/headers/union_dtor.hpp b/tests/headers/union_dtor.hpp new file mode 100644 index 00000000..399dc89d --- /dev/null +++ b/tests/headers/union_dtor.hpp @@ -0,0 +1,5 @@ +union UnionWithDtor { + ~UnionWithDtor(); + int mFoo; + void* mBar; +}; |