diff options
author | Flier Lu <flier.lu@gmail.com> | 2017-02-05 17:12:05 +0800 |
---|---|---|
committer | Flier Lu <flier.lu@gmail.com> | 2017-02-08 10:54:55 +0800 |
commit | 25b68ba8bda4cdacaf7f04260f91709233fe0d45 (patch) | |
tree | c447db1ada409f4929d7f621ca0f077fc1a59ff6 | |
parent | 16cc5bfe1891e762c9e70fdd267b0e46bdb4330b (diff) |
implement Default trait
161 files changed, 968 insertions, 204 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 0fdfaad0..5ee43173 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -8,7 +8,7 @@ use aster; use ir::annotations::FieldAccessorKind; use ir::comp::{Base, CompInfo, CompKind, Field, Method, MethodKind}; use ir::context::{BindgenContext, ItemId}; -use ir::derive::{CanDeriveCopy, CanDeriveDebug}; +use ir::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; use ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; use ir::function::{Function, FunctionSig}; use ir::int::IntKind; @@ -688,10 +688,16 @@ impl<'a> CodeGenerator for Vtable<'a> { assert_eq!(item.id(), self.item_id); // For now, generate an empty struct, later we should generate function // pointers and whatnot. + let mut attributes = vec![attributes::repr("C")]; + + if ctx.options().derive_default { + attributes.push(attributes::derives(&["Default"])) + } + let vtable = aster::AstBuilder::new() .item() .pub_() - .with_attr(attributes::repr("C")) + .with_attrs(attributes) .struct_(self.canonical_name(ctx)) .build(); result.push(vtable); @@ -879,6 +885,7 @@ impl CodeGenerator for CompInfo { let mut attributes = vec![]; let mut needs_clone_impl = false; + let mut needs_default_impl = false; if ctx.options().generate_comments { if let Some(comment) = item.comment() { attributes.push(attributes::doc(comment)); @@ -896,6 +903,12 @@ impl CodeGenerator for CompInfo { derives.push("Debug"); } + if item.can_derive_default(ctx, ()) { + derives.push("Default"); + } else { + needs_default_impl = ctx.options().derive_default; + } + if item.can_derive_copy(ctx, ()) && !item.annotations().disallow_copy() { derives.push("Copy"); @@ -1440,8 +1453,14 @@ impl CodeGenerator for CompInfo { // NB: We can't use to_rust_ty here since for opaque types this tries to // use the specialization knowledge to generate a blob field. - let ty_for_impl = - aster::AstBuilder::new().ty().path().id(&canonical_name).build(); + let ty_for_impl = aster::AstBuilder::new() + .ty() + .path() + .segment(&canonical_name) + .with_generics(generics.clone()) + .build() + .build(); + if needs_clone_impl { let impl_ = quote_item!(ctx.ext_cx(), impl X { @@ -1467,6 +1486,32 @@ impl CodeGenerator for CompInfo { result.push(clone_impl); } + if needs_default_impl { + let prefix = ctx.trait_prefix(); + let impl_ = quote_item!(ctx.ext_cx(), + impl X { + fn default() -> Self { unsafe { ::$prefix::mem::zeroed() } } + } + ); + + let impl_ = match impl_.unwrap().node { + ast::ItemKind::Impl(_, _, _, _, _, ref items) => items.clone(), + _ => unreachable!(), + }; + + let default_impl = aster::AstBuilder::new() + .item() + .impl_() + .trait_() + .id("Default") + .build() + .with_generics(generics.clone()) + .with_items(impl_) + .build_ty(ty_for_impl.clone()); + + result.push(default_impl); + } + if !methods.is_empty() { let methods = aster::AstBuilder::new() .item() @@ -2582,6 +2627,7 @@ mod utils { let incomplete_array_decl = quote_item!(ctx.ext_cx(), #[repr(C)] + #[derive(Default)] pub struct __IncompleteArrayField<T>( ::$prefix::marker::PhantomData<T>); ) diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 53efd278..1ca39559 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -2,7 +2,7 @@ use super::annotations::Annotations; use super::context::{BindgenContext, ItemId}; -use super::derive::{CanDeriveCopy, CanDeriveDebug}; +use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; use super::item::Item; use super::layout::Layout; use super::ty::Type; @@ -171,6 +171,14 @@ impl CanDeriveDebug for Field { } } +impl CanDeriveDefault for Field { + type Extra = (); + + fn can_derive_default(&self, ctx: &BindgenContext, _: ()) -> bool { + self.ty.can_derive_default(ctx, ()) + } +} + impl<'a> CanDeriveCopy<'a> for Field { type Extra = (); @@ -296,6 +304,10 @@ pub struct CompInfo { /// around the template arguments. detect_derive_debug_cycle: Cell<bool>, + /// Used to detect if we've run in a can_derive_default cycle while cycling + /// around the template arguments. + detect_derive_default_cycle: Cell<bool>, + /// Used to detect if we've run in a has_destructor cycle while cycling /// around the template arguments. detect_has_destructor_cycle: Cell<bool>, @@ -326,6 +338,7 @@ impl CompInfo { is_anonymous: false, found_unknown_attr: false, detect_derive_debug_cycle: Cell::new(false), + detect_derive_default_cycle: Cell::new(false), detect_has_destructor_cycle: Cell::new(false), is_forward_declaration: false, } @@ -952,6 +965,52 @@ impl CanDeriveDebug for CompInfo { } } +impl CanDeriveDefault for CompInfo { + type Extra = Option<Layout>; + + fn can_derive_default(&self, + ctx: &BindgenContext, + layout: Option<Layout>) + -> bool { + // We can reach here recursively via template parameters of a member, + // for example. + if self.detect_derive_default_cycle.get() { + warn!("Derive default cycle detected!"); + return true; + } + + if self.kind == CompKind::Union { + if ctx.options().unstable_rust { + return false; + } + + return layout.unwrap_or_else(Layout::zero) + .opaque() + .can_derive_debug(ctx, ()); + } + + self.detect_derive_default_cycle.set(true); + + let can_derive_default = !self.has_vtable(ctx) && + !self.needs_explicit_vtable(ctx) && + self.base_members + .iter() + .all(|base| base.ty.can_derive_default(ctx, ())) && + self.template_args + .iter() + .all(|id| id.can_derive_default(ctx, ())) && + self.fields + .iter() + .all(|f| f.can_derive_default(ctx, ())) && + self.ref_template + .map_or(true, |id| id.can_derive_default(ctx, ())); + + self.detect_derive_default_cycle.set(false); + + can_derive_default + } +} + impl<'a> CanDeriveCopy<'a> for CompInfo { type Extra = (&'a Item, Option<Layout>); diff --git a/src/ir/context.rs b/src/ir/context.rs index 38ecdf17..a7482394 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1,6 +1,6 @@ //! Common context that is passed around during parsing and codegen. -use super::derive::{CanDeriveCopy, CanDeriveDebug}; +use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; use super::int::IntKind; use super::item::{Item, ItemCanonicalPath}; use super::item_kind::ItemKind; @@ -42,6 +42,14 @@ impl CanDeriveDebug for ItemId { } } +impl CanDeriveDefault for ItemId { + type Extra = (); + + fn can_derive_default(&self, ctx: &BindgenContext, _: ()) -> bool { + ctx.resolve_item(*self).can_derive_default(ctx, ()) + } +} + impl<'a> CanDeriveCopy<'a> for ItemId { type Extra = (); diff --git a/src/ir/derive.rs b/src/ir/derive.rs index d13a8117..6d9f368b 100644 --- a/src/ir/derive.rs +++ b/src/ir/derive.rs @@ -65,3 +65,24 @@ pub trait CanDeriveCopy<'a> { extra: Self::Extra) -> bool; } + +/// A trait that encapsulates the logic for whether or not we can derive `Default` +/// for a given thing. +/// +/// This should ideally be a no-op that just returns `true`, but instead needs +/// to be a recursive method that checks whether all the proper members can +/// derive default or not, because of the limit rust has on 32 items as max in the +/// array. +pub trait CanDeriveDefault { + /// Implementations can define this type to get access to any extra + /// information required to determine whether they can derive `Default`. If + /// extra information is unneeded, then this should simply be the unit type. + type Extra; + + /// Return `true` if `Default` can be derived for this thing, `false` + /// otherwise. + fn can_derive_default(&self, + ctx: &BindgenContext, + extra: Self::Extra) + -> bool; +}
\ No newline at end of file diff --git a/src/ir/item.rs b/src/ir/item.rs index a5d10e41..c8de95c0 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -2,7 +2,7 @@ use super::annotations::Annotations; use super::context::{BindgenContext, ItemId}; -use super::derive::{CanDeriveCopy, CanDeriveDebug}; +use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; use super::function::Function; use super::item_kind::ItemKind; use super::module::Module; @@ -235,6 +235,26 @@ impl CanDeriveDebug for Item { } } +impl CanDeriveDefault for Item { + type Extra = (); + + fn can_derive_default(&self, ctx: &BindgenContext, _: ()) -> bool { + ctx.options().derive_default && + match self.kind { + ItemKind::Type(ref ty) => { + if self.is_opaque(ctx) { + ty.layout(ctx) + .map_or(false, + |l| l.opaque().can_derive_default(ctx, ())) + } else { + ty.can_derive_default(ctx, ()) + } + } + _ => false, + } + } +} + impl<'a> CanDeriveCopy<'a> for Item { type Extra = (); diff --git a/src/ir/layout.rs b/src/ir/layout.rs index e8c6c32b..03d43b51 100644 --- a/src/ir/layout.rs +++ b/src/ir/layout.rs @@ -1,7 +1,7 @@ //! Intermediate representation for the physical layout of some type. use super::context::BindgenContext; -use super::derive::{CanDeriveCopy, CanDeriveDebug}; +use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT; use std::cmp; @@ -79,6 +79,15 @@ impl CanDeriveDebug for Opaque { } } +impl CanDeriveDefault for Opaque { + type Extra = (); + + fn can_derive_default(&self, _: &BindgenContext, _: ()) -> bool { + self.array_size() + .map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) + } +} + impl<'a> CanDeriveCopy<'a> for Opaque { type Extra = (); diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 5903430c..c3a35f0f 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -2,7 +2,7 @@ use super::comp::CompInfo; use super::context::{BindgenContext, ItemId}; -use super::derive::{CanDeriveCopy, CanDeriveDebug}; +use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; use super::enum_ty::Enum; use super::function::FunctionSig; use super::int::IntKind; @@ -412,6 +412,39 @@ impl CanDeriveDebug for Type { } } +impl CanDeriveDefault for Type { + type Extra = (); + + fn can_derive_default(&self, ctx: &BindgenContext, _: ()) -> bool { + match self.kind { + TypeKind::Array(t, len) => { + len <= RUST_DERIVE_IN_ARRAY_LIMIT && + t.can_derive_default(ctx, ()) + } + TypeKind::ResolvedTypeRef(t) | + TypeKind::TemplateAlias(t, _) | + TypeKind::Alias(t) => t.can_derive_default(ctx, ()), + TypeKind::Comp(ref info) => { + info.can_derive_default(ctx, self.layout(ctx)) + } + TypeKind::Void | + TypeKind::Named | + TypeKind::TemplateRef(..) | + TypeKind::Reference(..) | + TypeKind::NullPtr | + TypeKind::Pointer(..) | + TypeKind::BlockPointer | + TypeKind::ObjCInterface(..) | + TypeKind::Enum(..) => false, + TypeKind::Function(..) | + TypeKind::Int(..) | + TypeKind::Float(..) | + TypeKind::Complex(..) => true, + TypeKind::UnresolvedTypeRef(..) => unreachable!(), + } + } +} + impl<'a> CanDeriveCopy<'a> for Type { type Extra = &'a Item; @@ -320,6 +320,12 @@ impl Builder { self } + /// Set whether `Default` should be derived by default. + pub fn derive_default(mut self, doit: bool) -> Self { + self.options.derive_default = doit; + self + } + /// Emit Clang AST. pub fn emit_clang_ast(mut self) -> Builder { self.options.emit_ast = true; @@ -496,6 +502,10 @@ pub struct BindgenOptions { /// and types. pub derive_debug: bool, + /// True if we shold derive Default trait implementations for C/C++ structures + /// and types. + pub derive_default: bool, + /// True if we can use unstable Rust code in the bindings, false if we /// cannot. pub unstable_rust: bool, @@ -581,6 +591,7 @@ impl Default for BindgenOptions { emit_ast: false, emit_ir: false, derive_debug: true, + derive_default: false, enable_cxx_namespaces: false, disable_name_namespacing: false, unstable_rust: true, diff --git a/src/options.rs b/src/options.rs index 8d11be2d..cc5f4845 100644 --- a/src/options.rs +++ b/src/options.rs @@ -42,6 +42,13 @@ pub fn builder_from_flags<I>(args: I) Arg::with_name("no-derive-debug") .long("no-derive-debug") .help("Avoid deriving Debug on any type."), + Arg::with_name("no-derive-default") + .long("no-derive-default") + .hidden(true) + .help("Avoid deriving Default on any type."), + Arg::with_name("with-derive-default") + .long("with-derive-default") + .help("Deriving Default on any type."), Arg::with_name("no-doc-comments") .long("no-doc-comments") .help("Avoid including doc comments in the output, see: \ @@ -212,6 +219,14 @@ pub fn builder_from_flags<I>(args: I) builder = builder.derive_debug(false); } + if matches.is_present("with-derive-default") { + builder = builder.derive_default(true); + } + + if matches.is_present("no-derive-default") { + builder = builder.derive_default(false); + } + if let Some(prefix) = matches.value_of("ctypes-prefix") { builder = builder.ctypes_prefix(prefix); } diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index b9dd74e3..2ab00679 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -29,21 +29,21 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_ipv4_tuple { pub src_addr: u32, pub dst_addr: u32, pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_ipv4_tuple__bindgen_ty_1 { pub __bindgen_anon_1: __BindgenUnionField<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>, pub sctp_tag: __BindgenUnionField<u32>, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, @@ -116,21 +116,21 @@ impl Clone for rte_ipv4_tuple { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_ipv6_tuple { pub src_addr: [u8; 16usize], pub dst_addr: [u8; 16usize], pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_ipv6_tuple__bindgen_ty_1 { pub __bindgen_anon_1: __BindgenUnionField<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>, pub sctp_tag: __BindgenUnionField<u32>, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, @@ -227,3 +227,6 @@ fn bindgen_test_layout_rte_thash_tuple() { impl Clone for rte_thash_tuple { fn clone(&self) -> Self { *self } } +impl Default for rte_thash_tuple { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/381-decltype-alias.rs b/tests/expectations/tests/381-decltype-alias.rs index 766be3bc..45b0cfdd 100644 --- a/tests/expectations/tests/381-decltype-alias.rs +++ b/tests/expectations/tests/381-decltype-alias.rs @@ -10,3 +10,6 @@ pub struct std_allocator_traits<_Alloc> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<_Alloc>, } +impl <_Alloc> Default for std_allocator_traits<_Alloc> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index c0d95bfb..753188bd 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct SomeAccessors { pub mNoAccessor: ::std::os::raw::c_int, /** <div rustbindgen accessor></div> */ @@ -70,7 +70,7 @@ impl SomeAccessors { } /** <div rustbindgen accessor></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct AllAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, @@ -116,7 +116,7 @@ impl AllAccessors { } /** <div rustbindgen accessor="unsafe"></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct AllUnsafeAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, @@ -164,7 +164,7 @@ impl AllUnsafeAccessors { } /** <div rustbindgen accessor></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct ContradictAccessors { pub mBothAccessors: ::std::os::raw::c_int, /** <div rustbindgen accessor="false"></div> */ @@ -231,7 +231,7 @@ impl ContradictAccessors { } /** <div rustbindgen accessor replaces="Replaced"></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Replaced { pub mAccessor: ::std::os::raw::c_int, } @@ -260,7 +260,7 @@ impl Replaced { } /** <div rustbindgen accessor></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Wrapper { pub mReplaced: Replaced, } diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index 62840b13..1ad8fd83 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -8,7 +8,7 @@ * <div rustbindgen opaque></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct D { pub _bindgen_opaque_blob: u32, } @@ -23,7 +23,7 @@ impl Clone for D { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct NotAnnotated { pub f: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index b2c7f5fc..07ea4810 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Test { pub foo: ::std::os::raw::c_int, pub bar: f32, diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index c258f7d6..31eaca83 100644 --- a/tests/expectations/tests/anon_enum_trait.rs +++ b/tests/expectations/tests/anon_enum_trait.rs @@ -27,8 +27,11 @@ pub const DataType_type_: DataType__bindgen_ty_1 = #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum DataType__bindgen_ty_1 { generic_type = 0, } +impl <_Tp> Default for DataType<_Tp> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub _address: u8, } diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index 6ded1e57..4418bc77 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -43,25 +43,28 @@ pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum TErrorResult_UnionState { HasMessage = 0, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct TErrorResult_Message<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct TErrorResult_DOMExceptionInfo<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct TErrorResult__bindgen_ty_1<T> { pub mMessage: __BindgenUnionField<*mut TErrorResult_Message<T>>, pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo<T>>, pub bindgen_union_field: u64, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for TErrorResult<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct ErrorResult { @@ -77,6 +80,9 @@ fn bindgen_test_layout_ErrorResult() { impl Clone for ErrorResult { fn clone(&self) -> Self { *self } } +impl Default for ErrorResult { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[test] fn __bindgen_test_layout_template_1() { assert_eq!(::std::mem::size_of::<TErrorResult<::std::os::raw::c_int>>() , diff --git a/tests/expectations/tests/auto.rs b/tests/expectations/tests/auto.rs index 554546af..4551f703 100644 --- a/tests/expectations/tests/auto.rs +++ b/tests/expectations/tests/auto.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub _address: u8, } @@ -26,6 +26,9 @@ pub struct Bar<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Bar<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} extern "C" { #[link_name = "_Z5Test2v"] pub fn Test2() -> ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs index 553879b7..b0c91e8c 100644 --- a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs +++ b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs @@ -10,8 +10,11 @@ pub struct std_char_traits<_CharT> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<_CharT>, } +impl <_CharT> Default for std_char_traits<_CharT> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct __gnu_cxx_char_traits { pub _address: u8, } diff --git a/tests/expectations/tests/base-to-derived.rs b/tests/expectations/tests/base-to-derived.rs index 4749096b..6ff4ce9a 100644 --- a/tests/expectations/tests/base-to-derived.rs +++ b/tests/expectations/tests/base-to-derived.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct false_type { pub _address: u8, } diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs index a8d3ecc5..362cf280 100644 --- a/tests/expectations/tests/bitfield-enum-basic.rs +++ b/tests/expectations/tests/bitfield-enum-basic.rs @@ -48,7 +48,7 @@ impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 { #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct _bindgen_ty_1(pub ::std::os::raw::c_uint); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Dummy { pub _address: u8, } diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs index 94f0aa8e..0ab5fce5 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct _bindgen_ty_1 { pub _bitfield_1: u32, } diff --git a/tests/expectations/tests/canonical_path_without_namespacing.rs b/tests/expectations/tests/canonical_path_without_namespacing.rs index dff6b707..43bec38d 100644 --- a/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Bar { pub _address: u8, } diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index 46adbc29..92389cbe 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -5,6 +5,7 @@ #[repr(C)] +#[derive(Default)] pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>); impl <T> __IncompleteArrayField<T> { #[inline] @@ -81,6 +82,9 @@ fn bindgen_test_layout_C() { "Alignment of field: " , stringify ! ( C ) , "::" , stringify ! ( big_array ) )); } +impl Default for C { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] pub struct C_with_zero_length_array { pub a: ::std::os::raw::c_int, @@ -114,6 +118,9 @@ fn bindgen_test_layout_C_with_zero_length_array() { C_with_zero_length_array ) , "::" , stringify ! ( zero_length_array ) )); } +impl Default for C_with_zero_length_array { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] pub struct C_with_incomplete_array { pub a: ::std::os::raw::c_int, @@ -129,6 +136,9 @@ fn bindgen_test_layout_C_with_incomplete_array() { concat ! ( "Alignment of " , stringify ! ( C_with_incomplete_array ) )); } +impl Default for C_with_incomplete_array { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { pub a: ::std::os::raw::c_int, @@ -147,8 +157,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { "Alignment of " , stringify ! ( C_with_zero_length_array_and_incomplete_array ) )); } +impl Default for C_with_zero_length_array_and_incomplete_array { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Default)] pub struct WithDtor { pub b: ::std::os::raw::c_int, } @@ -179,8 +192,11 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { "Alignment of " , stringify ! ( IncompleteArrayNonCopiable ) )); } +impl Default for IncompleteArrayNonCopiable { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Union { pub d: __BindgenUnionField<f32>, pub i: __BindgenUnionField<::std::os::raw::c_int>, @@ -207,7 +223,7 @@ impl Clone for Union { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct WithUnion { pub data: Union, } @@ -227,7 +243,7 @@ impl Clone for WithUnion { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct RealAbstractionWithTonsOfMethods { pub _address: u8, } diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 8a4125c9..19d70e50 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A { pub member_a: ::std::os::raw::c_int, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A_B { pub member_b: ::std::os::raw::c_int, } @@ -49,7 +49,7 @@ extern "C" { pub static mut var: A_B; } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct D { pub member: A_B, } @@ -78,3 +78,9 @@ pub struct Templated<T> { pub struct Templated_Templated_inner<T> { pub member_ptr: *mut T, } +impl <T> Default for Templated_Templated_inner<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl <T> Default for Templated<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index e41e3ffc..ad532100 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct whatever { pub _address: u8, } @@ -20,7 +20,7 @@ impl Clone for whatever { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct whatever_child { pub _address: u8, } @@ -35,7 +35,7 @@ impl Clone for whatever_child { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct whatever_child_with_member { pub m_member: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/class_static.rs b/tests/expectations/tests/class_static.rs index 207295b6..521621a7 100644 --- a/tests/expectations/tests/class_static.rs +++ b/tests/expectations/tests/class_static.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct MyClass { pub _address: u8, } diff --git a/tests/expectations/tests/class_static_const.rs b/tests/expectations/tests/class_static_const.rs index 5e59485b..4b0108a1 100644 --- a/tests/expectations/tests/class_static_const.rs +++ b/tests/expectations/tests/class_static_const.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A { pub _address: u8, } diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index 9184c9c8..f4db9013 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -8,7 +8,7 @@ * <div rustbindgen="true" replaces="whatever"></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct whatever { pub replacement: ::std::os::raw::c_int, } @@ -28,7 +28,7 @@ impl Clone for whatever { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct container { pub c: whatever, } diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index 1d8e6b4d..4c1d2718 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -9,6 +9,9 @@ pub struct HandleWithDtor<T> { pub ptr: *mut T, } +impl <T> Default for HandleWithDtor<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type HandleValue = HandleWithDtor<::std::os::raw::c_int>; #[repr(C)] #[derive(Debug)] @@ -27,6 +30,9 @@ fn bindgen_test_layout_WithoutDtor() { "Alignment of field: " , stringify ! ( WithoutDtor ) , "::" , stringify ! ( shouldBeWithDtor ) )); } +impl Default for WithoutDtor { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[test] fn __bindgen_test_layout_template_1() { assert_eq!(::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>() diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 1056fd69..a99aada5 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -29,14 +29,14 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A { pub c: ::std::os::raw::c_uint, pub named_union: A__bindgen_ty_1, pub __bindgen_anon_1: A__bindgen_ty_2, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, @@ -62,7 +62,7 @@ impl Clone for A_Segment { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A__bindgen_ty_1 { pub f: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, @@ -83,7 +83,7 @@ impl Clone for A__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A__bindgen_ty_2 { pub d: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, @@ -123,12 +123,12 @@ impl Clone for A { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct B { pub d: ::std::os::raw::c_uint, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct B_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, @@ -176,20 +176,20 @@ pub enum StepSyntax { FunctionalWithEndKeyword = 3, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct C { pub d: ::std::os::raw::c_uint, pub __bindgen_anon_1: C__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct C__bindgen_ty_1 { pub mFunc: __BindgenUnionField<C__bindgen_ty_1__bindgen_ty_1>, pub __bindgen_anon_1: __BindgenUnionField<C__bindgen_ty_1__bindgen_ty_2>, pub bindgen_union_field: [u32; 4usize], } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct C__bindgen_ty_1__bindgen_ty_1 { pub mX1: f32, pub mY1: f32, @@ -264,6 +264,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { impl Clone for C__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { *self } } +impl Default for C__bindgen_ty_1__bindgen_ty_2 { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[test] fn bindgen_test_layout_C__bindgen_ty_1() { assert_eq!(::std::mem::size_of::<C__bindgen_ty_1>() , 16usize , concat ! ( @@ -280,7 +283,7 @@ impl Clone for C__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct C_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index d3141fd9..1a92b986 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -65,6 +65,9 @@ extern "C" { impl Clone for C { fn clone(&self) -> Self { *self } } +impl Default for C { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} impl C { #[inline] pub unsafe fn method(&mut self, c: C_MyInt) { C_method(&mut *self, c) } @@ -102,3 +105,6 @@ fn bindgen_test_layout_D() { impl Clone for D { fn clone(&self) -> Self { *self } } +impl Default for D { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index 1048138e..d250f6b1 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -11,7 +11,7 @@ pub struct __BindgenComplex<T> { pub im: T, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct TestDouble { pub mMember: __BindgenComplex<f64>, } @@ -50,8 +50,11 @@ fn bindgen_test_layout_TestDoublePtr() { impl Clone for TestDoublePtr { fn clone(&self) -> Self { *self } } +impl Default for TestDoublePtr { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct TestFloat { pub mMember: __BindgenComplex<f32>, } @@ -90,3 +93,6 @@ fn bindgen_test_layout_TestFloatPtr() { impl Clone for TestFloatPtr { fn clone(&self) -> Self { *self } } +impl Default for TestFloatPtr { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/const_bool.rs b/tests/expectations/tests/const_bool.rs index 2c8ba788..de9e81b0 100644 --- a/tests/expectations/tests/const_bool.rs +++ b/tests/expectations/tests/const_bool.rs @@ -6,7 +6,7 @@ pub const k: bool = true; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A { pub _address: u8, } diff --git a/tests/expectations/tests/const_enum_unnamed.rs b/tests/expectations/tests/const_enum_unnamed.rs index 8a5f0f23..b6f61b35 100644 --- a/tests/expectations/tests/const_enum_unnamed.rs +++ b/tests/expectations/tests/const_enum_unnamed.rs @@ -10,7 +10,7 @@ pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { FOO_BAR = 0, FOO_BAZ = 1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub _address: u8, } diff --git a/tests/expectations/tests/const_tparam.rs b/tests/expectations/tests/const_tparam.rs index 3ed10d28..f47ca082 100644 --- a/tests/expectations/tests/const_tparam.rs +++ b/tests/expectations/tests/const_tparam.rs @@ -10,3 +10,6 @@ pub struct C<T> { pub foo: *const T, pub bar: *mut T, } +impl <T> Default for C<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/constant-non-specialized-tp.rs b/tests/expectations/tests/constant-non-specialized-tp.rs index bbadf8a2..f2aa5a75 100644 --- a/tests/expectations/tests/constant-non-specialized-tp.rs +++ b/tests/expectations/tests/constant-non-specialized-tp.rs @@ -10,6 +10,9 @@ pub struct Test<Args> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<Args>, } +impl <Args> Default for Test<Args> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Outer<T> { @@ -17,8 +20,11 @@ pub struct Outer<T> { pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct Outer_Inner<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Outer<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index ae89a9b7..e1210d9a 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -28,3 +28,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/constructor-tp.rs b/tests/expectations/tests/constructor-tp.rs index 0f53317b..ee04d3c5 100644 --- a/tests/expectations/tests/constructor-tp.rs +++ b/tests/expectations/tests/constructor-tp.rs @@ -10,8 +10,11 @@ pub struct Foo<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Foo<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Bar { pub _address: u8, } diff --git a/tests/expectations/tests/constructors.rs b/tests/expectations/tests/constructors.rs index 3abb2da7..13a4dcf8 100644 --- a/tests/expectations/tests/constructors.rs +++ b/tests/expectations/tests/constructors.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct TestOverload { pub _address: u8, } @@ -43,7 +43,7 @@ impl TestOverload { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct TestPublicNoArgs { pub _address: u8, } diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index 5971db06..ba35da33 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -60,3 +60,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/crtp.rs b/tests/expectations/tests/crtp.rs index 8fe0a5ae..7143f50e 100644 --- a/tests/expectations/tests/crtp.rs +++ b/tests/expectations/tests/crtp.rs @@ -10,6 +10,9 @@ pub struct Base<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Base<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct Derived { @@ -25,12 +28,18 @@ fn bindgen_test_layout_Derived() { impl Clone for Derived { fn clone(&self) -> Self { *self } } +impl Default for Derived { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug)] pub struct BaseWithDestructor<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for BaseWithDestructor<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug)] pub struct DerivedFromBaseWithDestructor { @@ -46,6 +55,9 @@ fn bindgen_test_layout_DerivedFromBaseWithDestructor() { "Alignment of " , stringify ! ( DerivedFromBaseWithDestructor ) )); } +impl Default for DerivedFromBaseWithDestructor { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[test] fn __bindgen_test_layout_template_1() { assert_eq!(::std::mem::size_of::<Base<Derived>>() , 1usize , concat ! ( diff --git a/tests/expectations/tests/dash_language.rs b/tests/expectations/tests/dash_language.rs index 148f9c32..24df1014 100644 --- a/tests/expectations/tests/dash_language.rs +++ b/tests/expectations/tests/dash_language.rs @@ -10,3 +10,6 @@ pub struct Foo<T> { pub bar: ::std::os::raw::c_int, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Foo<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index 1b785fd7..196cfc46 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -11,7 +11,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Bar { pub foo: ::std::os::raw::c_int, pub baz: bool, @@ -60,5 +60,8 @@ pub mod root { 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/empty_template_param_name.rs b/tests/expectations/tests/empty_template_param_name.rs index e10b56db..6ee8fce3 100644 --- a/tests/expectations/tests/empty_template_param_name.rs +++ b/tests/expectations/tests/empty_template_param_name.rs @@ -11,3 +11,6 @@ pub struct __iterator_traits<_Iterator> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<_Iterator>, } +impl <_Iterator> Default for __iterator_traits<_Iterator> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index e372d98b..300edd39 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -10,6 +10,7 @@ pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { match_ = 0, whatever_else = 1, } #[repr(C)] +#[derive(Default)] pub struct C__bindgen_vtable { } #[repr(C)] @@ -32,3 +33,6 @@ fn bindgen_test_layout_C() { impl Clone for C { fn clone(&self) -> Self { *self } } +impl Default for C { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/enum_in_template_with_typedef.rs b/tests/expectations/tests/enum_in_template_with_typedef.rs index 66a304aa..e4725b83 100644 --- a/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -16,3 +16,6 @@ pub const std_fbstring_core_Category_Bar: std_fbstring_core_Category = #[repr(u8)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum std_fbstring_core_Category { Foo = 0, } +impl <Char> Default for std_fbstring_core<Char> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/eval-variadic-template-parameter.rs b/tests/expectations/tests/eval-variadic-template-parameter.rs index f8c937e2..acc6f34c 100644 --- a/tests/expectations/tests/eval-variadic-template-parameter.rs +++ b/tests/expectations/tests/eval-variadic-template-parameter.rs @@ -10,3 +10,6 @@ pub struct B<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for B<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index ffe5b7b6..b05984c8 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -12,6 +12,9 @@ pub struct Foo([u8; 0]); pub struct RefPtr<T> { pub m_inner: *mut T, } +impl <T> Default for RefPtr<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct Bar { @@ -32,3 +35,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/forward-inherit-struct-with-fields.rs b/tests/expectations/tests/forward-inherit-struct-with-fields.rs index e377b3ad..ce61a545 100644 --- a/tests/expectations/tests/forward-inherit-struct-with-fields.rs +++ b/tests/expectations/tests/forward-inherit-struct-with-fields.rs @@ -9,9 +9,15 @@ pub struct Rooted<T> { pub _base: js_RootedBase<T>, } +impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct js_RootedBase<T> { pub foo: *mut T, pub next: *mut Rooted<T>, } +impl <T> Default for js_RootedBase<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/forward-inherit-struct.rs b/tests/expectations/tests/forward-inherit-struct.rs index 5de70fa9..1057e70c 100644 --- a/tests/expectations/tests/forward-inherit-struct.rs +++ b/tests/expectations/tests/forward-inherit-struct.rs @@ -10,9 +10,15 @@ pub struct Rooted<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct js_RootedBase<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for js_RootedBase<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index 0637fea3..a6e67f7b 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Foo_empty { pub _address: u8, } @@ -42,6 +42,9 @@ 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() } } +} extern "C" { #[link_name = "_Z10baz_structP3Foo"] pub fn baz_struct(f: *mut Foo); diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs index 51c61cdf..ec8b15d1 100644 --- a/tests/expectations/tests/forward_declared_struct.rs +++ b/tests/expectations/tests/forward_declared_struct.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct a { pub b: ::std::os::raw::c_int, } @@ -24,7 +24,7 @@ impl Clone for a { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct c { pub d: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index eba6c7e2..ce145866 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -30,3 +30,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/in_class_typedef.rs b/tests/expectations/tests/in_class_typedef.rs index 4e95ca8c..3634a631 100644 --- a/tests/expectations/tests/in_class_typedef.rs +++ b/tests/expectations/tests/in_class_typedef.rs @@ -13,9 +13,12 @@ pub struct Foo<T> { pub type Foo_elem_type<T> = T; pub type Foo_ptr_type<T> = *mut T; #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo_Bar<T> { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Foo<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/inherit-namespaced.rs b/tests/expectations/tests/inherit-namespaced.rs index c0d2e5a6..e5d5f875 100644 --- a/tests/expectations/tests/inherit-namespaced.rs +++ b/tests/expectations/tests/inherit-namespaced.rs @@ -10,9 +10,15 @@ pub struct js_RootedBase<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for js_RootedBase<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/inherit_named.rs b/tests/expectations/tests/inherit_named.rs index 8081c649..31c4bee9 100644 --- a/tests/expectations/tests/inherit_named.rs +++ b/tests/expectations/tests/inherit_named.rs @@ -10,8 +10,14 @@ pub struct Wohoo<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Wohoo<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Weeee<T> { pub _base: T, } +impl <T> Default for Weeee<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/inherit_typedef.rs b/tests/expectations/tests/inherit_typedef.rs index ff6a62d3..76d7c35f 100644 --- a/tests/expectations/tests/inherit_typedef.rs +++ b/tests/expectations/tests/inherit_typedef.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub _address: u8, } @@ -21,7 +21,7 @@ impl Clone for Foo { } pub type TypedefedFoo = Foo; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Bar { pub _address: u8, } diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index 6b2c4f80..8f2243ba 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -13,7 +13,7 @@ pub mod root { pub type Ty = ::std::os::raw::c_int; } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Bar { pub baz: root::foo::Ty, } diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index 5b74a5f6..7cf7c264 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -18,7 +18,7 @@ pub mod root { pub type Ty = ::std::os::raw::c_longlong; } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Bar { pub baz: root::foo::bar::Ty, } diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs index 3422f168..fd2793a4 100644 --- a/tests/expectations/tests/inner_const.rs +++ b/tests/expectations/tests/inner_const.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub bar: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index 4345e422..3510fa7c 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -10,6 +10,9 @@ pub struct LinkedList<T> { pub next: *mut LinkedList<T>, pub prev: *mut LinkedList<T>, } +impl <T> Default for LinkedList<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct InstantiateIt { @@ -30,3 +33,6 @@ fn bindgen_test_layout_InstantiateIt() { impl Clone for InstantiateIt { fn clone(&self) -> Self { *self } } +impl Default for InstantiateIt { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/issue-358.rs b/tests/expectations/tests/issue-358.rs index 1b933d34..d3be3c43 100644 --- a/tests/expectations/tests/issue-358.rs +++ b/tests/expectations/tests/issue-358.rs @@ -10,6 +10,9 @@ pub struct JS_PersistentRooted<c> { pub _base: a, pub _phantom_0: ::std::marker::PhantomData<c>, } +impl <c> Default for JS_PersistentRooted<c> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct a { @@ -18,3 +21,6 @@ pub struct a { impl Clone for a { fn clone(&self) -> Self { *self } } +impl Default for a { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index 8fcfd33d..1693f46a 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -27,6 +27,9 @@ pub mod root { impl Clone for d { fn clone(&self) -> Self { *self } } + impl Default for d { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } + } #[repr(C)] #[derive(Debug, Copy)] pub struct i { @@ -59,6 +62,9 @@ pub mod root { impl Clone for i { fn clone(&self) -> Self { *self } } + impl Default for i { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } + } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum n { @@ -91,4 +97,7 @@ pub mod root { "Alignment of field: " , stringify ! ( F ) , "::" , stringify ! ( w ) )); } + impl Default for F { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } + } } diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs index a8e0d8d4..2fe0f99b 100644 --- a/tests/expectations/tests/issue-410.rs +++ b/tests/expectations/tests/issue-410.rs @@ -11,7 +11,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Value { pub _address: u8, } diff --git a/tests/expectations/tests/issue-447.rs b/tests/expectations/tests/issue-447.rs index 0582f412..7ac9d714 100644 --- a/tests/expectations/tests/issue-447.rs +++ b/tests/expectations/tests/issue-447.rs @@ -14,7 +14,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct GuardObjectNotifier { pub _address: u8, } @@ -35,7 +35,7 @@ pub mod root { } } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct JSAutoCompartment { pub _address: u8, } diff --git a/tests/expectations/tests/issue_311.rs b/tests/expectations/tests/issue_311.rs index debc893d..6576b8b5 100644 --- a/tests/expectations/tests/issue_311.rs +++ b/tests/expectations/tests/issue_311.rs @@ -8,12 +8,12 @@ pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct jsval_layout { pub __bindgen_anon_1: root::jsval_layout__bindgen_ty_1, } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct jsval_layout__bindgen_ty_1 { pub _address: u8, } diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index ac092587..848286e7 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -96,7 +96,7 @@ pub enum JSWhyMagic { JS_WHY_MAGIC_COUNT = 18, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct jsval_layout { pub asBits: __BindgenUnionField<u64>, pub debugView: __BindgenUnionField<jsval_layout__bindgen_ty_1>, @@ -125,6 +125,9 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { impl Clone for jsval_layout__bindgen_ty_1 { fn clone(&self) -> Self { *self } } +impl Default for jsval_layout__bindgen_ty_1 { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} impl jsval_layout__bindgen_ty_1 { #[inline] pub fn payload47(&self) -> u64 { @@ -157,12 +160,12 @@ impl jsval_layout__bindgen_ty_1 { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct jsval_layout__bindgen_ty_2 { pub payload: jsval_layout__bindgen_ty_2__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub i32: __BindgenUnionField<i32>, pub u32: __BindgenUnionField<u32>, @@ -269,7 +272,7 @@ impl Clone for jsval_layout { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Value { pub data: jsval_layout, } diff --git a/tests/expectations/tests/layout.rs b/tests/expectations/tests/layout.rs index 5fae570c..115a108a 100644 --- a/tests/expectations/tests/layout.rs +++ b/tests/expectations/tests/layout.rs @@ -5,6 +5,7 @@ #[repr(C)] +#[derive(Default)] pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>); impl <T> __IncompleteArrayField<T> { #[inline] @@ -37,7 +38,7 @@ impl <T> ::std::clone::Clone for __IncompleteArrayField<T> { } impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { } #[repr(C, packed)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct header { pub proto: ::std::os::raw::c_char, pub size: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 0479521c..a21fa4d6 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -5,6 +5,7 @@ #[repr(C)] +#[derive(Default)] pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>); impl <T> __IncompleteArrayField<T> { #[inline] @@ -61,8 +62,11 @@ fn bindgen_test_layout_rte_kni_fifo() { impl Clone for rte_kni_fifo { fn clone(&self) -> Self { *self } } +impl Default for rte_kni_fifo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_eth_link { /**< ETH_SPEED_NUM_ */ pub link_speed: u32, diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs index c868f627..f3c59eb4 100644 --- a/tests/expectations/tests/layout_arp.rs +++ b/tests/expectations/tests/layout_arp.rs @@ -24,7 +24,7 @@ pub const ARP_OP_INVREPLY: ::std::os::raw::c_uint = 9; * See http://standards.ieee.org/regauth/groupmac/tutorial.html */ #[repr(C, packed)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct ether_addr { /**< Addr bytes in tx order */ pub addr_bytes: [u8; 6usize], @@ -48,7 +48,7 @@ impl Clone for ether_addr { * ARP header IPv4 payload. */ #[repr(C, packed)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct arp_ipv4 { /**< sender hardware address */ pub arp_sha: ether_addr, @@ -93,7 +93,7 @@ impl Clone for arp_ipv4 { * ARP header. */ #[repr(C, packed)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct arp_hdr { pub arp_hrd: u16, pub arp_pro: u16, diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index bc690fb6..3f86cda9 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -109,11 +109,14 @@ fn bindgen_test_layout_rte_mempool_ops() { impl Clone for rte_mempool_ops { fn clone(&self) -> Self { *self } } +impl Default for rte_mempool_ops { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /** * The rte_spinlock_t type. */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct _bindgen_ty_1 { /**< lock status 0 = unlocked, 1 = locked */ pub locked: ::std::os::raw::c_int, @@ -180,6 +183,9 @@ fn bindgen_test_layout_rte_mempool_ops_table() { impl Clone for rte_mempool_ops_table { fn clone(&self) -> Self { *self } } +impl Default for rte_mempool_ops_table { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /** * Structure to hold malloc heap */ @@ -218,6 +224,9 @@ fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { impl Clone for malloc_heap__bindgen_ty_1 { fn clone(&self) -> Self { *self } } +impl Default for malloc_heap__bindgen_ty_1 { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[test] fn bindgen_test_layout_malloc_heap() { assert_eq!(::std::mem::size_of::<malloc_heap>() , 128usize , concat ! ( @@ -246,3 +255,6 @@ fn bindgen_test_layout_malloc_heap() { impl Clone for malloc_heap { fn clone(&self) -> Self { *self } } +impl Default for malloc_heap { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index be4944bb..35127399 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -108,6 +108,9 @@ fn bindgen_test_layout_cmdline_token_hdr_cmdline_token_ops() { impl Clone for cmdline_token_hdr_cmdline_token_ops { fn clone(&self) -> Self { *self } } +impl Default for cmdline_token_hdr_cmdline_token_ops { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[test] fn bindgen_test_layout_cmdline_token_hdr() { assert_eq!(::std::mem::size_of::<cmdline_token_hdr>() , 16usize , concat ! @@ -128,6 +131,9 @@ fn bindgen_test_layout_cmdline_token_hdr() { impl Clone for cmdline_token_hdr { fn clone(&self) -> Self { *self } } +impl Default for cmdline_token_hdr { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type cmdline_parse_token_hdr_t = cmdline_token_hdr; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -163,6 +169,9 @@ fn bindgen_test_layout_cmdline_token_num_data() { impl Clone for cmdline_token_num_data { fn clone(&self) -> Self { *self } } +impl Default for cmdline_token_num_data { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct cmdline_token_num { @@ -189,4 +198,7 @@ fn bindgen_test_layout_cmdline_token_num() { impl Clone for cmdline_token_num { fn clone(&self) -> Self { *self } } +impl Default for cmdline_token_num { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type cmdline_parse_token_num_t = cmdline_token_num; diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 0034e707..16788d06 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -115,6 +115,9 @@ fn bindgen_test_layout_rte_eth_rxmode() { impl Clone for rte_eth_rxmode { fn clone(&self) -> Self { *self } } +impl Default for rte_eth_rxmode { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} impl rte_eth_rxmode { #[inline] pub fn header_split(&self) -> u16 { @@ -268,6 +271,9 @@ fn bindgen_test_layout_rte_eth_txmode() { impl Clone for rte_eth_txmode { fn clone(&self) -> Self { *self } } +impl Default for rte_eth_txmode { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} impl rte_eth_txmode { #[inline] pub fn hw_vlan_reject_tagged(&self) -> u8 { @@ -358,6 +364,9 @@ fn bindgen_test_layout_rte_eth_rss_conf() { impl Clone for rte_eth_rss_conf { fn clone(&self) -> Self { *self } } +impl Default for rte_eth_rss_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(u32)] /** * This enum indicates the possible number of traffic classes @@ -403,7 +412,7 @@ pub struct rte_eth_vmdq_dcb_conf { pub dcb_tc: [u8; 8usize], } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { /**< The vlan id of the received frame */ pub vlan_id: u16, @@ -476,6 +485,9 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { "Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf ) , "::" , stringify ! ( dcb_tc ) )); } +impl Default for rte_eth_vmdq_dcb_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct rte_eth_dcb_rx_conf { @@ -505,6 +517,9 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { impl Clone for rte_eth_dcb_rx_conf { fn clone(&self) -> Self { *self } } +impl Default for rte_eth_dcb_rx_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct rte_eth_vmdq_dcb_tx_conf { @@ -536,6 +551,9 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { impl Clone for rte_eth_vmdq_dcb_tx_conf { fn clone(&self) -> Self { *self } } +impl Default for rte_eth_vmdq_dcb_tx_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct rte_eth_dcb_tx_conf { @@ -565,6 +583,9 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { impl Clone for rte_eth_dcb_tx_conf { fn clone(&self) -> Self { *self } } +impl Default for rte_eth_dcb_tx_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct rte_eth_vmdq_tx_conf { @@ -587,6 +608,9 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { impl Clone for rte_eth_vmdq_tx_conf { fn clone(&self) -> Self { *self } } +impl Default for rte_eth_vmdq_tx_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] pub struct rte_eth_vmdq_rx_conf { /**< VMDq only mode, 8 or 64 pools */ @@ -605,7 +629,7 @@ pub struct rte_eth_vmdq_rx_conf { pub pool_map: [rte_eth_vmdq_rx_conf__bindgen_ty_1; 64usize], } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { /**< The vlan id of the received frame */ pub vlan_id: u16, @@ -683,6 +707,9 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { "Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf ) , "::" , stringify ! ( pool_map ) )); } +impl Default for rte_eth_vmdq_rx_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(u32)] /** * Flow Director setting modes: none, signature or perfect. @@ -720,7 +747,7 @@ pub enum rte_fdir_status_mode { * A structure used to define the input for IPV4 flow */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_eth_ipv4_flow { /**< IPv4 source address in big endian. */ pub src_ip: u32, @@ -772,7 +799,7 @@ impl Clone for rte_eth_ipv4_flow { * A structure used to define the input for IPV6 flow */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_eth_ipv6_flow { /**< IPv6 source address in big endian. */ pub src_ip: [u32; 4usize], @@ -825,7 +852,7 @@ impl Clone for rte_eth_ipv6_flow { * to match the various fields of RX packet headers. */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_eth_fdir_masks { /**< Bit mask for vlan_tci in big endian */ pub vlan_tci_mask: u16, @@ -944,12 +971,15 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { impl Clone for rte_eth_flex_payload_cfg { fn clone(&self) -> Self { *self } } +impl Default for rte_eth_flex_payload_cfg { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /** * A structure used to define FDIR masks for flexible payload * for each flow type */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_eth_fdir_flex_mask { pub flow_type: u16, pub mask: [u8; 16usize], @@ -1022,6 +1052,9 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { impl Clone for rte_eth_fdir_flex_conf { fn clone(&self) -> Self { *self } } +impl Default for rte_eth_fdir_flex_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /** * A structure used to configure the Flow Director (FDIR) feature * of an Ethernet port. @@ -1082,11 +1115,14 @@ fn bindgen_test_layout_rte_fdir_conf() { impl Clone for rte_fdir_conf { fn clone(&self) -> Self { *self } } +impl Default for rte_fdir_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /** * A structure used to enable/disable specific device interrupts. */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_intr_conf { /** enable/disable lsc interrupt. 0 (default) - disable, 1 enable */ pub lsc: u16, @@ -1192,8 +1228,11 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { rte_eth_conf__bindgen_ty_1 ) , "::" , stringify ! ( vmdq_rx_conf ) )); } +impl Default for rte_eth_conf__bindgen_ty_1 { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_eth_conf__bindgen_ty_2 { pub vmdq_dcb_tx_conf: __BindgenUnionField<rte_eth_vmdq_dcb_tx_conf>, pub dcb_tx_conf: __BindgenUnionField<rte_eth_dcb_tx_conf>, @@ -1283,3 +1322,6 @@ fn bindgen_test_layout_rte_eth_conf() { "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , stringify ! ( intr_conf ) )); } +impl Default for rte_eth_conf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index e0e3579a..d704267d 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -109,3 +109,6 @@ fn bindgen_test_layout_rte_kni_mbuf() { impl Clone for rte_kni_mbuf { fn clone(&self) -> Self { *self } } +impl Default for rte_kni_mbuf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index f1702673..c0c2cce2 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -38,7 +38,7 @@ pub type MARKER64 = [u64; 0usize]; * The atomic counter structure. */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct _bindgen_ty_1 { /**< An internal counter value. */ pub cnt: i16, @@ -118,7 +118,7 @@ pub struct rte_mbuf { * config option. */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_1 { /**< Atomically accessed refcnt */ pub refcnt_atomic: __BindgenUnionField<rte_atomic16_t>, @@ -149,7 +149,7 @@ impl Clone for rte_mbuf__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_2 { /**< L2/L3/L4 and tunnel information. */ pub packet_type: __BindgenUnionField<u32>, @@ -157,7 +157,7 @@ pub struct rte_mbuf__bindgen_ty_2 { pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { pub _bitfield_1: u32, } @@ -285,7 +285,7 @@ impl Clone for rte_mbuf__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_3 { /**< RSS hash result if RSS enabled */ pub rss: __BindgenUnionField<u32>, @@ -298,20 +298,20 @@ pub struct rte_mbuf__bindgen_ty_3 { pub bindgen_union_field: [u32; 2usize], } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1 { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, pub hi: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { pub __bindgen_anon_1: __BindgenUnionField<rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1>, pub lo: __BindgenUnionField<u32>, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { pub hash: u16, pub id: u16, @@ -395,7 +395,7 @@ impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { pub lo: u32, pub hi: u32, @@ -459,7 +459,7 @@ impl Clone for rte_mbuf__bindgen_ty_3 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_4 { /**< Can be used for external metadata */ pub userdata: __BindgenUnionField<*mut ::std::os::raw::c_void>, @@ -493,7 +493,7 @@ impl Clone for rte_mbuf__bindgen_ty_4 { #[derive(Debug, Copy, Clone)] pub struct rte_mbuf_rte_mempool([u8; 0]); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_5 { /**< combined for easy fetch */ pub tx_offload: __BindgenUnionField<u64>, @@ -501,7 +501,7 @@ pub struct rte_mbuf__bindgen_ty_5 { pub bindgen_union_field: u64, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { pub _bitfield_1: u64, } @@ -731,3 +731,6 @@ fn bindgen_test_layout_rte_mbuf() { impl Clone for rte_mbuf { fn clone(&self) -> Self { *self } } +impl Default for rte_mbuf { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/maddness-is-avoidable.rs b/tests/expectations/tests/maddness-is-avoidable.rs index d31345ba..2fb5e540 100644 --- a/tests/expectations/tests/maddness-is-avoidable.rs +++ b/tests/expectations/tests/maddness-is-avoidable.rs @@ -18,3 +18,9 @@ pub struct RefPtr_Proxy<T, R, Args> { pub _phantom_1: ::std::marker::PhantomData<R>, pub _phantom_2: ::std::marker::PhantomData<Args>, } +impl <T, R, Args> Default for RefPtr_Proxy<T, R, Args> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl <T> Default for RefPtr<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/method-mangling.rs b/tests/expectations/tests/method-mangling.rs index 94877dca..23f12280 100644 --- a/tests/expectations/tests/method-mangling.rs +++ b/tests/expectations/tests/method-mangling.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub _address: u8, } diff --git a/tests/expectations/tests/module-whitelisted.rs b/tests/expectations/tests/module-whitelisted.rs index cee91305..cb6dd6a6 100644 --- a/tests/expectations/tests/module-whitelisted.rs +++ b/tests/expectations/tests/module-whitelisted.rs @@ -8,7 +8,7 @@ pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Test { pub _address: u8, } diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index 842ca1f3..7ea253b6 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A { pub foo: usize, } diff --git a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs index 008ed565..253d5843 100644 --- a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs +++ b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub _address: u8, } @@ -20,7 +20,7 @@ impl Clone for Foo { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Bar { pub _address: u8, } @@ -35,7 +35,7 @@ impl Clone for Bar { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Baz { pub _address: u8, } diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs index 82689ce1..cde3dac1 100644 --- a/tests/expectations/tests/mutable.rs +++ b/tests/expectations/tests/mutable.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct C { pub m_member: ::std::os::raw::c_int, pub m_other: ::std::os::raw::c_int, @@ -31,7 +31,7 @@ impl Clone for C { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Default)] pub struct NonCopiable { pub m_member: ::std::os::raw::c_int, } @@ -48,7 +48,7 @@ fn bindgen_test_layout_NonCopiable() { stringify ! ( m_member ) )); } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Default)] pub struct NonCopiableWithNonCopiableMutableMember { pub m_member: NonCopiable, } diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 4d27385d..dda4cd26 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -28,7 +28,7 @@ pub mod root { pub fn foo(); } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct A { pub b: root::whatever::whatever_int_t, } @@ -69,6 +69,9 @@ pub mod root { pub m_c_ptr: *mut T, pub m_c_arr: [T; 10usize], } + impl <T> Default for C<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } + } pub mod w { #[allow(unused_imports)] use self::super::super::root; @@ -78,6 +81,9 @@ pub mod root { pub struct D<T> { pub m_c: root::C<T>, } + impl <T> Default for D<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } + } extern "C" { #[link_name = "_ZN1w3hehEv"] pub fn heh() -> root::w::whatever_int_t; diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs index 4c119bc7..d50f8e17 100644 --- a/tests/expectations/tests/nested.rs +++ b/tests/expectations/tests/nested.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Calc { pub w: ::std::os::raw::c_int, } @@ -25,18 +25,18 @@ impl Clone for Calc { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Test { pub _address: u8, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Test_Size { pub mWidth: Test_Size_Dimension, pub mHeight: Test_Size_Dimension, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Test_Size_Dimension { pub _base: Calc, } diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index 7cc30423..e16a23d7 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -5,6 +5,7 @@ #[repr(C)] +#[derive(Default)] pub struct nsISupports__bindgen_vtable { } #[repr(C)] @@ -22,6 +23,9 @@ fn bindgen_test_layout_nsISupports() { impl Clone for nsISupports { fn clone(&self) -> Self { *self } } +impl Default for nsISupports { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct nsIRunnable { @@ -37,6 +41,9 @@ fn bindgen_test_layout_nsIRunnable() { impl Clone for nsIRunnable { fn clone(&self) -> Self { *self } } +impl Default for nsIRunnable { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct Runnable { @@ -52,3 +59,6 @@ fn bindgen_test_layout_Runnable() { impl Clone for Runnable { fn clone(&self) -> Self { *self } } +impl Default for Runnable { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index db4e0493..cb6eead3 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -11,12 +11,12 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Bar { pub foo: ::std::os::raw::c_int, } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Bar_Baz { pub foo: ::std::os::raw::c_int, } @@ -51,7 +51,7 @@ pub mod root { fn clone(&self) -> Self { *self } } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Baz { pub baz: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs index c3bb13c4..058f2045 100644 --- a/tests/expectations/tests/no-comments.rs +++ b/tests/expectations/tests/no-comments.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub s: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index 4de75797..07e6ae82 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -3,7 +3,7 @@ #![allow(non_snake_case)] -#[repr(C)] #[derive(Copy, Clone)] pub struct foo { bar: ::std::os::raw::c_int, } +#[repr(C)] #[derive(Copy, Clone, Default)] pub struct foo { bar: ::std::os::raw::c_int, } /** * bar should compile. It will normally derive debug, but our blacklist of foo @@ -11,7 +11,7 @@ * from building if --no-derive-debug didn't work. */ #[repr(C)] -#[derive(Copy)] +#[derive(Default, Copy)] pub struct bar { pub foo: foo, pub baz: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs new file mode 100644 index 00000000..2cec9d19 --- /dev/null +++ b/tests/expectations/tests/no-derive-default.rs @@ -0,0 +1,38 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + +#[repr(C)] #[derive(Copy, Clone, Debug)] pub struct foo { bar: ::std::os::raw::c_int, } + +/** + * bar should compile. It will normally derive default, but our blacklist of foo + * and replacement for another type that doesn't implement it would prevent it + * from building if --no-derive-default didn't work. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct bar { + pub foo: foo, + pub baz: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_bar() { + assert_eq!(::std::mem::size_of::<bar>() , 8usize , concat ! ( + "Size of: " , stringify ! ( bar ) )); + assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const bar ) ) . foo as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( bar ) , "::" , + stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const bar ) ) . baz as * const _ as usize } , + 4usize , concat ! ( + "Alignment of field: " , stringify ! ( bar ) , "::" , + stringify ! ( baz ) )); +} +impl Clone for bar { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/no-recursive-whitelisting.rs b/tests/expectations/tests/no-recursive-whitelisting.rs index c8341990..7cc3d89e 100644 --- a/tests/expectations/tests/no-recursive-whitelisting.rs +++ b/tests/expectations/tests/no-recursive-whitelisting.rs @@ -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/no-std.rs b/tests/expectations/tests/no-std.rs index 21cfda00..998ac2a8 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -38,3 +38,6 @@ fn bindgen_test_layout_foo() { impl Clone for foo { fn clone(&self) -> Self { *self } } +impl Default for foo { + fn default() -> Self { unsafe { ::core::mem::zeroed() } } +} diff --git a/tests/expectations/tests/no_copy.rs b/tests/expectations/tests/no_copy.rs index 53ab9677..3590241f 100644 --- a/tests/expectations/tests/no_copy.rs +++ b/tests/expectations/tests/no_copy.rs @@ -11,3 +11,6 @@ pub struct CopiableButWait<T> { pub whatever: ::std::os::raw::c_int, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for CopiableButWait<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/nsStyleAutoArray.rs b/tests/expectations/tests/nsStyleAutoArray.rs index c150ec46..bc5f5184 100644 --- a/tests/expectations/tests/nsStyleAutoArray.rs +++ b/tests/expectations/tests/nsStyleAutoArray.rs @@ -9,6 +9,9 @@ pub struct nsTArray<T> { pub mBuff: *mut T, } +impl <T> Default for nsTArray<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsStyleAutoArray<T> { @@ -20,3 +23,6 @@ pub struct nsStyleAutoArray<T> { pub enum nsStyleAutoArray_WithSingleInitialElement { WITH_SINGLE_INITIAL_ELEMENT = 0, } +impl <T> Default for nsStyleAutoArray<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index 544ced07..edf551d3 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -31,6 +31,9 @@ fn bindgen_test_layout_FooStruct() { impl Clone for FooStruct { fn clone(&self) -> Self { *self } } +impl Default for FooStruct { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} extern "C" { pub fn fooFunc(foo: id); } diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs index 7811584b..9252097d 100644 --- a/tests/expectations/tests/only_bitfields.rs +++ b/tests/expectations/tests/only_bitfields.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct C { pub _bitfield_1: u8, } diff --git a/tests/expectations/tests/opaque-tracing.rs b/tests/expectations/tests/opaque-tracing.rs index b19a1e68..c7534d97 100644 --- a/tests/expectations/tests/opaque-tracing.rs +++ b/tests/expectations/tests/opaque-tracing.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Container { pub _bindgen_opaque_blob: [u32; 2usize], } diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index cba5952e..f689b02b 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -6,7 +6,7 @@ /** <div rustbindgen opaque> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct opaque { pub _bindgen_opaque_blob: u32, } @@ -21,7 +21,7 @@ impl Clone for opaque { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct container { pub contained: opaque, } diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 3cfa6d87..15b01db4 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -8,7 +8,7 @@ * <div rustbindgen opaque></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct OtherOpaque { pub _bindgen_opaque_blob: u32, } @@ -30,6 +30,9 @@ impl Clone for OtherOpaque { pub struct Opaque<T> { pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Opaque<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct WithOpaquePtr { @@ -62,3 +65,6 @@ fn bindgen_test_layout_WithOpaquePtr() { impl Clone for WithOpaquePtr { fn clone(&self) -> Self { *self } } +impl Default for WithOpaquePtr { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/opaque_typedef.rs b/tests/expectations/tests/opaque_typedef.rs index c45cbc6f..d6d5ac5d 100644 --- a/tests/expectations/tests/opaque_typedef.rs +++ b/tests/expectations/tests/opaque_typedef.rs @@ -10,6 +10,9 @@ pub struct RandomTemplate<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for RandomTemplate<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /** <div rustbindgen opaque></div> */ pub type ShouldBeOpaque = [u8; 0usize]; pub type ShouldNotBeOpaque = RandomTemplate<f32>; diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index 809e224a..a9fbef9f 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct HasPrivate { pub mNotPrivate: ::std::os::raw::c_int, /** <div rustbindgen private></div> */ @@ -33,7 +33,7 @@ impl Clone for HasPrivate { } /** <div rustbindgen private></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct VeryPrivate { mIsPrivate: ::std::os::raw::c_int, mIsAlsoPrivate: ::std::os::raw::c_int, @@ -60,7 +60,7 @@ impl Clone for VeryPrivate { } /** <div rustbindgen private></div> */ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct ContradictPrivate { /** <div rustbindgen private="false"></div> */ pub mNotPrivate: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/public-dtor.rs b/tests/expectations/tests/public-dtor.rs index d4c18c6b..1accf49c 100644 --- a/tests/expectations/tests/public-dtor.rs +++ b/tests/expectations/tests/public-dtor.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Default)] pub struct cv_String { pub _address: u8, } diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index 675bbbca..714467f6 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -6,6 +6,7 @@ pub const NSID_LENGTH: ::std::os::raw::c_uint = 10; #[repr(C)] +#[derive(Default)] pub struct nsID__bindgen_vtable { } #[repr(C)] @@ -23,3 +24,6 @@ fn bindgen_test_layout_nsID() { impl Clone for nsID { fn clone(&self) -> Self { *self } } +impl Default for nsID { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index baeab03e..6965f767 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -12,7 +12,7 @@ pub mod root { use self::super::super::root; /// <div rustbindgen replaces="foo::Bar"></div> #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Bar { pub bazz: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/replace_template_alias.rs b/tests/expectations/tests/replace_template_alias.rs index f922ac77..dbd0d283 100644 --- a/tests/expectations/tests/replace_template_alias.rs +++ b/tests/expectations/tests/replace_template_alias.rs @@ -13,3 +13,6 @@ pub type JS_detail_MaybeWrapped<T> = T; pub struct JS_Rooted<T> { pub ptr: JS_detail_MaybeWrapped<T>, } +impl <T> Default for JS_Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index ed55080a..d93121d3 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -13,6 +13,9 @@ pub struct nsTArray<T> { pub y: ::std::os::raw::c_uint, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for nsTArray<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct Test { @@ -33,3 +36,6 @@ fn bindgen_test_layout_Test() { impl Clone for Test { fn clone(&self) -> Self { *self } } +impl Default for Test { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/replaces_double.rs b/tests/expectations/tests/replaces_double.rs index 50dafd42..99b812db 100644 --- a/tests/expectations/tests/replaces_double.rs +++ b/tests/expectations/tests/replaces_double.rs @@ -13,3 +13,6 @@ pub struct Rooted<T> { * <div rustbindgen replaces="Rooted_MaybeWrapped"></div> */ pub type Rooted_MaybeWrapped<T> = T; +impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 4dde8266..820b5e71 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -8,7 +8,7 @@ #[derive(Debug, Copy, Clone)] pub struct JS_Zone([u8; 0]); #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct JS_shadow_Zone { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 87df768d..4d81651e 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -24,3 +24,6 @@ fn bindgen_test_layout_C() { impl Clone for C { fn clone(&self) -> Self { *self } } +impl Default for C { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 60f12262..ff16490a 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -10,7 +10,7 @@ pub struct a { pub val_a: *mut a_b, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct a_b { pub val_b: ::std::os::raw::c_int, } @@ -44,3 +44,6 @@ fn bindgen_test_layout_a() { impl Clone for a { fn clone(&self) -> Self { *self } } +impl Default for a { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index 75baf354..b02fdd0e 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index f20f03d8..a19c957b 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -5,13 +5,13 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub bar: [foo__bindgen_ty_1; 2usize], pub baz: [[[foo__bindgen_ty_2; 4usize]; 3usize]; 2usize], } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, @@ -37,7 +37,7 @@ impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_2 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 087ff3d8..e0b06f76 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -10,7 +10,7 @@ pub struct foo { pub bar: *mut foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, @@ -50,3 +50,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/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index ac4b6f75..aff61c45 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -29,12 +29,12 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub b: __BindgenUnionField<::std::os::raw::c_ushort>, diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 982b3bdc..80039415 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 26edbceb..f55d8e38 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -29,12 +29,12 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub b: __BindgenUnionField<::std::os::raw::c_ushort>, diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 90f2fba2..861ad662 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct bitfield { pub _bitfield_1: u8, pub e: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index b81baa00..58a94853 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct LittleArray { pub a: [::std::os::raw::c_int; 32usize], } @@ -40,8 +40,11 @@ fn bindgen_test_layout_BigArray() { "Alignment of field: " , stringify ! ( BigArray ) , "::" , stringify ! ( a ) )); } +impl Default for BigArray { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct WithLittleArray { pub a: LittleArray, } @@ -76,3 +79,6 @@ fn bindgen_test_layout_WithBigArray() { "Alignment of field: " , stringify ! ( WithBigArray ) , "::" , stringify ! ( a ) )); } +impl Default for WithBigArray { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 4bd5586b..30ba124b 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -29,13 +29,13 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub a: ::std::os::raw::c_uint, pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub b: __BindgenUnionField<::std::os::raw::c_uint>, pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_1__bindgen_ty_1>, @@ -43,7 +43,7 @@ pub struct foo__bindgen_ty_1 { pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, @@ -75,7 +75,7 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub d1: ::std::os::raw::c_uchar, pub d2: ::std::os::raw::c_uchar, diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index b7afdafe..cba3d475 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -5,7 +5,7 @@ #[repr(C, packed)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct a { pub b: ::std::os::raw::c_char, pub c: ::std::os::raw::c_short, diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index d28806c4..bcdaada2 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub x: ::std::os::raw::c_uint, pub y: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/struct_with_typedef_template_arg.rs b/tests/expectations/tests/struct_with_typedef_template_arg.rs index 6f8d71f1..f882c65d 100644 --- a/tests/expectations/tests/struct_with_typedef_template_arg.rs +++ b/tests/expectations/tests/struct_with_typedef_template_arg.rs @@ -13,3 +13,6 @@ pub struct Proxy<T, Args> { } pub type Proxy_foo<T> = ::std::option::Option<unsafe extern "C" fn(bar: *mut T)>; +impl <T, Args> Default for Proxy<T, Args> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-fun-ty.rs b/tests/expectations/tests/template-fun-ty.rs index c2a8a028..b894920f 100644 --- a/tests/expectations/tests/template-fun-ty.rs +++ b/tests/expectations/tests/template-fun-ty.rs @@ -12,6 +12,9 @@ pub struct Foo<T> { } pub type Foo_FunctionPtr<T> = ::std::option::Option<unsafe extern "C" fn() -> T>; +impl <T> Default for Foo<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr<T> { @@ -28,4 +31,10 @@ pub struct RefPtr_Proxy<T, R, Args> { } pub type RefPtr_Proxy_member_function<R, Args> = ::std::option::Option<unsafe extern "C" fn(arg1: Args) -> R>; +impl <T, R, Args> Default for RefPtr_Proxy<T, R, Args> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl <T> Default for RefPtr<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type Returner<T> = ::std::option::Option<unsafe extern "C" fn() -> T>; diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 844dc6c2..131a54fd 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -12,6 +12,9 @@ pub struct Foo<T, U> { pub m_member_arr: [T; 1usize], pub _phantom_1: ::std::marker::PhantomData<U>, } +impl <T, U> Default for Foo<T, U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} extern "C" { #[link_name = "_Z3bar3FooIiiE"] pub fn bar(foo: Foo<::std::os::raw::c_int, ::std::os::raw::c_int>); @@ -30,6 +33,12 @@ pub struct D_U<T, Z> { pub m_baz: Z, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T, Z> Default for D_U<T, Z> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl <T> Default for D<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted<T> { @@ -37,6 +46,9 @@ pub struct Rooted<T> { pub next: *mut Rooted<*mut ::std::os::raw::c_void>, pub ptr: T, } +impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct RootedContainer { @@ -57,11 +69,17 @@ fn bindgen_test_layout_RootedContainer() { impl Clone for RootedContainer { fn clone(&self) -> Self { *self } } +impl Default for RootedContainer { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug)] pub struct WithDtor<T> { pub member: T, } +impl <T> Default for WithDtor<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type WithDtorIntFwd = WithDtor<::std::os::raw::c_int>; #[repr(C)] #[derive(Debug)] @@ -80,14 +98,20 @@ fn bindgen_test_layout_PODButContainsDtor() { "Alignment of field: " , stringify ! ( PODButContainsDtor ) , "::" , stringify ! ( member ) )); } +impl Default for PODButContainsDtor { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /** <div rustbindgen opaque> */ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Opaque<T> { pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Opaque<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct POD { pub opaque_member: u32, } @@ -114,17 +138,26 @@ impl Clone for POD { pub struct NestedReplaced<T> { pub buff: *mut T, } +impl <T> Default for NestedReplaced<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct NestedBase<T, U> { pub buff: *mut T, pub _phantom_1: ::std::marker::PhantomData<U>, } +impl <T, U> Default for NestedBase<T, U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Incomplete<T> { pub d: T, } +impl <T> Default for Incomplete<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct NestedContainer<T> { @@ -132,8 +165,11 @@ pub struct NestedContainer<T> { pub nested: NestedReplaced<T>, pub inc: Incomplete<T>, } +impl <T> Default for NestedContainer<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Untemplated { pub _address: u8, } @@ -153,6 +189,9 @@ pub struct Templated<T> { pub m_untemplated: Untemplated, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for Templated<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /** * If the replacement doesn't happen at the parse level the container would be * copy and the replacement wouldn't, so this wouldn't compile. @@ -164,16 +203,25 @@ pub struct Templated<T> { pub struct ReplacedWithoutDestructor<T> { pub buff: *mut T, } +impl <T> Default for ReplacedWithoutDestructor<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug)] pub struct ShouldNotBeCopiable<T> { pub m_member: ReplacedWithoutDestructor<T>, } +impl <T> Default for ShouldNotBeCopiable<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug)] pub struct ShouldNotBeCopiableAsWell<U> { pub m_member: ReplacedWithoutDestructorFwd<U>, } +impl <U> Default for ShouldNotBeCopiableAsWell<U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /** * If the replacement doesn't happen at the parse level the container would be * copy and the replacement wouldn't, so this wouldn't compile. @@ -185,12 +233,18 @@ pub struct ShouldNotBeCopiableAsWell<U> { pub struct ReplacedWithoutDestructorFwd<T> { pub buff: *mut T, } +impl <T> Default for ReplacedWithoutDestructorFwd<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct TemplateWithVar<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for TemplateWithVar<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[test] fn __bindgen_test_layout_template_1() { assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>() diff --git a/tests/expectations/tests/template_alias.rs b/tests/expectations/tests/template_alias.rs index d301a11c..44f7830f 100644 --- a/tests/expectations/tests/template_alias.rs +++ b/tests/expectations/tests/template_alias.rs @@ -10,3 +10,6 @@ pub type JS_detail_Wrapped<T> = T; pub struct JS_Rooted<T> { pub ptr: JS_detail_Wrapped<T>, } +impl <T> Default for JS_Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template_alias_namespace.rs b/tests/expectations/tests/template_alias_namespace.rs index cf4a079c..dd4add40 100644 --- a/tests/expectations/tests/template_alias_namespace.rs +++ b/tests/expectations/tests/template_alias_namespace.rs @@ -20,5 +20,8 @@ pub mod root { pub struct Rooted<T> { pub ptr: root::JS::detail::Wrapped<T>, } + impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } + } } } diff --git a/tests/expectations/tests/template_typedef_transitive_param.rs b/tests/expectations/tests/template_typedef_transitive_param.rs index 166ddc3c..cc801f35 100644 --- a/tests/expectations/tests/template_typedef_transitive_param.rs +++ b/tests/expectations/tests/template_typedef_transitive_param.rs @@ -15,4 +15,10 @@ pub struct Wrapper<T> { pub struct Wrapper_Wrapped<T> { pub t: T, } +impl <T> Default for Wrapper_Wrapped<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type Wrapper_Type<T> = Wrapper_Wrapped<T>; +impl <T> Default for Wrapper<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template_typedefs.rs b/tests/expectations/tests/template_typedefs.rs index 5f0d80b9..9213c0d2 100644 --- a/tests/expectations/tests/template_typedefs.rs +++ b/tests/expectations/tests/template_typedefs.rs @@ -20,3 +20,6 @@ pub type Foo_nsCOMArrayEnumFunc<T> = aData: *mut ::std::os::raw::c_void) -> bool>; +impl <T, U> Default for Foo<T, U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/templateref_opaque.rs b/tests/expectations/tests/templateref_opaque.rs index d69254c8..dfe941af 100644 --- a/tests/expectations/tests/templateref_opaque.rs +++ b/tests/expectations/tests/templateref_opaque.rs @@ -11,6 +11,9 @@ pub struct detail_PointerType<T> { pub _phantom_0: ::std::marker::PhantomData<T>, } pub type detail_PointerType_Type<T> = *mut T; +impl <T> Default for detail_PointerType<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UniquePtr<T> { @@ -18,3 +21,6 @@ pub struct UniquePtr<T> { pub _phantom_0: ::std::marker::PhantomData<T>, } pub type UniquePtr_Pointer<T> = detail_PointerType<T>; +impl <T> Default for UniquePtr<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs index f4201a56..67381d41 100644 --- a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs +++ b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct dl_phdr_info { pub x: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/type_alias_partial_template_especialization.rs b/tests/expectations/tests/type_alias_partial_template_especialization.rs index 70b5f66c..2e0f2f4d 100644 --- a/tests/expectations/tests/type_alias_partial_template_especialization.rs +++ b/tests/expectations/tests/type_alias_partial_template_especialization.rs @@ -10,3 +10,6 @@ pub type MaybeWrapped<A> = A; pub struct Rooted<T> { pub ptr: MaybeWrapped<T>, } +impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/type_alias_template_specialized.rs b/tests/expectations/tests/type_alias_template_specialized.rs index 5dd2038f..20665af6 100644 --- a/tests/expectations/tests/type_alias_template_specialized.rs +++ b/tests/expectations/tests/type_alias_template_specialized.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Rooted { pub ptr: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index c199b7ab..47b7a66a 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -48,8 +48,11 @@ fn bindgen_test_layout_nsFoo() { impl Clone for nsFoo { fn clone(&self) -> Self { *self } } +impl Default for nsFoo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct mozilla_FragmentOrURL { pub mIsLocalRef: bool, } @@ -71,7 +74,7 @@ impl Clone for mozilla_FragmentOrURL { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct mozilla_Position { pub _address: u8, } @@ -92,13 +95,16 @@ pub struct mozilla_StyleShapeSource<ReferenceBox> { pub _phantom_0: ::std::marker::PhantomData<ReferenceBox>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct mozilla_StyleShapeSource__bindgen_ty_1<ReferenceBox> { pub mPosition: __BindgenUnionField<*mut mozilla_Position>, pub mFragmentOrURL: __BindgenUnionField<*mut mozilla_FragmentOrURL>, pub bindgen_union_field: u64, pub _phantom_0: ::std::marker::PhantomData<ReferenceBox>, } +impl <ReferenceBox> Default for mozilla_StyleShapeSource<ReferenceBox> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct Bar { @@ -119,3 +125,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/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index cb69d603..208b6283 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -36,7 +36,7 @@ pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct bar { pub baz: root::__BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index ad707b63..bfd573e0 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -29,7 +29,7 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Default)] pub struct UnionWithDtor { pub mFoo: __BindgenUnionField<::std::os::raw::c_int>, pub mBar: __BindgenUnionField<*mut ::std::os::raw::c_void>, diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 64eb3fe4..823a0b8b 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -29,7 +29,7 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct _bindgen_ty_1 { pub mInt: __BindgenUnionField<::std::os::raw::c_int>, pub mFloat: __BindgenUnionField<f32>, diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index fc92afb8..2eba0f0a 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -37,7 +37,7 @@ pub struct NastyStruct<T> { pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct NastyStruct__bindgen_ty_1<T> { pub mFoo: __BindgenUnionField<*mut ::std::os::raw::c_void>, pub mDummy: __BindgenUnionField<::std::os::raw::c_ulong>, @@ -45,15 +45,18 @@ pub struct NastyStruct__bindgen_ty_1<T> { pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct NastyStruct__bindgen_ty_2<T> { pub wat: __BindgenUnionField<::std::os::raw::c_short>, pub wut: __BindgenUnionField<*mut ::std::os::raw::c_int>, pub bindgen_union_field: u64, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for NastyStruct<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct Whatever<T> { pub mTPtr: __BindgenUnionField<*mut ::std::os::raw::c_void>, pub mInt: __BindgenUnionField<::std::os::raw::c_int>, diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index 4b9c635f..59f8fcab 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -29,13 +29,13 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub bar: __BindgenUnionField<foo__bindgen_ty_1>, pub bindgen_union_field: [u32; 2usize], } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 449fd440..d14a38bb 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -29,14 +29,14 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub a: __BindgenUnionField<::std::os::raw::c_int>, pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_1>, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub _bitfield_1: u32, } diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 16b33551..9e182d21 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -29,13 +29,13 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub bar: __BindgenUnionField<foo__bindgen_ty_1>, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub b: __BindgenUnionField<::std::os::raw::c_ushort>, diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 7982728a..4d0b639f 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -29,14 +29,14 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct pixel { pub rgba: __BindgenUnionField<::std::os::raw::c_uint>, pub __bindgen_anon_1: __BindgenUnionField<pixel__bindgen_ty_1>, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct pixel__bindgen_ty_1 { pub r: ::std::os::raw::c_uchar, pub g: ::std::os::raw::c_uchar, diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 1e7f918c..fd6f82fc 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -29,14 +29,14 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_1>, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub b: __BindgenUnionField<::std::os::raw::c_ushort>, pub c: __BindgenUnionField<::std::os::raw::c_uchar>, diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 58407cdb..2b7a8eef 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -55,8 +55,11 @@ fn bindgen_test_layout_WithBigArray() { impl Clone for WithBigArray { fn clone(&self) -> Self { *self } } +impl Default for WithBigArray { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct WithBigArray2 { pub a: __BindgenUnionField<::std::os::raw::c_int>, pub b: __BindgenUnionField<[::std::os::raw::c_char; 33usize]>, @@ -109,3 +112,6 @@ fn bindgen_test_layout_WithBigMember() { impl Clone for WithBigMember { fn clone(&self) -> Self { *self } } +impl Default for WithBigMember { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 17c3c8f0..d92e8efa 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -29,20 +29,20 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_1>, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1 { pub __bindgen_anon_1: foo__bindgen_ty_1__bindgen_ty_1, pub __bindgen_anon_2: foo__bindgen_ty_1__bindgen_ty_2, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub b1: __BindgenUnionField<::std::os::raw::c_ushort>, pub b2: __BindgenUnionField<::std::os::raw::c_ushort>, @@ -75,7 +75,7 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub c1: __BindgenUnionField<::std::os::raw::c_ushort>, pub c2: __BindgenUnionField<::std::os::raw::c_ushort>, diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index 12a35760..efb86102 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct _bindgen_ty_1 { pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, pub __bindgen_padding_0: u64, diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index f09d1519..dd13156f 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -37,5 +37,8 @@ fn bindgen_test_layout_foo() { impl Clone for foo { fn clone(&self) -> Self { *self } } +impl Default for foo { + fn default() -> Self { unsafe { ::core::mem::zeroed() } } +} pub type fooFunction = ::core::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)>; diff --git a/tests/expectations/tests/using.rs b/tests/expectations/tests/using.rs index dbb6c84f..1638287a 100644 --- a/tests/expectations/tests/using.rs +++ b/tests/expectations/tests/using.rs @@ -10,5 +10,8 @@ pub struct Point<T> { pub x: T, pub y: T, } +impl <T> Default for Point<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type IntPoint2D = Point<::std::os::raw::c_int>; pub type IntVec2D = Point<::std::os::raw::c_int>; diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs index 7a09bcb6..ba10cf22 100644 --- a/tests/expectations/tests/var-tracing.rs +++ b/tests/expectations/tests/var-tracing.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Bar { pub m_baz: ::std::os::raw::c_int, } @@ -37,7 +37,7 @@ impl Bar { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Baz { pub _address: u8, } diff --git a/tests/expectations/tests/variadic-method.rs b/tests/expectations/tests/variadic-method.rs index 45155128..542e1e75 100644 --- a/tests/expectations/tests/variadic-method.rs +++ b/tests/expectations/tests/variadic-method.rs @@ -9,7 +9,7 @@ extern "C" { pub fn foo(fmt: *const ::std::os::raw::c_char, ...); } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct Bar { pub _address: u8, } diff --git a/tests/expectations/tests/variadic_template_function.rs b/tests/expectations/tests/variadic_template_function.rs index cd99df96..32be9f68 100644 --- a/tests/expectations/tests/variadic_template_function.rs +++ b/tests/expectations/tests/variadic_template_function.rs @@ -10,3 +10,6 @@ pub struct VariadicFunctionObject<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } +impl <T> Default for VariadicFunctionObject<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index 4b689744..31bc8fd7 100644 --- a/tests/expectations/tests/vector.rs +++ b/tests/expectations/tests/vector.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub mMember: [::std::os::raw::c_longlong; 1usize], } diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs index de5e01af..0c410977 100644 --- a/tests/expectations/tests/virtual_dtor.rs +++ b/tests/expectations/tests/virtual_dtor.rs @@ -5,6 +5,7 @@ #[repr(C)] +#[derive(Default)] pub struct nsSlots__bindgen_vtable { } #[repr(C)] @@ -19,3 +20,6 @@ fn bindgen_test_layout_nsSlots() { assert_eq! (::std::mem::align_of::<nsSlots>() , 8usize , concat ! ( "Alignment of " , stringify ! ( nsSlots ) )); } +impl Default for nsSlots { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index e0510730..6896eb31 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct A { pub foo: ::std::os::raw::c_int, } @@ -25,6 +25,7 @@ impl Clone for A { fn clone(&self) -> Self { *self } } #[repr(C)] +#[derive(Default)] pub struct B__bindgen_vtable { } #[repr(C)] @@ -48,7 +49,11 @@ fn bindgen_test_layout_B() { impl Clone for B { fn clone(&self) -> Self { *self } } +impl Default for B { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] +#[derive(Default)] pub struct C__bindgen_vtable { } #[repr(C)] @@ -72,6 +77,9 @@ fn bindgen_test_layout_C() { impl Clone for C { fn clone(&self) -> Self { *self } } +impl Default for C { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy)] pub struct D { @@ -89,3 +97,6 @@ fn bindgen_test_layout_D() { impl Clone for D { fn clone(&self) -> Self { *self } } +impl Default for D { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index 9937cf5d..e7ae9f4a 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -5,6 +5,7 @@ #[repr(C)] +#[derive(Default)] pub struct C__bindgen_vtable { } #[repr(C)] @@ -22,3 +23,6 @@ fn bindgen_test_layout_C() { impl Clone for C { fn clone(&self) -> Self { *self } } +impl Default for C { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index 6cf3135f..716ce39f 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -19,7 +19,11 @@ fn bindgen_test_layout_Derived() { impl Clone for Derived { fn clone(&self) -> Self { *self } } +impl Default for Derived { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] +#[derive(Default)] pub struct Base__bindgen_vtable { } #[repr(C)] @@ -37,3 +41,6 @@ fn bindgen_test_layout_Base() { impl Clone for Base { fn clone(&self) -> Self { *self } } +impl Default for Base { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 98765b09..a2841e34 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -99,6 +99,9 @@ fn bindgen_test_layout_Weird() { impl Clone for Weird { fn clone(&self) -> Self { *self } } +impl Default for Weird { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} impl Weird { #[inline] pub fn bitTest(&self) -> ::std::os::raw::c_uint { diff --git a/tests/expectations/tests/what_is_going_on.rs b/tests/expectations/tests/what_is_going_on.rs index d0265c4e..46af0139 100644 --- a/tests/expectations/tests/what_is_going_on.rs +++ b/tests/expectations/tests/what_is_going_on.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct UnknownUnits { pub _address: u8, } @@ -27,4 +27,7 @@ pub struct PointTyped<units, F> { pub y: F, pub _phantom_0: ::std::marker::PhantomData<units>, } +impl <units, F> Default for PointTyped<units, F> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type IntPoint = PointTyped<UnknownUnits, f32>; diff --git a/tests/expectations/tests/whitelist-namespaces-basic.rs b/tests/expectations/tests/whitelist-namespaces-basic.rs index 06f24ff0..ba96895b 100644 --- a/tests/expectations/tests/whitelist-namespaces-basic.rs +++ b/tests/expectations/tests/whitelist-namespaces-basic.rs @@ -14,7 +14,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Helper { pub _address: u8, } diff --git a/tests/expectations/tests/whitelist-namespaces.rs b/tests/expectations/tests/whitelist-namespaces.rs index d3707800..5e47c9d6 100644 --- a/tests/expectations/tests/whitelist-namespaces.rs +++ b/tests/expectations/tests/whitelist-namespaces.rs @@ -14,7 +14,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::super::root; #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Helper { pub _address: u8, } @@ -30,7 +30,7 @@ pub mod root { } } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Default, Copy)] pub struct Test { pub helper: root::outer::inner::Helper, } diff --git a/tests/expectations/tests/whitelist_basic.rs b/tests/expectations/tests/whitelist_basic.rs index 0104f049..d67fb7a3 100644 --- a/tests/expectations/tests/whitelist_basic.rs +++ b/tests/expectations/tests/whitelist_basic.rs @@ -16,3 +16,9 @@ pub struct WhitelistMe<T> { pub struct WhitelistMe_Inner<T> { pub bar: T, } +impl <T> Default for WhitelistMe_Inner<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl <T> Default for WhitelistMe<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/headers/no-derive-debug.h b/tests/headers/no-derive-debug.h index 4a49e404..c780d2d8 100644 --- a/tests/headers/no-derive-debug.h +++ b/tests/headers/no-derive-debug.h @@ -1,4 +1,4 @@ -// bindgen-flags: --no-derive-debug --blacklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone)] pub struct foo { bar: ::std::os::raw::c_int, }" +// bindgen-flags: --no-derive-debug --blacklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone, Default)] pub struct foo { bar: ::std::os::raw::c_int, }" struct foo { int bar; diff --git a/tests/headers/no-derive-default.h b/tests/headers/no-derive-default.h new file mode 100644 index 00000000..207b93b6 --- /dev/null +++ b/tests/headers/no-derive-default.h @@ -0,0 +1,15 @@ +// bindgen-flags: --no-derive-default --blacklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone, Debug)] pub struct foo { bar: ::std::os::raw::c_int, }" + +struct foo { + int bar; +}; + +/** + * bar should compile. It will normally derive default, but our blacklist of foo + * and replacement for another type that doesn't implement it would prevent it + * from building if --no-derive-default didn't work. + */ +struct bar { + struct foo foo; + int baz; +}; diff --git a/tests/tests.rs b/tests/tests.rs index 5b0ccd11..ef5b2c24 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -104,6 +104,7 @@ fn create_bindgen_builder(header: &PathBuf) -> Result<Option<Builder>, Error> { .ok_or(Error::new(ErrorKind::Other, "Invalid header file name"))); let prepend = ["bindgen", + "--with-derive-default", header_str, "--raw-line", "", |