diff options
-rw-r--r-- | src/ir/analysis/derive_default.rs | 11 | ||||
-rw-r--r-- | tests/expectations/tests/no-derive-debug.rs | 5 | ||||
-rw-r--r-- | tests/expectations/tests/no-recursive-whitelisting.rs | 5 | ||||
-rw-r--r-- | tests/expectations/tests/opaque-template-inst-member-2.rs | 5 | ||||
-rw-r--r-- | tests/expectations/tests/opaque-template-inst-member.rs | 5 | ||||
-rw-r--r-- | tests/expectations/tests/opaque_pointer.rs | 5 | ||||
-rw-r--r-- | tests/expectations/tests/template.rs | 5 |
7 files changed, 19 insertions, 22 deletions
diff --git a/src/ir/analysis/derive_default.rs b/src/ir/analysis/derive_default.rs index de74177d..fe429e2a 100644 --- a/src/ir/analysis/derive_default.rs +++ b/src/ir/analysis/derive_default.rs @@ -158,7 +158,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> { } }; - if ty.is_opaque(self.ctx, item) { + if item.is_opaque(self.ctx, &()) { let layout_can_derive = ty.layout(self.ctx).map_or(true, |l| { l.opaque().can_trivially_derive_default() }); @@ -265,7 +265,8 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> { let bases_cannot_derive = info.base_members() .iter() - .any(|base| self.cannot_derive_default.contains(&base.ty)); + .any(|base| !self.ctx.whitelisted_items().contains(&base.ty) || + self.cannot_derive_default.contains(&base.ty)); if bases_cannot_derive { trace!(" base members cannot derive Default, so we can't \ either"); @@ -277,12 +278,14 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> { .any(|f| { match *f { Field::DataMember(ref data) => { - self.cannot_derive_default.contains(&data.ty()) + !self.ctx.whitelisted_items().contains(&data.ty()) || + self.cannot_derive_default.contains(&data.ty()) } Field::Bitfields(ref bfu) => { bfu.bitfields() .iter().any(|b| { - self.cannot_derive_default.contains(&b.ty()) + !self.ctx.whitelisted_items().contains(&b.ty()) || + self.cannot_derive_default.contains(&b.ty()) }) } } diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index 0de55fab..311b3767 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -9,7 +9,7 @@ /// and replacement for another type that doesn't implement it would prevent it /// from building if --no-derive-debug didn't work. #[repr(C)] -#[derive(Default, Copy)] +#[derive(Copy)] pub struct bar { pub foo: foo, pub baz: ::std::os::raw::c_int, @@ -34,3 +34,6 @@ fn bindgen_test_layout_bar() { impl Clone for bar { fn clone(&self) -> Self { *self } } +impl Default for bar { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/no-recursive-whitelisting.rs b/tests/expectations/tests/no-recursive-whitelisting.rs index abd092bc..e2aba543 100644 --- a/tests/expectations/tests/no-recursive-whitelisting.rs +++ b/tests/expectations/tests/no-recursive-whitelisting.rs @@ -6,7 +6,7 @@ pub enum Bar {} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Copy)] pub struct Foo { pub baz: *mut Bar, } @@ -25,3 +25,6 @@ fn bindgen_test_layout_Foo() { impl Clone for Foo { fn clone(&self) -> Self { *self } } +impl Default for Foo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index 9adf8ef5..65efefb2 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -5,12 +5,9 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct OpaqueTemplate { } -impl Default for OpaqueTemplate { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct ContainsOpaqueTemplate { diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index 6e239521..9f0969cd 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -5,12 +5,9 @@ #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Default, Copy, Clone)] pub struct OpaqueTemplate { } -impl Default for OpaqueTemplate { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} #[repr(C)] pub struct ContainsOpaqueTemplate { pub mBlah: [u32; 101usize], diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 8c2cab8b..feb22439 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -22,12 +22,9 @@ impl Clone for OtherOpaque { } /// <div rustbindgen opaque></div> #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct Opaque { } -impl Default for Opaque { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} #[repr(C)] #[derive(Debug, Copy)] pub struct WithOpaquePtr { diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 275f45ea..f1cc8a25 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -171,12 +171,9 @@ impl Default for PODButContainsDtor { } /// <div rustbindgen opaque> #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct Opaque { } -impl Default for Opaque { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct POD { |