From 25b68ba8bda4cdacaf7f04260f91709233fe0d45 Mon Sep 17 00:00:00 2001 From: Flier Lu Date: Sun, 5 Feb 2017 17:12:05 +0800 Subject: [PATCH] implement Default trait --- src/codegen/mod.rs | 54 ++++++++++++++-- src/ir/comp.rs | 61 ++++++++++++++++++- src/ir/context.rs | 10 ++- src/ir/derive.rs | 21 +++++++ src/ir/item.rs | 22 ++++++- src/ir/layout.rs | 11 +++- src/ir/ty.rs | 35 ++++++++++- src/lib.rs | 11 ++++ src/options.rs | 15 +++++ tests/expectations/tests/16-byte-alignment.rs | 15 +++-- .../expectations/tests/381-decltype-alias.rs | 3 + tests/expectations/tests/accessors.rs | 12 ++-- tests/expectations/tests/annotation_hide.rs | 4 +- tests/expectations/tests/anon_enum.rs | 2 +- tests/expectations/tests/anon_enum_trait.rs | 5 +- tests/expectations/tests/anon_union.rs | 12 +++- tests/expectations/tests/auto.rs | 5 +- .../bad-namespace-parenthood-inheritance.rs | 5 +- tests/expectations/tests/base-to-derived.rs | 2 +- .../expectations/tests/bitfield-enum-basic.rs | 2 +- .../tests/bitfield_method_mangling.rs | 2 +- .../canonical_path_without_namespacing.rs | 2 +- tests/expectations/tests/class.rs | 24 ++++++-- tests/expectations/tests/class_nested.rs | 12 +++- tests/expectations/tests/class_no_members.rs | 6 +- tests/expectations/tests/class_static.rs | 2 +- .../expectations/tests/class_static_const.rs | 2 +- tests/expectations/tests/class_use_as.rs | 4 +- tests/expectations/tests/class_with_dtor.rs | 6 ++ .../tests/class_with_inner_struct.rs | 23 ++++--- .../expectations/tests/class_with_typedef.rs | 6 ++ tests/expectations/tests/complex.rs | 10 ++- tests/expectations/tests/const_bool.rs | 2 +- .../expectations/tests/const_enum_unnamed.rs | 2 +- tests/expectations/tests/const_tparam.rs | 3 + .../tests/constant-non-specialized-tp.rs | 8 ++- .../expectations/tests/constify-all-enums.rs | 3 + tests/expectations/tests/constructor-tp.rs | 5 +- tests/expectations/tests/constructors.rs | 4 +- tests/expectations/tests/convert-floats.rs | 3 + tests/expectations/tests/crtp.rs | 12 ++++ tests/expectations/tests/dash_language.rs | 3 + .../duplicated-namespaces-definitions.rs | 5 +- .../tests/empty_template_param_name.rs | 3 + .../tests/enum_and_vtable_mangling.rs | 4 ++ .../tests/enum_in_template_with_typedef.rs | 3 + .../tests/eval-variadic-template-parameter.rs | 3 + .../tests/forward-declaration-autoptr.rs | 6 ++ .../forward-inherit-struct-with-fields.rs | 6 ++ .../tests/forward-inherit-struct.rs | 6 ++ .../tests/forward_declared_complex_types.rs | 5 +- .../tests/forward_declared_struct.rs | 4 +- .../expectations/tests/func_ptr_in_struct.rs | 3 + tests/expectations/tests/in_class_typedef.rs | 5 +- .../expectations/tests/inherit-namespaced.rs | 6 ++ tests/expectations/tests/inherit_named.rs | 6 ++ tests/expectations/tests/inherit_typedef.rs | 4 +- tests/expectations/tests/inline_namespace.rs | 2 +- .../tests/inline_namespace_conservative.rs | 2 +- tests/expectations/tests/inner_const.rs | 2 +- .../expectations/tests/inner_template_self.rs | 6 ++ tests/expectations/tests/issue-358.rs | 6 ++ tests/expectations/tests/issue-372.rs | 9 +++ tests/expectations/tests/issue-410.rs | 2 +- tests/expectations/tests/issue-447.rs | 4 +- tests/expectations/tests/issue_311.rs | 4 +- .../expectations/tests/jsval_layout_opaque.rs | 11 ++-- tests/expectations/tests/layout.rs | 3 +- tests/expectations/tests/layout_align.rs | 6 +- tests/expectations/tests/layout_arp.rs | 6 +- tests/expectations/tests/layout_array.rs | 14 ++++- .../tests/layout_cmdline_token.rs | 12 ++++ tests/expectations/tests/layout_eth_conf.rs | 58 +++++++++++++++--- tests/expectations/tests/layout_kni_mbuf.rs | 3 + tests/expectations/tests/layout_mbuf.rs | 27 ++++---- .../tests/maddness-is-avoidable.rs | 6 ++ tests/expectations/tests/method-mangling.rs | 2 +- .../expectations/tests/module-whitelisted.rs | 2 +- tests/expectations/tests/msvc-no-usr.rs | 2 +- .../multiple-inherit-empty-correct-layout.rs | 6 +- tests/expectations/tests/mutable.rs | 6 +- tests/expectations/tests/namespace.rs | 8 ++- tests/expectations/tests/nested.rs | 8 +-- tests/expectations/tests/nested_vtable.rs | 10 +++ .../tests/nested_within_namespace.rs | 6 +- tests/expectations/tests/no-comments.rs | 2 +- tests/expectations/tests/no-derive-debug.rs | 4 +- tests/expectations/tests/no-derive-default.rs | 38 ++++++++++++ .../tests/no-recursive-whitelisting.rs | 3 + tests/expectations/tests/no-std.rs | 3 + tests/expectations/tests/no_copy.rs | 3 + tests/expectations/tests/nsStyleAutoArray.rs | 6 ++ .../expectations/tests/objc_interface_type.rs | 3 + tests/expectations/tests/only_bitfields.rs | 2 +- tests/expectations/tests/opaque-tracing.rs | 2 +- tests/expectations/tests/opaque_in_struct.rs | 4 +- tests/expectations/tests/opaque_pointer.rs | 8 ++- tests/expectations/tests/opaque_typedef.rs | 3 + tests/expectations/tests/private.rs | 6 +- tests/expectations/tests/public-dtor.rs | 2 +- .../expectations/tests/ref_argument_array.rs | 4 ++ .../tests/reparented_replacement.rs | 2 +- .../tests/replace_template_alias.rs | 3 + tests/expectations/tests/replace_use.rs | 6 ++ tests/expectations/tests/replaces_double.rs | 3 + ...ame_struct_name_in_different_namespaces.rs | 2 +- tests/expectations/tests/size_t_template.rs | 3 + ...ruct_containing_forward_declared_struct.rs | 5 +- .../tests/struct_with_anon_struct.rs | 4 +- .../tests/struct_with_anon_struct_array.rs | 6 +- .../tests/struct_with_anon_struct_pointer.rs | 5 +- .../tests/struct_with_anon_union.rs | 4 +- .../tests/struct_with_anon_unnamed_struct.rs | 4 +- .../tests/struct_with_anon_unnamed_union.rs | 4 +- .../tests/struct_with_bitfields.rs | 2 +- .../tests/struct_with_derive_debug.rs | 10 ++- .../expectations/tests/struct_with_nesting.rs | 8 +-- .../expectations/tests/struct_with_packing.rs | 2 +- .../expectations/tests/struct_with_struct.rs | 4 +- .../tests/struct_with_typedef_template_arg.rs | 3 + tests/expectations/tests/template-fun-ty.rs | 9 +++ tests/expectations/tests/template.rs | 58 +++++++++++++++++- tests/expectations/tests/template_alias.rs | 3 + .../tests/template_alias_namespace.rs | 3 + .../template_typedef_transitive_param.rs | 6 ++ tests/expectations/tests/template_typedefs.rs | 3 + .../expectations/tests/templateref_opaque.rs | 6 ++ ...type-referenced-by-whitelisted-function.rs | 2 +- ..._alias_partial_template_especialization.rs | 3 + .../tests/type_alias_template_specialized.rs | 2 +- tests/expectations/tests/typeref.rs | 15 ++++- tests/expectations/tests/union-in-ns.rs | 2 +- tests/expectations/tests/union_dtor.rs | 2 +- tests/expectations/tests/union_fields.rs | 2 +- tests/expectations/tests/union_template.rs | 9 ++- .../tests/union_with_anon_struct.rs | 4 +- .../tests/union_with_anon_struct_bitfield.rs | 4 +- .../tests/union_with_anon_union.rs | 4 +- .../tests/union_with_anon_unnamed_struct.rs | 4 +- .../tests/union_with_anon_unnamed_union.rs | 4 +- .../tests/union_with_big_member.rs | 8 ++- .../expectations/tests/union_with_nesting.rs | 8 +-- tests/expectations/tests/unknown_attr.rs | 2 +- tests/expectations/tests/use-core.rs | 3 + tests/expectations/tests/using.rs | 3 + tests/expectations/tests/var-tracing.rs | 4 +- tests/expectations/tests/variadic-method.rs | 2 +- .../tests/variadic_template_function.rs | 3 + tests/expectations/tests/vector.rs | 2 +- tests/expectations/tests/virtual_dtor.rs | 4 ++ .../expectations/tests/virtual_inheritance.rs | 13 +++- .../expectations/tests/virtual_overloaded.rs | 4 ++ .../tests/vtable_recursive_sig.rs | 7 +++ tests/expectations/tests/weird_bitfields.rs | 3 + tests/expectations/tests/what_is_going_on.rs | 5 +- .../tests/whitelist-namespaces-basic.rs | 2 +- .../tests/whitelist-namespaces.rs | 4 +- tests/expectations/tests/whitelist_basic.rs | 6 ++ tests/headers/no-derive-debug.h | 2 +- tests/headers/no-derive-default.h | 15 +++++ tests/tests.rs | 1 + 161 files changed, 968 insertions(+), 204 deletions(-) create mode 100644 tests/expectations/tests/no-derive-default.rs create mode 100644 tests/headers/no-derive-default.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 0fdfaad0a9..5ee43173c8 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( ::$prefix::marker::PhantomData); ) diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 53efd278bf..1ca3955993 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, + /// Used to detect if we've run in a can_derive_default cycle while cycling + /// around the template arguments. + detect_derive_default_cycle: Cell, + /// Used to detect if we've run in a has_destructor cycle while cycling /// around the template arguments. detect_has_destructor_cycle: Cell, @@ -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; + + fn can_derive_default(&self, + ctx: &BindgenContext, + layout: Option) + -> 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); diff --git a/src/ir/context.rs b/src/ir/context.rs index 38ecdf1701..a748239496 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 d13a811708..6d9f368ba2 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 a5d10e418d..c8de95c072 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 e8c6c32bf9..03d43b51ba 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 5903430c91..c3a35f0f31 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; diff --git a/src/lib.rs b/src/lib.rs index 84a2ee6708..38ff3619fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 8d11be2d2a..cc5f48459a 100644 --- a/src/options.rs +++ b/src/options.rs @@ -42,6 +42,13 @@ pub fn builder_from_flags(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(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 b9dd74e37c..2ab00679b9 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -29,21 +29,21 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[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, pub sctp_tag: __BindgenUnionField, 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, pub sctp_tag: __BindgenUnionField, 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 766be3bced..45b0cfdd55 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 c0d95bfb08..753188bdd0 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, /**
*/ @@ -70,7 +70,7 @@ impl SomeAccessors { } /**
*/ #[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 { } /**
*/ #[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 { } /**
*/ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct ContradictAccessors { pub mBothAccessors: ::std::os::raw::c_int, /**
*/ @@ -231,7 +231,7 @@ impl ContradictAccessors { } /**
*/ #[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 { } /**
*/ #[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 62840b13b6..1ad8fd8337 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -8,7 +8,7 @@ *
*/ #[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 b2c7f5fc54..07ea481062 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 c258f7d6fd..31eaca8399 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 6ded1e5706..4418bc7780 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 { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct TErrorResult_DOMExceptionInfo { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct TErrorResult__bindgen_ty_1 { pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, pub bindgen_union_field: u64, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for TErrorResult { + 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::>() , diff --git a/tests/expectations/tests/auto.rs b/tests/expectations/tests/auto.rs index 554546af0e..4551f70314 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 { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Bar { + 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 553879b7a8..b0c91e8ca9 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 4749096ba6..6ff4ce9a97 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 a8d3ecc5cc..362cf28030 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 94f0aa8e4c..0ab5fce557 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 dff6b7071f..43bec38d2f 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 46adbc2940..92389cbefa 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -5,6 +5,7 @@ #[repr(C)] +#[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData); impl __IncompleteArrayField { #[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, 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 8a4125c904..19d70e5034 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 { pub struct Templated_Templated_inner { pub member_ptr: *mut T, } +impl Default for Templated_Templated_inner { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl Default for Templated { + 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 e41e3ffc7d..ad532100ec 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 207295b6c0..521621a760 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 5e59485bc2..4b0108a17d 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 9184c9c84b..f4db9013cb 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -8,7 +8,7 @@ *
*/ #[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 1d8e6b4dd3..4c1d271878 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -9,6 +9,9 @@ pub struct HandleWithDtor { pub ptr: *mut T, } +impl Default for HandleWithDtor { + 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::>() diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 1056fd69c3..a99aada553 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -29,14 +29,14 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[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, pub __bindgen_anon_1: __BindgenUnionField, 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::() , 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 d3141fd99d..1a92b98603 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 1048138eb7..d250f6b118 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -11,7 +11,7 @@ pub struct __BindgenComplex { pub im: T, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct TestDouble { pub mMember: __BindgenComplex, } @@ -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, } @@ -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 2c8ba788c3..de9e81b02e 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 8a5f0f23a9..b6f61b356d 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 3ed10d28b5..f47ca08244 100644 --- a/tests/expectations/tests/const_tparam.rs +++ b/tests/expectations/tests/const_tparam.rs @@ -10,3 +10,6 @@ pub struct C { pub foo: *const T, pub bar: *mut T, } +impl Default for C { + 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 bbadf8a2df..f2aa5a7584 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 { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Test { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Outer { @@ -17,8 +20,11 @@ pub struct Outer { pub _phantom_0: ::std::marker::PhantomData, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct Outer_Inner { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Outer { + 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 ae89a9b72c..e1210d9a1f 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 0f53317b4e..ee04d3c5d9 100644 --- a/tests/expectations/tests/constructor-tp.rs +++ b/tests/expectations/tests/constructor-tp.rs @@ -10,8 +10,11 @@ pub struct Foo { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Foo { + 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 3abb2da783..13a4dcf877 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 5971db0630..ba35da3314 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 8fe0a5ae2e..7143f50e6d 100644 --- a/tests/expectations/tests/crtp.rs +++ b/tests/expectations/tests/crtp.rs @@ -10,6 +10,9 @@ pub struct Base { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Base { + 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 { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for BaseWithDestructor { + 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::>() , 1usize , concat ! ( diff --git a/tests/expectations/tests/dash_language.rs b/tests/expectations/tests/dash_language.rs index 148f9c32d7..24df101487 100644 --- a/tests/expectations/tests/dash_language.rs +++ b/tests/expectations/tests/dash_language.rs @@ -10,3 +10,6 @@ pub struct Foo { pub bar: ::std::os::raw::c_int, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Foo { + 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 1b785fd7f2..196cfc46d1 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 e10b56db71..6ee8fce396 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 e372d98bba..300edd3931 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 66a304aa95..e4725b8386 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 Default for std_fbstring_core { + 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 f8c937e2a8..acc6f34c61 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 { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for B { + 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 ffe5b7b626..b05984c8c8 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 { pub m_inner: *mut T, } +impl Default for RefPtr { + 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 e377b3ad2a..ce61a5459c 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 { pub _base: js_RootedBase, } +impl Default for Rooted { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct js_RootedBase { pub foo: *mut T, pub next: *mut Rooted, } +impl Default for js_RootedBase { + 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 5de70fa9fa..1057e70c06 100644 --- a/tests/expectations/tests/forward-inherit-struct.rs +++ b/tests/expectations/tests/forward-inherit-struct.rs @@ -10,9 +10,15 @@ pub struct Rooted { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Rooted { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct js_RootedBase { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for js_RootedBase { + 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 0637fea3fb..a6e67f7b77 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 51c61cdf0d..ec8b15d1e3 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 eba6c7e2dc..ce14586615 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 4e95ca8c6a..3634a6313c 100644 --- a/tests/expectations/tests/in_class_typedef.rs +++ b/tests/expectations/tests/in_class_typedef.rs @@ -13,9 +13,12 @@ pub struct Foo { pub type Foo_elem_type = T; pub type Foo_ptr_type = *mut T; #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo_Bar { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Foo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/inherit-namespaced.rs b/tests/expectations/tests/inherit-namespaced.rs index c0d2e5a643..e5d5f875ee 100644 --- a/tests/expectations/tests/inherit-namespaced.rs +++ b/tests/expectations/tests/inherit-namespaced.rs @@ -10,9 +10,15 @@ pub struct js_RootedBase { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for js_RootedBase { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Rooted { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/inherit_named.rs b/tests/expectations/tests/inherit_named.rs index 8081c649b7..31c4bee911 100644 --- a/tests/expectations/tests/inherit_named.rs +++ b/tests/expectations/tests/inherit_named.rs @@ -10,8 +10,14 @@ pub struct Wohoo { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Wohoo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Weeee { pub _base: T, } +impl Default for Weeee { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/inherit_typedef.rs b/tests/expectations/tests/inherit_typedef.rs index ff6a62d3ce..76d7c35f8c 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 6b2c4f80c9..8f2243ba2c 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 5b74a5f6b9..7cf7c26421 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 3422f1683b..fd2793a434 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 4345e422cb..3510fa7c77 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -10,6 +10,9 @@ pub struct LinkedList { pub next: *mut LinkedList, pub prev: *mut LinkedList, } +impl Default for LinkedList { + 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 1b933d3437..d3be3c4374 100644 --- a/tests/expectations/tests/issue-358.rs +++ b/tests/expectations/tests/issue-358.rs @@ -10,6 +10,9 @@ pub struct JS_PersistentRooted { pub _base: a, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for JS_PersistentRooted { + 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 8fcfd33dc7..1693f46a2d 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 a8e0d8d469..2fe0f99b27 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 0582f4129e..7ac9d714ab 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 debc893d57..6576b8b5fb 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 ac09258736..848286e7ea 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, pub debugView: __BindgenUnionField, @@ -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, pub u32: __BindgenUnionField, @@ -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 5fae570c9d..115a108a2e 100644 --- a/tests/expectations/tests/layout.rs +++ b/tests/expectations/tests/layout.rs @@ -5,6 +5,7 @@ #[repr(C)] +#[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData); impl __IncompleteArrayField { #[inline] @@ -37,7 +38,7 @@ impl ::std::clone::Clone for __IncompleteArrayField { } impl ::std::marker::Copy for __IncompleteArrayField { } #[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 0479521cee..a21fa4d6ec 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(::std::marker::PhantomData); impl __IncompleteArrayField { #[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 c868f627d5..f3c59eb412 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 bc690fb6e5..3f86cda9a5 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::() , 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 be4944bbfa..35127399e3 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::() , 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 0034e707b9..16788d06f5 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, pub dcb_tx_conf: __BindgenUnionField, @@ -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 e0e3579aca..d704267dee 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 f1702673f4..c0c2cce28b 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, @@ -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, @@ -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, @@ -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, pub lo: __BindgenUnionField, 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, @@ -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 d31345ba67..2fb5e540e3 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 { pub _phantom_1: ::std::marker::PhantomData, pub _phantom_2: ::std::marker::PhantomData, } +impl Default for RefPtr_Proxy { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl Default for RefPtr { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/method-mangling.rs b/tests/expectations/tests/method-mangling.rs index 94877dca56..23f1228018 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 cee913058f..cb6dd6a6c1 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 842ca1f3e6..7ea253b694 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 008ed56526..253d58435b 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 82689ce1b8..cde3dac1b3 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 4d27385d3c..dda4cd2690 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 Default for C { + 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 { pub m_c: root::C, } + impl Default for D { + 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 4c119bc7fe..d50f8e1703 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 7cc3042341..e16a23d71d 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 db4e049311..cb6eead35c 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 c3bb13c47b..058f2045dc 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 4de7579776..07e6ae8228 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 0000000000..2cec9d19b5 --- /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::() , 8usize , concat ! ( + "Size of: " , stringify ! ( bar ) )); + assert_eq! (::std::mem::align_of::() , 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 c8341990f2..7cc3d89e04 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 21cfda00bd..998ac2a87c 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 53ab967700..3590241fce 100644 --- a/tests/expectations/tests/no_copy.rs +++ b/tests/expectations/tests/no_copy.rs @@ -11,3 +11,6 @@ pub struct CopiableButWait { pub whatever: ::std::os::raw::c_int, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for CopiableButWait { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/nsStyleAutoArray.rs b/tests/expectations/tests/nsStyleAutoArray.rs index c150ec4609..bc5f5184cb 100644 --- a/tests/expectations/tests/nsStyleAutoArray.rs +++ b/tests/expectations/tests/nsStyleAutoArray.rs @@ -9,6 +9,9 @@ pub struct nsTArray { pub mBuff: *mut T, } +impl Default for nsTArray { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsStyleAutoArray { @@ -20,3 +23,6 @@ pub struct nsStyleAutoArray { pub enum nsStyleAutoArray_WithSingleInitialElement { WITH_SINGLE_INITIAL_ELEMENT = 0, } +impl Default for nsStyleAutoArray { + 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 544ced074e..edf551d354 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 7811584bd4..9252097d66 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 b19a1e6869..c7534d97ce 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 cba5952eb5..f689b02bc0 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -6,7 +6,7 @@ /**
*/ #[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 3cfa6d870b..15b01db448 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -8,7 +8,7 @@ *
*/ #[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 { pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Opaque { + 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 c45cbc6f5e..d6d5ac5de6 100644 --- a/tests/expectations/tests/opaque_typedef.rs +++ b/tests/expectations/tests/opaque_typedef.rs @@ -10,6 +10,9 @@ pub struct RandomTemplate { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for RandomTemplate { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} /**
*/ pub type ShouldBeOpaque = [u8; 0usize]; pub type ShouldNotBeOpaque = RandomTemplate; diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index 809e224a7b..a9fbef9f50 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, /**
*/ @@ -33,7 +33,7 @@ impl Clone for HasPrivate { } /**
*/ #[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 { } /**
*/ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct ContradictPrivate { /**
*/ pub mNotPrivate: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/public-dtor.rs b/tests/expectations/tests/public-dtor.rs index d4c18c6bd9..1accf49cb5 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 675bbbca6a..714467f6f3 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 baeab03e83..6965f767d7 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; ///
#[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 f922ac7750..dbd0d283de 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; pub struct JS_Rooted { pub ptr: JS_detail_MaybeWrapped, } +impl Default for JS_Rooted { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index ed55080a0e..d93121d3dd 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -13,6 +13,9 @@ pub struct nsTArray { pub y: ::std::os::raw::c_uint, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for nsTArray { + 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 50dafd4249..99b812db39 100644 --- a/tests/expectations/tests/replaces_double.rs +++ b/tests/expectations/tests/replaces_double.rs @@ -13,3 +13,6 @@ pub struct Rooted { *
*/ pub type Rooted_MaybeWrapped = T; +impl Default for Rooted { + 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 4dde8266d8..820b5e71e0 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 87df768d62..4d81651e9d 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 60f1226272..ff16490a3a 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 75baf354da..b02fdd0ed7 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 f20f03d851..a19c957b35 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 087ff3d8d2..e0b06f7682 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 ac4b6f7591..aff61c4542 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -29,12 +29,12 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[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 982b3bdcca..80039415bb 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 26edbceb87..f55d8e3867 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 ::std::fmt::Debug for __BindgenUnionField { } } #[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 90f2fba288..861ad66277 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 b81baa002e..58a94853be 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 4bd5586bb6..30ba124b94 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -29,13 +29,13 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[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, @@ -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 b7afdafefd..cba3d4759e 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 d28806c44b..bcdaada225 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 6f8d71f183..f882c65d54 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 { } pub type Proxy_foo = ::std::option::Option; +impl Default for Proxy { + 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 c2a8a028da..b894920ff0 100644 --- a/tests/expectations/tests/template-fun-ty.rs +++ b/tests/expectations/tests/template-fun-ty.rs @@ -12,6 +12,9 @@ pub struct Foo { } pub type Foo_FunctionPtr = ::std::option::Option T>; +impl Default for Foo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr { @@ -28,4 +31,10 @@ pub struct RefPtr_Proxy { } pub type RefPtr_Proxy_member_function = ::std::option::Option R>; +impl Default for RefPtr_Proxy { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl Default for RefPtr { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type Returner = ::std::option::Option T>; diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 844dc6c2a9..131a54fdae 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -12,6 +12,9 @@ pub struct Foo { pub m_member_arr: [T; 1usize], pub _phantom_1: ::std::marker::PhantomData, } +impl Default for Foo { + 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 { pub m_baz: Z, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for D_U { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl Default for D { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { @@ -37,6 +46,9 @@ pub struct Rooted { pub next: *mut Rooted<*mut ::std::os::raw::c_void>, pub ptr: T, } +impl Default for Rooted { + 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 { pub member: T, } +impl Default for WithDtor { + 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() } } +} /**
*/ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Opaque { pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Opaque { + 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 { pub buff: *mut T, } +impl Default for NestedReplaced { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct NestedBase { pub buff: *mut T, pub _phantom_1: ::std::marker::PhantomData, } +impl Default for NestedBase { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Incomplete { pub d: T, } +impl Default for Incomplete { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct NestedContainer { @@ -132,8 +165,11 @@ pub struct NestedContainer { pub nested: NestedReplaced, pub inc: Incomplete, } +impl Default for NestedContainer { + 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 { pub m_untemplated: Untemplated, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for Templated { + 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 { pub struct ReplacedWithoutDestructor { pub buff: *mut T, } +impl Default for ReplacedWithoutDestructor { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug)] pub struct ShouldNotBeCopiable { pub m_member: ReplacedWithoutDestructor, } +impl Default for ShouldNotBeCopiable { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug)] pub struct ShouldNotBeCopiableAsWell { pub m_member: ReplacedWithoutDestructorFwd, } +impl Default for ShouldNotBeCopiableAsWell { + 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 { pub struct ReplacedWithoutDestructorFwd { pub buff: *mut T, } +impl Default for ReplacedWithoutDestructorFwd { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct TemplateWithVar { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for TemplateWithVar { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[test] fn __bindgen_test_layout_template_1() { assert_eq!(::std::mem::size_of::>() diff --git a/tests/expectations/tests/template_alias.rs b/tests/expectations/tests/template_alias.rs index d301a11c42..44f7830f66 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; pub struct JS_Rooted { pub ptr: JS_detail_Wrapped, } +impl Default for JS_Rooted { + 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 cf4a079c7e..dd4add4083 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 { pub ptr: root::JS::detail::Wrapped, } + impl Default for Rooted { + 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 166ddc3c4c..cc801f3574 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 { pub struct Wrapper_Wrapped { pub t: T, } +impl Default for Wrapper_Wrapped { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type Wrapper_Type = Wrapper_Wrapped; +impl Default for Wrapper { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template_typedefs.rs b/tests/expectations/tests/template_typedefs.rs index 5f0d80b901..9213c0d234 100644 --- a/tests/expectations/tests/template_typedefs.rs +++ b/tests/expectations/tests/template_typedefs.rs @@ -20,3 +20,6 @@ pub type Foo_nsCOMArrayEnumFunc = aData: *mut ::std::os::raw::c_void) -> bool>; +impl Default for Foo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/templateref_opaque.rs b/tests/expectations/tests/templateref_opaque.rs index d69254c814..dfe941af83 100644 --- a/tests/expectations/tests/templateref_opaque.rs +++ b/tests/expectations/tests/templateref_opaque.rs @@ -11,6 +11,9 @@ pub struct detail_PointerType { pub _phantom_0: ::std::marker::PhantomData, } pub type detail_PointerType_Type = *mut T; +impl Default for detail_PointerType { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UniquePtr { @@ -18,3 +21,6 @@ pub struct UniquePtr { pub _phantom_0: ::std::marker::PhantomData, } pub type UniquePtr_Pointer = detail_PointerType; +impl Default for UniquePtr { + 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 f4201a5610..67381d41eb 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 70b5f66c50..2e0f2f4d6c 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; pub struct Rooted { pub ptr: MaybeWrapped, } +impl Default for Rooted { + 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 5dd2038fe6..20665af67d 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 c199b7abc9..47b7a66a55 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 { pub _phantom_0: ::std::marker::PhantomData, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct mozilla_StyleShapeSource__bindgen_ty_1 { pub mPosition: __BindgenUnionField<*mut mozilla_Position>, pub mFragmentOrURL: __BindgenUnionField<*mut mozilla_FragmentOrURL>, pub bindgen_union_field: u64, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for mozilla_StyleShapeSource { + 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 cb69d60347..208b62832a 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 ad707b63a7..bfd573e021 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -29,7 +29,7 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[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 64eb3fe43f..823a0b8b36 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -29,7 +29,7 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[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, diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index fc92afb83e..2eba0f0a4f 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -37,7 +37,7 @@ pub struct NastyStruct { pub _phantom_0: ::std::marker::PhantomData, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct NastyStruct__bindgen_ty_1 { 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 { pub _phantom_0: ::std::marker::PhantomData, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct NastyStruct__bindgen_ty_2 { 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, } +impl Default for NastyStruct { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct Whatever { 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 4b9c635f04..59f8fcab79 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -29,13 +29,13 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub bar: __BindgenUnionField, 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 449fd44004..d14a38bb3f 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 ::std::fmt::Debug for __BindgenUnionField { } } #[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, 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 16b33551bc..9e182d218d 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -29,13 +29,13 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Default, Copy)] pub struct foo { pub bar: __BindgenUnionField, 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 7982728a51..4d0b639f2d 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 ::std::fmt::Debug for __BindgenUnionField { } } #[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, 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 1e7f918c41..fd6f82fc5a 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 ::std::fmt::Debug for __BindgenUnionField { } } #[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, 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 58407cdb10..2b7a8eefd3 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 17c3c8f07b..d92e8efae2 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -29,20 +29,20 @@ impl ::std::fmt::Debug for __BindgenUnionField { } } #[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, 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 12a35760dd..efb8610229 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 f09d151994..dd13156f68 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; diff --git a/tests/expectations/tests/using.rs b/tests/expectations/tests/using.rs index dbb6c84f23..1638287ab6 100644 --- a/tests/expectations/tests/using.rs +++ b/tests/expectations/tests/using.rs @@ -10,5 +10,8 @@ pub struct Point { pub x: T, pub y: T, } +impl Default for Point { + 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 7a09bcb60d..ba10cf2285 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 4515512829..542e1e75b4 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 cd99df960d..32be9f682b 100644 --- a/tests/expectations/tests/variadic_template_function.rs +++ b/tests/expectations/tests/variadic_template_function.rs @@ -10,3 +10,6 @@ pub struct VariadicFunctionObject { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for VariadicFunctionObject { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index 4b68974465..31bc8fd7a0 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 de5e01afd9..0c4109776d 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::() , 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 e051073078..6896eb31c9 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 9937cf5db6..e7ae9f4a73 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 6cf3135f5b..716ce39f5c 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 98765b092d..a2841e341f 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 d0265c4ea4..46af013991 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 { pub y: F, pub _phantom_0: ::std::marker::PhantomData, } +impl Default for PointTyped { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} pub type IntPoint = PointTyped; diff --git a/tests/expectations/tests/whitelist-namespaces-basic.rs b/tests/expectations/tests/whitelist-namespaces-basic.rs index 06f24ff01d..ba96895b62 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 d3707800b6..5e47c9d6bb 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 0104f04959..d67fb7a36a 100644 --- a/tests/expectations/tests/whitelist_basic.rs +++ b/tests/expectations/tests/whitelist_basic.rs @@ -16,3 +16,9 @@ pub struct WhitelistMe { pub struct WhitelistMe_Inner { pub bar: T, } +impl Default for WhitelistMe_Inner { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl Default for WhitelistMe { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/headers/no-derive-debug.h b/tests/headers/no-derive-debug.h index 4a49e40422..c780d2d8f8 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 0000000000..207b93b62f --- /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 5b0ccd1112..ef5b2c2489 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -104,6 +104,7 @@ fn create_bindgen_builder(header: &PathBuf) -> Result, Error> { .ok_or(Error::new(ErrorKind::Other, "Invalid header file name"))); let prepend = ["bindgen", + "--with-derive-default", header_str, "--raw-line", "",