diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ac28244c54..55aaf72926 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -284,20 +284,21 @@ impl AppendImplicitTemplateParams for quote::Tokens { _ => {}, } - if let Some(params) = item.used_template_params(ctx) { - if params.is_empty() { - return; - } + let params = item.used_template_params(ctx); - let params = params.into_iter().map(|p| { - p.try_to_rust_ty(ctx, &()) - .expect("template params cannot fail to be a rust type") - }); - - self.append(quote! { - < #( #params ),* > - }); + if params.is_empty() { + return; } + + let params = params.into_iter().map(|p| { + p.try_to_rust_ty(ctx, &()) + .expect("template params cannot fail to be a rust type") + }); + + self.append(quote! { + < #( #params ),* > + }); + } } @@ -461,11 +462,9 @@ impl CodeGenerator for Var { // We can't generate bindings to static variables of templates. The // number of actual variables for a single declaration are open ended // and we don't know what instantiations do or don't exist. - let type_params = item.all_template_params(ctx); - if let Some(params) = type_params { - if !params.is_empty() { - return; - } + + if !item.all_template_params(ctx).is_empty() { + return } let ty = self.ty().to_rust_ty_or_opaque(ctx, &()); @@ -619,15 +618,15 @@ impl CodeGenerator for Type { return; } - let mut outer_params = item.used_template_params(ctx) - .and_then(|ps| if ps.is_empty() { - None + let mut outer_params = + if !item.used_template_params(ctx).is_empty() { + item.used_template_params(ctx).clone() } else { - Some(ps) - }); + Vec::new() + }; let inner_rust_type = if item.is_opaque(ctx, &()) { - outer_params = None; + outer_params = Vec::new(); self.to_opaque(ctx, item) } else { // Its possible that we have better layout information than @@ -682,7 +681,7 @@ impl CodeGenerator for Type { 'A'...'Z' | 'a'...'z' | '0'...'9' | ':' | '_' | ' ' => true, _ => false, }) && - outer_params.is_none() && + outer_params.is_empty() && inner_item.expect_type().canonical_type(ctx).is_enum() { tokens.append(quote! { @@ -701,8 +700,8 @@ impl CodeGenerator for Type { pub type #rust_name }); - if let Some(params) = outer_params { - let params: Vec<_> = params.into_iter() + if !outer_params.is_empty() { + let params: Vec<_> = outer_params.into_iter() .filter_map(|p| p.as_template_param(ctx, &())) .collect(); if params.iter().any(|p| ctx.resolve_type(*p).is_invalid_type_param()) { @@ -1401,7 +1400,7 @@ impl CodeGenerator for CompInfo { // // NB: We generate a proper struct to avoid struct/function name // collisions. - if self.is_forward_declaration() && used_template_params.is_none() { + if self.is_forward_declaration() && used_template_params.is_empty() { let struct_name = item.canonical_name(ctx); let struct_name = ctx.rust_ident_raw(struct_name); let tuple_struct = quote! { @@ -1584,7 +1583,9 @@ impl CodeGenerator for CompInfo { let mut generic_param_names = vec![]; - if let Some(ref params) = used_template_params { + let ref params = used_template_params; + + if !params.is_empty() { for (idx, ty) in params.iter().enumerate() { let param = ctx.resolve_type(*ty); let name = param.name().unwrap(); @@ -1594,13 +1595,14 @@ impl CodeGenerator for CompInfo { let prefix = ctx.trait_prefix(); let field_name = ctx.rust_ident(format!("_phantom_{}", idx)); fields.push(quote! { - pub #field_name : ::#prefix::marker::PhantomData< - ::#prefix::cell::UnsafeCell<#ident> - > , - }); + pub #field_name : ::#prefix::marker::PhantomData< + ::#prefix::cell::UnsafeCell<#ident> + > , + }); } } + let generics = if !generic_param_names.is_empty() { let generic_param_names = generic_param_names.clone(); quote! { @@ -1642,7 +1644,7 @@ impl CodeGenerator for CompInfo { ctx.options().derive_copy { derives.push("Copy"); - if used_template_params.is_some() { + if !used_template_params.is_empty() { // FIXME: This requires extra logic if you have a big array in a // templated struct. The reason for this is that the magic: // fn clone(&self) -> Self { *self } @@ -1726,7 +1728,7 @@ impl CodeGenerator for CompInfo { ); } - if used_template_params.is_none() { + if used_template_params.is_empty() { if !is_opaque { for var in self.inner_vars() { ctx.resolve_item(*var).codegen(ctx, result, &()); @@ -2928,10 +2930,10 @@ impl TryToRustTy for Type { TypeKind::TemplateAlias(..) | TypeKind::Alias(..) => { let template_params = item.used_template_params(ctx) - .unwrap_or(vec![]) - .into_iter() - .filter(|param| param.is_template_param(ctx, &())) - .collect::>(); + + .into_iter() + .filter(|param| param.is_template_param(ctx, &())) + .collect::>(); let spelling = self.name().expect("Unnamed alias?"); if item.is_opaque(ctx, &()) && !template_params.is_empty() { @@ -2949,7 +2951,7 @@ impl TryToRustTy for Type { TypeKind::Comp(ref info) => { let template_params = item.used_template_params(ctx); if info.has_non_type_template_params() || - (item.is_opaque(ctx, &()) && template_params.is_some()) + (item.is_opaque(ctx, &()) && !template_params.is_empty()) { return self.try_to_opaque(ctx, item); } @@ -3043,18 +3045,18 @@ impl TryToRustTy for TemplateInstantiation { let def_path = def.namespace_aware_canonical_path(ctx); ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), "::"); - let def_params = match def.self_template_params(ctx) { - Some(params) => params, - None => { - // This can happen if we generated an opaque type for a partial - // template specialization, and we've hit an instantiation of - // that partial specialization. - extra_assert!( - def.is_opaque(ctx, &()) - ); - return Err(error::Error::InstantiationOfOpaqueType); - } - }; + let def_params = def.self_template_params(ctx); + + if def_params.is_empty() { + // This can happen if we generated an opaque type for a partial + // template specialization, and we've hit an instantiation of + // that partial specialization. + extra_assert!( + def.is_opaque(ctx, &()) + ); + return Err(error::Error::InstantiationOfOpaqueType); + + } // TODO: If the definition type is a template class/struct // definition's member template definition, it could rely on @@ -3132,12 +3134,12 @@ impl CodeGenerator for Function { // instantiations is open ended and we have no way of knowing which // monomorphizations actually exist. let type_params = item.all_template_params(ctx); - if let Some(params) = type_params { - if !params.is_empty() { - return; - } + + if !type_params.is_empty() { + return; } + let name = self.name(); let mut canonical_name = item.canonical_name(ctx); let mangled_name = self.mangled_name(); diff --git a/src/ir/analysis/derive_copy.rs b/src/ir/analysis/derive_copy.rs index ba40141ee9..8fa074b023 100644 --- a/src/ir/analysis/derive_copy.rs +++ b/src/ir/analysis/derive_copy.rs @@ -241,8 +241,8 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> { } // https://github.com/rust-lang/rust/issues/36640 - if info.self_template_params(self.ctx).is_some() || - item.used_template_params(self.ctx).is_some() + if !info.self_template_params(self.ctx).is_empty() || + !item.used_template_params(self.ctx).is_empty() { trace!( " comp cannot derive copy because issue 36640" diff --git a/src/ir/analysis/template_params.rs b/src/ir/analysis/template_params.rs index 00504aa40e..1659b47fcd 100644 --- a/src/ir/analysis/template_params.rs +++ b/src/ir/analysis/template_params.rs @@ -275,7 +275,7 @@ impl<'ctx> UsedTemplateParameters<'ctx> { let decl = self.ctx.resolve_type(instantiation.template_definition()); let args = instantiation.template_arguments(); - let params = decl.self_template_params(self.ctx).unwrap_or(vec![]); + let params = decl.self_template_params(self.ctx); debug_assert!(this_id != instantiation.template_definition()); let used_by_def = self.used @@ -418,8 +418,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // Although template definitions should always have // template parameters, there is a single exception: // opaque templates. Hence the unwrap_or. - let params = - decl.self_template_params(ctx).unwrap_or(vec![]); + let params = decl.self_template_params(ctx); for (arg, param) in args.iter().zip(params.iter()) { let arg = arg.into_resolver() diff --git a/src/ir/comp.rs b/src/ir/comp.rs index c77834ee36..0e73448d17 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1585,12 +1585,8 @@ impl TemplateParameters for CompInfo { fn self_template_params( &self, _ctx: &BindgenContext, - ) -> Option> { - if self.template_params.is_empty() { - None - } else { - Some(self.template_params.clone()) - } + ) -> Vec { + self.template_params.clone() } } @@ -1601,7 +1597,7 @@ impl Trace for CompInfo { where T: Tracer, { - let params = item.all_template_params(context).unwrap_or(vec![]); + let params = item.all_template_params(context); for p in params { tracer.visit_kind(p.into(), EdgeKind::TemplateParameterDefinition); } diff --git a/src/ir/context.rs b/src/ir/context.rs index 560f6ec247..7a766db8aa 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1306,10 +1306,14 @@ impl BindgenContext { let mut used_params = HashMap::new(); for &id in self.whitelisted_items() { used_params.entry(id).or_insert( - id.self_template_params(self).map_or( - Default::default(), - |params| params.into_iter().map(|p| p.into()).collect(), - ), + if !id.self_template_params(self).is_empty() { + id.self_template_params(self) + .into_iter() + .map(|p| p.into()) + .collect() + } else { + Default::default() + } ); } self.used_template_parameters = Some(used_params); @@ -1492,14 +1496,13 @@ impl BindgenContext { .and_then(|canon_decl| { self.get_resolved_type(&canon_decl).and_then( |template_decl_id| { - template_decl_id.num_self_template_params(self).map( - |num_params| { - ( - *canon_decl.cursor(), - template_decl_id.into(), - num_params, - ) - }, + Some( + ( + *canon_decl.cursor(), + template_decl_id.into(), + template_decl_id + .num_self_template_params(self), + ) ) }, ) @@ -1521,14 +1524,13 @@ impl BindgenContext { .cloned() }) .and_then(|template_decl| { - template_decl.num_self_template_params(self).map( - |num_template_params| { - ( - *template_decl.decl(), - template_decl.id(), - num_template_params, - ) - }, + Some( + ( + *template_decl.decl(), + template_decl.id(), + template_decl + .num_self_template_params(self), + ) ) }) }) @@ -1576,16 +1578,16 @@ impl BindgenContext { ) -> Option { use clang_sys; - let num_expected_args = match self.resolve_type(template) - .num_self_template_params(self) { - Some(n) => n, - None => { - warn!( - "Tried to instantiate a template for which we could not \ - determine any template parameters" - ); - return None; - } + let num_expected_args = self.resolve_type(template) + .num_self_template_params(self); + + if num_expected_args == 0 { + warn!( + "Tried to instantiate a template for which we could not \ + determine any template parameters" + ); + + return None }; let mut args = vec![]; @@ -2562,13 +2564,13 @@ impl TemplateParameters for PartialType { fn self_template_params( &self, _ctx: &BindgenContext, - ) -> Option> { + ) -> Vec { // Maybe at some point we will eagerly parse named types, but for now we // don't and this information is unavailable. - None + Vec::new() } - fn num_self_template_params(&self, _ctx: &BindgenContext) -> Option { + fn num_self_template_params(&self, _ctx: &BindgenContext) -> usize { // Wouldn't it be nice if libclang would reliably give us this // information‽ match self.decl().kind() { @@ -2587,9 +2589,9 @@ impl TemplateParameters for PartialType { }; clang_sys::CXChildVisit_Continue }); - Some(num_params) + num_params } - _ => None, + _ => 0, } } } diff --git a/src/ir/item.rs b/src/ir/item.rs index dbc352eb84..e8a7e0830c 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1090,10 +1090,12 @@ where fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option> { - ctx.resolve_item_fallible(*self).and_then(|item| { + ) -> Vec { + if let Some(item) = ctx.resolve_item_fallible(*self) { item.self_template_params(ctx) - }) + } else { + Vec::new() + } } } @@ -1101,7 +1103,7 @@ impl TemplateParameters for Item { fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option> { + ) -> Vec { self.kind.self_template_params(ctx) } } @@ -1110,7 +1112,7 @@ impl TemplateParameters for ItemKind { fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option> { + ) -> Vec { match *self { ItemKind::Type(ref ty) => ty.self_template_params(ctx), // If we start emitting bindings to explicitly instantiated @@ -1118,7 +1120,7 @@ impl TemplateParameters for ItemKind { // template params. ItemKind::Function(_) | ItemKind::Module(_) | - ItemKind::Var(_) => None, + ItemKind::Var(_) => Vec::new(), } } } diff --git a/src/ir/template.rs b/src/ir/template.rs index f5cc015234..afd909b5f3 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -36,7 +36,7 @@ use parse::ClangItemParser; /// Template declaration (and such declaration's template parameters) related /// methods. /// -/// This trait's methods distinguish between `None` and `Some([])` for +/// This trait's methods distinguish between [] and [T] for /// declarations that are not templates and template declarations with zero /// parameters, in general. /// @@ -81,23 +81,23 @@ use parse::ClangItemParser; /// +------+----------------------+--------------------------+------------------------+---- /// |Decl. | self_template_params | num_self_template_params | all_template_parameters| ... /// +------+----------------------+--------------------------+------------------------+---- -/// |Foo | Some([T, U]) | Some(2) | Some([T, U]) | ... -/// |Bar | Some([V]) | Some(1) | Some([T, U, V]) | ... -/// |Inner | None | None | Some([T, U]) | ... -/// |Lol | Some([W]) | Some(1) | Some([T, U, W]) | ... -/// |Wtf | Some([X]) | Some(1) | Some([T, U, X]) | ... -/// |Qux | None | None | None | ... +/// |Foo | [T, U] | 2 | [T, U] | ... +/// |Bar | [V] | 1 | [T, U, V] | ... +/// |Inner | [] | 0 | [T, U] | ... +/// |Lol | [W] | 1 | [T, U, W] | ... +/// |Wtf | [X] | 1 | [T, U, X] | ... +/// |Qux | [] | 0 | [] | ... /// +------+----------------------+--------------------------+------------------------+---- /// /// ----+------+-----+----------------------+ /// ... |Decl. | ... | used_template_params | /// ----+------+-----+----------------------+ -/// ... |Foo | ... | Some([T, U]) | -/// ... |Bar | ... | Some([V]) | -/// ... |Inner | ... | None | -/// ... |Lol | ... | Some([T]) | -/// ... |Wtf | ... | Some([T]) | -/// ... |Qux | ... | None | +/// ... |Foo | ... | [T, U] | +/// ... |Bar | ... | [V] | +/// ... |Inner | ... | [] | +/// ... |Lol | ... | [T] | +/// ... |Wtf | ... | [T] | +/// ... |Qux | ... | [] | /// ----+------+-----+----------------------+ pub trait TemplateParameters { /// Get the set of `ItemId`s that make up this template declaration's free @@ -109,24 +109,24 @@ pub trait TemplateParameters { /// anything but types, so we must treat them as opaque, and avoid /// instantiating them. fn self_template_params(&self, ctx: &BindgenContext) - -> Option>; + -> Vec; /// Get the number of free template parameters this template declaration /// has. /// - /// Implementations *may* return `Some` from this method when - /// `template_params` returns `None`. This is useful when we only have + /// Implementations *may* return a number > 0 from this method when + /// `template_params` returns []. This is useful when we only have /// partial information about the template declaration, such as when we are /// in the middle of parsing it. - fn num_self_template_params(&self, ctx: &BindgenContext) -> Option { - self.self_template_params(ctx).map(|params| params.len()) + fn num_self_template_params(&self, ctx: &BindgenContext) -> usize { + self.self_template_params(ctx).len() } /// Get the complete set of template parameters that can affect this /// declaration. /// /// Note that this item doesn't need to be a template declaration itself for - /// `Some` to be returned here (in contrast to `self_template_params`). If + /// [T] to be returned here (in contrast to `self_template_params`). If /// this item is a member of a template declaration, then the parent's /// template parameters are included here. /// @@ -136,30 +136,28 @@ pub trait TemplateParameters { /// how we would fully reference such a member type in C++: /// `Foo::Inner`. `Foo` *must* be instantiated with template /// arguments before we can gain access to the `Inner` member type. - fn all_template_params(&self, ctx: &BindgenContext) -> Option> + fn all_template_params(&self, ctx: &BindgenContext) -> Vec where Self: ItemAncestors, { let each_self_params: Vec> = self.ancestors(ctx) - .filter_map(|id| id.self_template_params(ctx)) + .map(|id| id.self_template_params(ctx)) .collect(); if each_self_params.is_empty() { - None + Vec::new() } else { - Some( - each_self_params - .into_iter() - .rev() - .flat_map(|params| params) - .collect(), - ) + each_self_params + .into_iter() + .rev() + .flat_map(|params| params) + .collect() } } /// Get only the set of template parameters that this item uses. This is a /// subset of `all_template_params` and does not necessarily contain any of /// `self_template_params`. - fn used_template_params(&self, ctx: &BindgenContext) -> Option> + fn used_template_params(&self, ctx: &BindgenContext) -> Vec where Self: AsRef, { @@ -169,14 +167,10 @@ pub trait TemplateParameters { ); let id = *self.as_ref(); - ctx.resolve_item(id).all_template_params(ctx).map( - |all_params| { - all_params - .into_iter() - .filter(|p| ctx.uses_template_parameter(id, *p)) - .collect() - }, - ) + ctx.resolve_item(id).all_template_params(ctx) + .into_iter() + .filter(|p| ctx.uses_template_parameter(id, *p)) + .collect() } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 0db913852d..56e130d635 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -543,7 +543,7 @@ impl TemplateParameters for Type { fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option> { + ) -> Vec { self.kind.self_template_params(ctx) } } @@ -552,13 +552,13 @@ impl TemplateParameters for TypeKind { fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option> { + ) -> Vec { match *self { TypeKind::ResolvedTypeRef(id) => { ctx.resolve_type(id).self_template_params(ctx) } TypeKind::Comp(ref comp) => comp.self_template_params(ctx), - TypeKind::TemplateAlias(_, ref args) => Some(args.clone()), + TypeKind::TemplateAlias(_, ref args) => args.clone(), TypeKind::Opaque | TypeKind::TemplateInstantiation(..) | @@ -578,7 +578,7 @@ impl TemplateParameters for TypeKind { TypeKind::Alias(_) | TypeKind::ObjCId | TypeKind::ObjCSel | - TypeKind::ObjCInterface(_) => None, + TypeKind::ObjCInterface(_) => Vec::new(), } } } diff --git a/tests/expectations/tests/381-decltype-alias.rs b/tests/expectations/tests/381-decltype-alias.rs index 7f2bb8787b..6fbc03b368 100644 --- a/tests/expectations/tests/381-decltype-alias.rs +++ b/tests/expectations/tests/381-decltype-alias.rs @@ -5,8 +5,13 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct std_allocator_traits { pub _address: u8, } pub type std_allocator_traits___size_type<_Alloc> = _Alloc; +impl Clone for std_allocator_traits { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index f0c1d364f5..2b588c448c 100644 --- a/tests/expectations/tests/anon_enum_trait.rs +++ b/tests/expectations/tests/anon_enum_trait.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct DataType { pub _address: u8, } @@ -13,19 +13,21 @@ pub type DataType_value_type<_Tp> = _Tp; pub type DataType_work_type<_Tp> = DataType_value_type<_Tp>; pub type DataType_channel_type<_Tp> = DataType_value_type<_Tp>; pub type DataType_vec_type<_Tp> = DataType_value_type<_Tp>; -pub const DataType_generic_type: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_depth: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_channels: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_fmt: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_type_: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; +pub const DataType_generic_type: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_depth: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum DataType__bindgen_ty_1 { generic_type = 0, } +pub enum DataType__bindgen_ty_1 { + generic_type = 0, +} +impl Clone for DataType { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Foo { @@ -35,14 +37,24 @@ pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Foo__bindgen_ty_1 { Bar = 0, } +pub enum Foo__bindgen_ty_1 { + Bar = 0, +} #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Foo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Foo ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); } impl Clone for Foo { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index f2da118da2..7660f19343 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -5,6 +5,7 @@ #[repr(C)] +#[derive(Copy)] pub struct TErrorResult { pub mResult: ::std::os::raw::c_int, pub __bindgen_anon_1: TErrorResult__bindgen_ty_1, @@ -15,49 +16,103 @@ pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum TErrorResult_UnionState { HasMessage = 0, } +pub enum TErrorResult_UnionState { + HasMessage = 0, +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone)] pub struct TErrorResult_Message { - pub _address: u8, + _unused: [u8; 0], } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone)] pub struct TErrorResult_DOMExceptionInfo { - pub _address: u8, + _unused: [u8; 0], } #[repr(C)] +#[derive(Copy)] pub union TErrorResult__bindgen_ty_1 { pub mMessage: *mut TErrorResult_Message, pub mDOMExceptionInfo: *mut TErrorResult_DOMExceptionInfo, _bindgen_union_align: u64, } +#[test] +fn bindgen_test_layout_TErrorResult__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TErrorResult__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TErrorResult__bindgen_ty_1)) + ); +} +impl Clone for TErrorResult__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } +} impl Default for TErrorResult__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl Clone for TErrorResult { + fn clone(&self) -> Self { + *self + } } impl Default for TErrorResult { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] +#[derive(Copy)] pub struct ErrorResult { pub _base: TErrorResult, } #[test] fn bindgen_test_layout_ErrorResult() { - assert_eq!(::std::mem::size_of::() , 24usize , concat ! ( - "Size of: " , stringify ! ( ErrorResult ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( ErrorResult ) )); + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(ErrorResult)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ErrorResult)) + ); +} +impl Clone for ErrorResult { + fn clone(&self) -> Self { + *self + } } impl Default for ErrorResult { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 24usize , concat ! ( - "Size of template specialization: " , stringify ! ( - TErrorResult ) )); - assert_eq!(::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - TErrorResult ) )); + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(TErrorResult) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(TErrorResult) + ) + ); } diff --git a/tests/expectations/tests/anon_union_1_0.rs b/tests/expectations/tests/anon_union_1_0.rs index b96928d42a..b163e9ebd9 100644 --- a/tests/expectations/tests/anon_union_1_0.rs +++ b/tests/expectations/tests/anon_union_1_0.rs @@ -6,37 +6,49 @@ #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { +impl __BindgenUnionField { #[inline] - pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } + pub fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } #[inline] - pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) } + pub unsafe fn as_ref(&self) -> &T { + ::std::mem::transmute(self) + } #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) } + pub unsafe fn as_mut(&mut self) -> &mut T { + ::std::mem::transmute(self) + } } -impl ::std::default::Default for __BindgenUnionField { +impl ::std::default::Default for __BindgenUnionField { #[inline] - fn default() -> Self { Self::new() } + fn default() -> Self { + Self::new() + } } -impl ::std::clone::Clone for __BindgenUnionField { +impl ::std::clone::Clone for __BindgenUnionField { #[inline] - fn clone(&self) -> Self { Self::new() } + fn clone(&self) -> Self { + Self::new() + } } -impl ::std::marker::Copy for __BindgenUnionField { } -impl ::std::fmt::Debug for __BindgenUnionField { +impl ::std::marker::Copy for __BindgenUnionField {} +impl ::std::fmt::Debug for __BindgenUnionField { fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fmt.write_str("__BindgenUnionField") } } -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) { } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) {} } -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { true } +impl ::std::cmp::PartialEq for __BindgenUnionField { + fn eq(&self, _other: &__BindgenUnionField) -> bool { + true + } } -impl ::std::cmp::Eq for __BindgenUnionField { } +impl ::std::cmp::Eq for __BindgenUnionField {} #[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct TErrorResult { pub mResult: ::std::os::raw::c_int, pub __bindgen_anon_1: TErrorResult__bindgen_ty_1, @@ -47,26 +59,53 @@ pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum TErrorResult_UnionState { HasMessage = 0, } +pub enum TErrorResult_UnionState { + HasMessage = 0, +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone)] pub struct TErrorResult_Message { - pub _address: u8, + _unused: [u8; 0], } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone)] pub struct TErrorResult_DOMExceptionInfo { - pub _address: u8, + _unused: [u8; 0], } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct TErrorResult__bindgen_ty_1 { pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, pub bindgen_union_field: u64, } +#[test] +fn bindgen_test_layout_TErrorResult__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TErrorResult__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TErrorResult__bindgen_ty_1)) + ); +} +impl Clone for TErrorResult__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } +} +impl Clone for TErrorResult { + fn clone(&self) -> Self { + *self + } +} impl Default for TErrorResult { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] @@ -75,23 +114,43 @@ pub struct ErrorResult { } #[test] fn bindgen_test_layout_ErrorResult() { - assert_eq!(::std::mem::size_of::() , 24usize , concat ! ( - "Size of: " , stringify ! ( ErrorResult ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( ErrorResult ) )); + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(ErrorResult)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ErrorResult)) + ); } impl Clone for ErrorResult { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } impl Default for ErrorResult { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 24usize , concat ! ( - "Size of template specialization: " , stringify ! ( - TErrorResult ) )); - assert_eq!(::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - TErrorResult ) )); + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(TErrorResult) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(TErrorResult) + ) + ); } diff --git a/tests/expectations/tests/anonymous-template-types.rs b/tests/expectations/tests/anonymous-template-types.rs index 532e2427c9..d1da6d797c 100644 --- a/tests/expectations/tests/anonymous-template-types.rs +++ b/tests/expectations/tests/anonymous-template-types.rs @@ -10,26 +10,40 @@ pub struct Foo { pub t_member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for Foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for Foo { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Bar { pub member: ::std::os::raw::c_char, } +impl Clone for Bar { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Quux { pub v_member: V, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for Quux { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for Quux { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Lobo { pub also_member: ::std::os::raw::c_char, } +impl Clone for Lobo { + fn clone(&self) -> Self { + *self + } +} pub type AliasWithAnonType = ::std::os::raw::c_char; diff --git a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs index 3bd9bec0b8..d652060469 100644 --- a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs +++ b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs @@ -5,15 +5,27 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct std_char_traits { pub _address: u8, } +impl Clone for std_char_traits { + fn clone(&self) -> Self { + *self + } +} impl Default for std_char_traits { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct __gnu_cxx_char_traits { pub _address: u8, } +impl Clone for __gnu_cxx_char_traits { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/constant-non-specialized-tp.rs b/tests/expectations/tests/constant-non-specialized-tp.rs index 8be8e5d3b2..33a72e3f2f 100644 --- a/tests/expectations/tests/constant-non-specialized-tp.rs +++ b/tests/expectations/tests/constant-non-specialized-tp.rs @@ -5,17 +5,32 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Test { pub _address: u8, } +impl Clone for Test { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Outer { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Outer_Inner { pub _address: u8, } +impl Clone for Outer_Inner { + fn clone(&self) -> Self { + *self + } +} +impl Clone for Outer { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/constructor-tp.rs b/tests/expectations/tests/constructor-tp.rs index 534f70e3f3..d770186ab6 100644 --- a/tests/expectations/tests/constructor-tp.rs +++ b/tests/expectations/tests/constructor-tp.rs @@ -5,10 +5,15 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub _address: u8, } +impl Clone for Foo { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Bar { @@ -16,17 +21,25 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)) + ); } extern "C" { #[link_name = "\u{1}_ZN3BarC1Ev"] pub fn Bar_Bar(this: *mut Bar); } impl Clone for Bar { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } impl Bar { #[inline] diff --git a/tests/expectations/tests/crtp.rs b/tests/expectations/tests/crtp.rs index f2b1dbd853..75bb6ea30e 100644 --- a/tests/expectations/tests/crtp.rs +++ b/tests/expectations/tests/crtp.rs @@ -5,10 +5,15 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Base { pub _address: u8, } +impl Clone for Base { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Derived { @@ -16,13 +21,21 @@ pub struct Derived { } #[test] fn bindgen_test_layout_Derived() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( Derived ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( Derived ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Derived)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Derived)) + ); } impl Clone for Derived { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[repr(C)] #[derive(Debug, Default)] @@ -36,30 +49,47 @@ pub struct DerivedFromBaseWithDestructor { } #[test] fn bindgen_test_layout_DerivedFromBaseWithDestructor() { - assert_eq!(::std::mem::size_of::() , 1usize - , concat ! ( - "Size of: " , stringify ! ( DerivedFromBaseWithDestructor ) )); - assert_eq! (::std::mem::align_of::() , - 1usize , concat ! ( - "Alignment of " , stringify ! ( DerivedFromBaseWithDestructor - ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(DerivedFromBaseWithDestructor)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(DerivedFromBaseWithDestructor)) + ); } #[test] fn __bindgen_test_layout_Base_open0_Derived_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( Base ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( Base ) - )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Base)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Base)) + ); } #[test] -fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! - ( - "Size of template specialization: " , stringify ! ( - BaseWithDestructor ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat - ! ( - "Alignment of template specialization: " , stringify ! ( - BaseWithDestructor ) )); +fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation( +) { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!( + "Size of template specialization: ", + stringify!(BaseWithDestructor) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(BaseWithDestructor) + ) + ); } diff --git a/tests/expectations/tests/dash_language.rs b/tests/expectations/tests/dash_language.rs index f6d15d1c24..bd319b94ee 100644 --- a/tests/expectations/tests/dash_language.rs +++ b/tests/expectations/tests/dash_language.rs @@ -5,7 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub bar: ::std::os::raw::c_int, } +impl Clone for Foo { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/empty_template_param_name.rs b/tests/expectations/tests/empty_template_param_name.rs index 30289ce48a..944e48decd 100644 --- a/tests/expectations/tests/empty_template_param_name.rs +++ b/tests/expectations/tests/empty_template_param_name.rs @@ -6,7 +6,12 @@ pub type __void_t = ::std::os::raw::c_void; #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct __iterator_traits { pub _address: u8, } +impl Clone for __iterator_traits { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/enum_in_template_with_typedef.rs b/tests/expectations/tests/enum_in_template_with_typedef.rs index 8c8195354e..8e937a7f98 100644 --- a/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct std_fbstring_core { pub _address: u8, } @@ -14,4 +14,11 @@ pub const std_fbstring_core_Category_Bar: std_fbstring_core_Category = std_fbstring_core_Category::Foo; #[repr(u8)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum std_fbstring_core_Category { Foo = 0, } +pub enum std_fbstring_core_Category { + Foo = 0, +} +impl Clone for std_fbstring_core { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/eval-variadic-template-parameter.rs b/tests/expectations/tests/eval-variadic-template-parameter.rs index 1386396f46..b143de4a12 100644 --- a/tests/expectations/tests/eval-variadic-template-parameter.rs +++ b/tests/expectations/tests/eval-variadic-template-parameter.rs @@ -5,7 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct B { pub _address: u8, } +impl Clone for B { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/forward-inherit-struct.rs b/tests/expectations/tests/forward-inherit-struct.rs index e3f2b225ea..777d32142d 100644 --- a/tests/expectations/tests/forward-inherit-struct.rs +++ b/tests/expectations/tests/forward-inherit-struct.rs @@ -5,15 +5,27 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct js_RootedBase { pub _address: u8, } +impl Clone for js_RootedBase { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct Rooted { pub _address: u8, } +impl Clone for Rooted { + fn clone(&self) -> Self { + *self + } +} impl Default for Rooted { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + 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 92a23ad31c..764711d9a9 100644 --- a/tests/expectations/tests/in_class_typedef.rs +++ b/tests/expectations/tests/in_class_typedef.rs @@ -5,15 +5,25 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub _address: u8, } pub type Foo_elem_type = T; pub type Foo_ptr_type = *mut T; #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Foo_Bar { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } +impl Clone for Foo_Bar { + fn clone(&self) -> Self { + *self + } +} +impl Clone for Foo { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/inherit-namespaced.rs b/tests/expectations/tests/inherit-namespaced.rs index e3f2b225ea..777d32142d 100644 --- a/tests/expectations/tests/inherit-namespaced.rs +++ b/tests/expectations/tests/inherit-namespaced.rs @@ -5,15 +5,27 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct js_RootedBase { pub _address: u8, } +impl Clone for js_RootedBase { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct Rooted { pub _address: u8, } +impl Clone for Rooted { + fn clone(&self) -> Self { + *self + } +} impl Default for Rooted { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/inherit_named.rs b/tests/expectations/tests/inherit_named.rs index 0503804a7c..71c2da5603 100644 --- a/tests/expectations/tests/inherit_named.rs +++ b/tests/expectations/tests/inherit_named.rs @@ -5,16 +5,23 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Wohoo { pub _address: u8, } +impl Clone for Wohoo { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Weeee { pub _base: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for Weeee { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for Weeee { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/inline_namespace_no_ns_enabled.rs b/tests/expectations/tests/inline_namespace_no_ns_enabled.rs index c2592e577c..58435d67b1 100644 --- a/tests/expectations/tests/inline_namespace_no_ns_enabled.rs +++ b/tests/expectations/tests/inline_namespace_no_ns_enabled.rs @@ -13,12 +13,19 @@ pub struct std_basic_string { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct std_basic_string_Alloc_hider { pub storage: *mut ::std::os::raw::c_void, } +impl Clone for std_basic_string_Alloc_hider { + fn clone(&self) -> Self { + *self + } +} impl Default for std_basic_string_Alloc_hider { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] #[derive(Debug)] @@ -26,9 +33,13 @@ pub struct std_basic_string__bindgen_ty_1 { pub inline_storage: [CharT; 4usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for std_basic_string__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for std_basic_string__bindgen_ty_1 { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } -impl Default for std_basic_string { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for std_basic_string { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index b94ba60f70..b7b14057e8 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -5,13 +5,20 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct LinkedList { pub next: *mut LinkedList, pub prev: *mut LinkedList, } +impl Clone for LinkedList { + fn clone(&self) -> Self { + *self + } +} impl Default for LinkedList { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] #[derive(Debug, Copy)] @@ -20,28 +27,50 @@ pub struct InstantiateIt { } #[test] fn bindgen_test_layout_InstantiateIt() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of: " , stringify ! ( InstantiateIt ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( InstantiateIt ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const InstantiateIt ) ) . m_list as * const _ - as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( InstantiateIt ) , "::" - , stringify ! ( m_list ) )); + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(InstantiateIt)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(InstantiateIt)) + ); + assert_eq!( + unsafe { &(*(0 as *const InstantiateIt)).m_list as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(InstantiateIt), + "::", + stringify!(m_list) + ) + ); } impl Clone for InstantiateIt { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } impl Default for InstantiateIt { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_LinkedList_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( - "Size of template specialization: " , stringify ! ( LinkedList - ) )); - assert_eq!(::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - LinkedList ) )); + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of template specialization: ", stringify!(LinkedList)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(LinkedList) + ) + ); } diff --git a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs index 265109106a..c0834eadb1 100644 --- a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs +++ b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs @@ -5,8 +5,13 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct a { pub _address: u8, } pub type a__bindgen_ty_1 = i32; +impl Clone for a { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/issue-358.rs b/tests/expectations/tests/issue-358.rs index c094b3337a..8ae4fb9bf5 100644 --- a/tests/expectations/tests/issue-358.rs +++ b/tests/expectations/tests/issue-358.rs @@ -5,18 +5,32 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct JS_PersistentRooted { pub _base: a, } +impl Clone for JS_PersistentRooted { + fn clone(&self) -> Self { + *self + } +} impl Default for JS_PersistentRooted { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct a { pub b: *mut a, } +impl Clone for a { + fn clone(&self) -> Self { + *self + } +} impl Default for a { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/issue-446.rs b/tests/expectations/tests/issue-446.rs index d416548d88..f6c4120e26 100644 --- a/tests/expectations/tests/issue-446.rs +++ b/tests/expectations/tests/issue-446.rs @@ -5,18 +5,32 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct List { pub next: *mut List, } +impl Clone for List { + fn clone(&self) -> Self { + *self + } +} impl Default for List { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct PersistentRooted { pub root_list: List, } +impl Clone for PersistentRooted { + fn clone(&self) -> Self { + *self + } +} impl Default for PersistentRooted { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index 7a9473660d..9f1e24d738 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -5,38 +5,7 @@ #[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } - #[inline] - pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { Self::new() } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { Self::new() } -} -impl ::std::marker::Copy for __BindgenUnionField { } -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) { } -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { true } -} -impl ::std::cmp::Eq for __BindgenUnionField { } -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct basic_string { pub _address: u8, } @@ -44,73 +13,181 @@ pub type basic_string_size_type = ::std::os::raw::c_ulonglong; pub type basic_string_value_type = ::std::os::raw::c_char; pub type basic_string_pointer = *mut basic_string_value_type; #[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct basic_string___long { pub __cap_: basic_string_size_type, pub __size_: basic_string_size_type, pub __data_: basic_string_pointer, } +impl Clone for basic_string___long { + fn clone(&self) -> Self { + *self + } +} impl Default for basic_string___long { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum basic_string__bindgen_ty_1 { __min_cap = 0, } +pub enum basic_string__bindgen_ty_1 { + __min_cap = 0, +} #[repr(C)] +#[derive(Copy)] pub struct basic_string___short { pub __bindgen_anon_1: basic_string___short__bindgen_ty_1, pub __data_: *mut basic_string_value_type, } #[repr(C)] +#[derive(Copy)] pub union basic_string___short__bindgen_ty_1 { pub __size_: ::std::os::raw::c_uchar, pub __lx: basic_string_value_type, _bindgen_union_align: u8, } +#[test] +fn bindgen_test_layout_basic_string___short__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(basic_string___short__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of ", + stringify!(basic_string___short__bindgen_ty_1) + ) + ); +} +impl Clone for basic_string___short__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } +} impl Default for basic_string___short__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl Clone for basic_string___short { + fn clone(&self) -> Self { + *self + } } impl Default for basic_string___short { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -pub struct basic_string___ulx { - pub __lx: __BindgenUnionField, - pub __lxx: __BindgenUnionField, - pub bindgen_union_field: [u8; 0usize], +#[derive(Copy)] +pub union basic_string___ulx { + pub __lx: basic_string___long, + pub __lxx: basic_string___short, + _bindgen_union_align: [u8; 0usize], +} +#[test] +fn bindgen_test_layout_basic_string___ulx() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(basic_string___ulx)) + ); + assert_eq!( + ::std::mem::align_of::(), + 0usize, + concat!("Alignment of ", stringify!(basic_string___ulx)) + ); +} +impl Clone for basic_string___ulx { + fn clone(&self) -> Self { + *self + } } impl Default for basic_string___ulx { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum basic_string__bindgen_ty_2 { __n_words = 0, } +pub enum basic_string__bindgen_ty_2 { + __n_words = 0, +} #[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct basic_string___raw { pub __words: *mut basic_string_size_type, } +impl Clone for basic_string___raw { + fn clone(&self) -> Self { + *self + } +} impl Default for basic_string___raw { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] +#[derive(Copy)] pub struct basic_string___rep { pub __bindgen_anon_1: basic_string___rep__bindgen_ty_1, } #[repr(C)] -pub struct basic_string___rep__bindgen_ty_1 { - pub __l: __BindgenUnionField, - pub __s: __BindgenUnionField, - pub __r: __BindgenUnionField, - pub bindgen_union_field: [u8; 0usize], +#[derive(Copy)] +pub union basic_string___rep__bindgen_ty_1 { + pub __l: basic_string___long, + pub __s: basic_string___short, + pub __r: basic_string___raw, + _bindgen_union_align: [u8; 0usize], +} +#[test] +fn bindgen_test_layout_basic_string___rep__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(basic_string___rep__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 0usize, + concat!( + "Alignment of ", + stringify!(basic_string___rep__bindgen_ty_1) + ) + ); +} +impl Clone for basic_string___rep__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } } impl Default for basic_string___rep__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl Clone for basic_string___rep { + fn clone(&self) -> Self { + *self + } } impl Default for basic_string___rep { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl Clone for basic_string { + fn clone(&self) -> Self { + *self + } } diff --git a/tests/expectations/tests/issue-493_1_0.rs b/tests/expectations/tests/issue-493_1_0.rs index 710cd41e26..a04c4f8d91 100644 --- a/tests/expectations/tests/issue-493_1_0.rs +++ b/tests/expectations/tests/issue-493_1_0.rs @@ -6,37 +6,49 @@ #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { +impl __BindgenUnionField { #[inline] - pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } + pub fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } #[inline] - pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) } + pub unsafe fn as_ref(&self) -> &T { + ::std::mem::transmute(self) + } #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) } + pub unsafe fn as_mut(&mut self) -> &mut T { + ::std::mem::transmute(self) + } } -impl ::std::default::Default for __BindgenUnionField { +impl ::std::default::Default for __BindgenUnionField { #[inline] - fn default() -> Self { Self::new() } + fn default() -> Self { + Self::new() + } } -impl ::std::clone::Clone for __BindgenUnionField { +impl ::std::clone::Clone for __BindgenUnionField { #[inline] - fn clone(&self) -> Self { Self::new() } + fn clone(&self) -> Self { + Self::new() + } } -impl ::std::marker::Copy for __BindgenUnionField { } -impl ::std::fmt::Debug for __BindgenUnionField { +impl ::std::marker::Copy for __BindgenUnionField {} +impl ::std::fmt::Debug for __BindgenUnionField { fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fmt.write_str("__BindgenUnionField") } } -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) { } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) {} } -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { true } +impl ::std::cmp::PartialEq for __BindgenUnionField { + fn eq(&self, _other: &__BindgenUnionField) -> bool { + true + } } -impl ::std::cmp::Eq for __BindgenUnionField { } +impl ::std::cmp::Eq for __BindgenUnionField {} #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct basic_string { pub _address: u8, } @@ -44,75 +56,176 @@ pub type basic_string_size_type = ::std::os::raw::c_ulonglong; pub type basic_string_value_type = ::std::os::raw::c_char; pub type basic_string_pointer = *mut basic_string_value_type; #[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct basic_string___long { pub __cap_: basic_string_size_type, pub __size_: basic_string_size_type, pub __data_: basic_string_pointer, } +impl Clone for basic_string___long { + fn clone(&self) -> Self { + *self + } +} impl Default for basic_string___long { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum basic_string__bindgen_ty_1 { __min_cap = 0, } +pub enum basic_string__bindgen_ty_1 { + __min_cap = 0, +} #[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct basic_string___short { pub __bindgen_anon_1: basic_string___short__bindgen_ty_1, pub __data_: *mut basic_string_value_type, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct basic_string___short__bindgen_ty_1 { pub __size_: __BindgenUnionField<::std::os::raw::c_uchar>, pub __lx: __BindgenUnionField, pub bindgen_union_field: u8, } +#[test] +fn bindgen_test_layout_basic_string___short__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(basic_string___short__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of ", + stringify!(basic_string___short__bindgen_ty_1) + ) + ); +} +impl Clone for basic_string___short__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } +} +impl Clone for basic_string___short { + fn clone(&self) -> Self { + *self + } +} impl Default for basic_string___short { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy)] pub struct basic_string___ulx { pub __lx: __BindgenUnionField, pub __lxx: __BindgenUnionField, pub bindgen_union_field: [u8; 0usize], } +#[test] +fn bindgen_test_layout_basic_string___ulx() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(basic_string___ulx)) + ); + assert_eq!( + ::std::mem::align_of::(), + 0usize, + concat!("Alignment of ", stringify!(basic_string___ulx)) + ); +} +impl Clone for basic_string___ulx { + fn clone(&self) -> Self { + *self + } +} impl Default for basic_string___ulx { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum basic_string__bindgen_ty_2 { __n_words = 0, } +pub enum basic_string__bindgen_ty_2 { + __n_words = 0, +} #[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct basic_string___raw { pub __words: *mut basic_string_size_type, } +impl Clone for basic_string___raw { + fn clone(&self) -> Self { + *self + } +} impl Default for basic_string___raw { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy)] pub struct basic_string___rep { pub __bindgen_anon_1: basic_string___rep__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy)] pub struct basic_string___rep__bindgen_ty_1 { pub __l: __BindgenUnionField, pub __s: __BindgenUnionField, pub __r: __BindgenUnionField, pub bindgen_union_field: [u8; 0usize], } +#[test] +fn bindgen_test_layout_basic_string___rep__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(basic_string___rep__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 0usize, + concat!( + "Alignment of ", + stringify!(basic_string___rep__bindgen_ty_1) + ) + ); +} +impl Clone for basic_string___rep__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } +} impl Default for basic_string___rep__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl Clone for basic_string___rep { + fn clone(&self) -> Self { + *self + } } impl Default for basic_string___rep { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl Clone for basic_string { + fn clone(&self) -> Self { + *self + } } diff --git a/tests/expectations/tests/issue-544-stylo-creduce.rs b/tests/expectations/tests/issue-544-stylo-creduce.rs index fbee3b2556..7f58c3cd54 100644 --- a/tests/expectations/tests/issue-544-stylo-creduce.rs +++ b/tests/expectations/tests/issue-544-stylo-creduce.rs @@ -5,7 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct a { pub _address: u8, } +impl Clone for a { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 3eae94880a..a558b0355e 100644 --- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -8,15 +8,25 @@ pub const ENUM_VARIANT_1: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_1; pub const ENUM_VARIANT_2: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_2; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum _bindgen_ty_1 { ENUM_VARIANT_1 = 0, ENUM_VARIANT_2 = 1, } +pub enum _bindgen_ty_1 { + ENUM_VARIANT_1 = 0, + ENUM_VARIANT_2 = 1, +} pub type JS_Alias = u8; #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct JS_Base { pub f: JS_Alias, } +impl Clone for JS_Base { + fn clone(&self) -> Self { + *self + } +} impl Default for JS_Base { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] #[derive(Debug, Copy)] @@ -25,23 +35,40 @@ pub struct JS_AutoIdVector { } #[test] fn bindgen_test_layout_JS_AutoIdVector() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( JS_AutoIdVector ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! - ( "Alignment of " , stringify ! ( JS_AutoIdVector ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(JS_AutoIdVector)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(JS_AutoIdVector)) + ); } impl Clone for JS_AutoIdVector { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } impl Default for JS_AutoIdVector { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_JS_Base_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( JS_Base ) - )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - JS_Base ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(JS_Base)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(JS_Base) + ) + ); } diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index 50ea61e075..373c99da94 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -5,10 +5,15 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Outer { pub i: u8, } +impl Clone for Outer { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct AutoIdVector { @@ -16,24 +21,42 @@ pub struct AutoIdVector { } #[test] fn bindgen_test_layout_AutoIdVector() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( AutoIdVector ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( AutoIdVector ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const AutoIdVector ) ) . ar as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( AutoIdVector ) , "::" , - stringify ! ( ar ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(AutoIdVector)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AutoIdVector)) + ); + assert_eq!( + unsafe { &(*(0 as *const AutoIdVector)).ar as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(AutoIdVector), + "::", + stringify!(ar) + ) + ); } impl Clone for AutoIdVector { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[test] fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( Outer ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( Outer - ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Outer)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Outer)) + ); } diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 0d13c10dca..c5011253dd 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -5,10 +5,15 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct a { pub _address: u8, } +impl Clone for a { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct _bindgen_ty_1 { @@ -16,18 +21,31 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 1usize , concat ! ( - "Size of: " , stringify ! ( _bindgen_ty_1 ) )); - assert_eq! (::std::mem::align_of::<_bindgen_ty_1>() , 1usize , concat ! ( - "Alignment of " , stringify ! ( _bindgen_ty_1 ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const _bindgen_ty_1 ) ) . ar as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" - , stringify ! ( ar ) )); + assert_eq!( + ::std::mem::size_of::<_bindgen_ty_1>(), + 1usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::<_bindgen_ty_1>(), + 1usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(0 as *const _bindgen_ty_1)).ar as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(ar) + ) + ); } impl Clone for _bindgen_ty_1 { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } extern "C" { #[link_name = "\u{1}AutoIdVector"] @@ -35,9 +53,14 @@ extern "C" { } #[test] fn __bindgen_test_layout_a_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( a ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( a ) - )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(a)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(a)) + ); } diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 87b38f283f..49ad2654c5 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -13,44 +13,68 @@ pub struct A { pub type A_a = b; #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( A ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( A ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)) + ); } impl Clone for A { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[repr(C)] pub struct e { pub d: RefPtr, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for e { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for e { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct f { pub _address: u8, } +impl Clone for f { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] pub struct g { pub h: f, } #[test] fn bindgen_test_layout_g() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( g ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( g ) )); - assert_eq! (unsafe { & ( * ( 0 as * const g ) ) . h as * const _ as usize - } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( g ) , "::" , stringify - ! ( h ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(g)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(g)) + ); + assert_eq!( + unsafe { &(*(0 as *const g)).h as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(g), "::", stringify!(h)) + ); } impl Default for g { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] pub struct b { @@ -58,13 +82,21 @@ pub struct b { } #[test] fn bindgen_test_layout_b() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( b ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( b ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(b)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(b)) + ); } impl Default for b { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } extern "C" { #[link_name = "\u{1}_Z25Servo_Element_GetSnapshotv"] @@ -72,9 +104,14 @@ extern "C" { } #[test] fn __bindgen_test_layout_f_open0_e_open1_int_close1_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( f ) )); - assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( f ) - )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(f)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(f)) + ); } diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs index 31fe3c5396..06f45f0ac6 100644 --- a/tests/expectations/tests/issue-674-1.rs +++ b/tests/expectations/tests/issue-674-1.rs @@ -12,11 +12,16 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct Maybe { pub _address: u8, } pub type Maybe_ValueType = T; + impl Clone for Maybe { + fn clone(&self) -> Self { + *self + } + } } #[repr(C)] #[derive(Debug, Default, Copy)] @@ -25,19 +30,30 @@ pub mod root { } #[test] fn bindgen_test_layout_CapturingContentInfo() { - assert_eq!(::std::mem::size_of::() , 1usize , - concat ! ( - "Size of: " , stringify ! ( CapturingContentInfo ) )); - assert_eq! (::std::mem::align_of::() , 1usize , - concat ! ( - "Alignment of " , stringify ! ( CapturingContentInfo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const CapturingContentInfo ) ) . a as * - const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( - CapturingContentInfo ) , "::" , stringify ! ( a ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(CapturingContentInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(CapturingContentInfo)) + ); + assert_eq!( + unsafe { &(*(0 as *const CapturingContentInfo)).a as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(CapturingContentInfo), + "::", + stringify!(a) + ) + ); } impl Clone for CapturingContentInfo { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } } diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index cfbef26944..f7564d9f0b 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -12,11 +12,16 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct Rooted { pub _address: u8, } pub type Rooted_ElementType = T; + impl Clone for Rooted { + fn clone(&self) -> Self { + *self + } + } } #[repr(C)] #[derive(Debug, Default, Copy)] @@ -25,18 +30,26 @@ pub mod root { } #[test] fn bindgen_test_layout_c() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( c ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( c ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const c ) ) . b as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( c ) , "::" , - stringify ! ( b ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(c)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(c)) + ); + assert_eq!( + unsafe { &(*(0 as *const c)).b as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(c), "::", stringify!(b)) + ); } impl Clone for c { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[repr(C)] #[derive(Debug, Default, Copy)] @@ -45,33 +58,54 @@ pub mod root { } #[test] fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( B ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( B ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const B ) ) . a as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( B ) , "::" , - stringify ! ( a ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(B)) + ); + assert_eq!( + unsafe { &(*(0 as *const B)).a as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(B), "::", stringify!(a)) + ); } impl Clone for B { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct StaticRefPtr { pub _address: u8, } + impl Clone for StaticRefPtr { + fn clone(&self) -> Self { + *self + } + } #[test] fn __bindgen_test_layout_StaticRefPtr_open0_B_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 1usize , - concat ! ( - "Size of template specialization: " , stringify ! ( - root::StaticRefPtr ) )); - assert_eq!(::std::mem::align_of::() , 1usize , - concat ! ( - "Alignment of template specialization: " , stringify ! ( - root::StaticRefPtr ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!( + "Size of template specialization: ", + stringify!(root::StaticRefPtr) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::StaticRefPtr) + ) + ); } } diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs index 71f794c387..0244f9f4e0 100644 --- a/tests/expectations/tests/issue-674-3.rs +++ b/tests/expectations/tests/issue-674-3.rs @@ -9,11 +9,16 @@ pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct nsRefPtrHashtable { pub _address: u8, } pub type nsRefPtrHashtable_UserDataType = *mut PtrType; + impl Clone for nsRefPtrHashtable { + fn clone(&self) -> Self { + *self + } + } #[repr(C)] #[derive(Debug, Default, Copy)] pub struct a { @@ -21,18 +26,26 @@ pub mod root { } #[test] fn bindgen_test_layout_a() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( a ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( a ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const a ) ) . b as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( a ) , "::" , - stringify ! ( b ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(a)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(0 as *const a)).b as *const _ as usize }, + 0usize, + concat!("Alignment of field: ", stringify!(a), "::", stringify!(b)) + ); } impl Clone for a { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[repr(C)] #[derive(Debug, Default, Copy)] @@ -41,17 +54,30 @@ pub mod root { } #[test] fn bindgen_test_layout_nsCSSValue() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( nsCSSValue ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( - "Alignment of " , stringify ! ( nsCSSValue ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const nsCSSValue ) ) . c as * const _ as - usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( nsCSSValue ) , "::" - , stringify ! ( c ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(nsCSSValue)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(nsCSSValue)) + ); + assert_eq!( + unsafe { &(*(0 as *const nsCSSValue)).c as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(nsCSSValue), + "::", + stringify!(c) + ) + ); } impl Clone for nsCSSValue { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } } diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs index 09f5ee20ee..502c6f5900 100644 --- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -13,22 +13,37 @@ pub struct VirtualMethods { } #[test] fn bindgen_test_layout_VirtualMethods() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( VirtualMethods ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( VirtualMethods ) )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(VirtualMethods)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(VirtualMethods)) + ); } impl Clone for VirtualMethods { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } impl Default for VirtualMethods { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Set { pub bar: ::std::os::raw::c_int, } +impl Clone for Set { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Copy)] pub struct ServoElementSnapshotTable { @@ -36,25 +51,37 @@ pub struct ServoElementSnapshotTable { } #[test] fn bindgen_test_layout_ServoElementSnapshotTable() { - assert_eq!(::std::mem::size_of::() , 4usize , - concat ! ( - "Size of: " , stringify ! ( ServoElementSnapshotTable ) )); - assert_eq! (::std::mem::align_of::() , 4usize , - concat ! ( - "Alignment of " , stringify ! ( ServoElementSnapshotTable ) - )); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(ServoElementSnapshotTable)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ServoElementSnapshotTable)) + ); } impl Clone for ServoElementSnapshotTable { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } impl Default for ServoElementSnapshotTable { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_Set_open0_VirtualMethods_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( - "Size of template specialization: " , stringify ! ( Set ) )); - assert_eq!(::std::mem::align_of::() , 4usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( Set ) - )); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of template specialization: ", stringify!(Set)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of template specialization: ", stringify!(Set)) + ); } diff --git a/tests/expectations/tests/issue-833-2.rs b/tests/expectations/tests/issue-833-2.rs index c77f59236e..d0c4cdaf6f 100644 --- a/tests/expectations/tests/issue-833-2.rs +++ b/tests/expectations/tests/issue-833-2.rs @@ -6,7 +6,12 @@ // If the output of this changes, please ensure issue-833-1.hpp changes too #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct nsTArray { pub _address: u8, } +impl Clone for nsTArray { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/libclang-3.8/auto.rs b/tests/expectations/tests/libclang-3.8/auto.rs index b86a5c9e07..ad18184589 100644 --- a/tests/expectations/tests/libclang-3.8/auto.rs +++ b/tests/expectations/tests/libclang-3.8/auto.rs @@ -32,10 +32,15 @@ impl Clone for Foo { } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Bar { pub _address: u8, } +impl Clone for Bar { + fn clone(&self) -> Self { + *self + } +} extern "C" { #[link_name = "\u{1}_Z5Test2v"] pub fn Test2() -> ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs index 960b5522f9..16adbb66fd 100644 --- a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs @@ -5,15 +5,25 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Base { pub _address: u8, } +impl Clone for Base { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Derived { pub b: bool, } +impl Clone for Derived { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Usage { diff --git a/tests/expectations/tests/maddness-is-avoidable.rs b/tests/expectations/tests/maddness-is-avoidable.rs index b1eea1d093..3e7c91c8d4 100644 --- a/tests/expectations/tests/maddness-is-avoidable.rs +++ b/tests/expectations/tests/maddness-is-avoidable.rs @@ -5,12 +5,22 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct RefPtr { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct RefPtr_Proxy { pub _address: u8, } +impl Clone for RefPtr_Proxy { + fn clone(&self) -> Self { + *self + } +} +impl Clone for RefPtr { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/nsBaseHashtable.rs b/tests/expectations/tests/nsBaseHashtable.rs index 338978e1c8..770f2e354b 100644 --- a/tests/expectations/tests/nsBaseHashtable.rs +++ b/tests/expectations/tests/nsBaseHashtable.rs @@ -5,33 +5,56 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct nsBaseHashtableET { pub _address: u8, } +impl Clone for nsBaseHashtableET { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct nsTHashtable { pub _address: u8, } +impl Clone for nsTHashtable { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct nsBaseHashtable { pub _address: u8, } pub type nsBaseHashtable_KeyType = [u8; 0usize]; pub type nsBaseHashtable_EntryType = nsBaseHashtableET; #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct nsBaseHashtable_LookupResult { pub mEntry: *mut nsBaseHashtable_EntryType, pub mTable: *mut nsBaseHashtable, } +impl Clone for nsBaseHashtable_LookupResult { + fn clone(&self) -> Self { + *self + } +} impl Default for nsBaseHashtable_LookupResult { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +impl nsBaseHashtable_LookupResult { + #[inline] + pub unsafe fn new(arg1: *mut nsBaseHashtable_EntryType, arg2: *mut nsBaseHashtable) -> Self { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + nsBaseHashtable_LookupResult_LookupResult(&mut __bindgen_tmp, arg1, arg2); + __bindgen_tmp + } +} #[repr(C)] #[derive(Debug)] pub struct nsBaseHashtable_EntryPtr { @@ -43,6 +66,27 @@ impl Default for nsBaseHashtable_EntryPtr { unsafe { ::std::mem::zeroed() } } } +impl nsBaseHashtable_EntryPtr { + #[inline] + pub unsafe fn new( + arg1: *mut nsBaseHashtable, + arg2: *mut nsBaseHashtable_EntryType, + arg3: bool, + ) -> Self { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + nsBaseHashtable_EntryPtr_EntryPtr(&mut __bindgen_tmp, arg1, arg2, arg3); + __bindgen_tmp + } + #[inline] + pub unsafe fn destruct(&mut self) { + nsBaseHashtable_EntryPtr_EntryPtr_destructor(self) + } +} +impl Clone for nsBaseHashtable { + fn clone(&self) -> Self { + *self + } +} impl Default for nsBaseHashtable { fn default() -> Self { unsafe { ::std::mem::zeroed() } diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index 20b44d7e76..d0dd3467b4 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -8,8 +8,13 @@ /// This is like `opaque-template-inst-member.hpp` except exercising the cases /// where we are OK to derive Debug/Hash/PartialEq. #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct OpaqueTemplate {} +impl Clone for OpaqueTemplate { + fn clone(&self) -> Self { + *self + } +} /// Should derive Debug/Hash/PartialEq. #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index f686150c9f..5407cdf9c6 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -5,8 +5,13 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct OpaqueTemplate {} +impl Clone for OpaqueTemplate { + fn clone(&self) -> Self { + *self + } +} /// This should not end up deriving Debug/Hash because its `mBlah` field cannot derive /// Debug/Hash because the instantiation's definition cannot derive Debug/Hash. #[repr(C)] diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 6eb7b67235..1ba368226e 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -31,8 +31,13 @@ impl Clone for OtherOpaque { } ///
#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Opaque {} +impl Clone for Opaque { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq)] pub struct WithOpaquePtr { diff --git a/tests/expectations/tests/opaque_typedef.rs b/tests/expectations/tests/opaque_typedef.rs index 96df276ccd..6b2fe5a9b8 100644 --- a/tests/expectations/tests/opaque_typedef.rs +++ b/tests/expectations/tests/opaque_typedef.rs @@ -5,10 +5,15 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct RandomTemplate { pub _address: u8, } +impl Clone for RandomTemplate { + fn clone(&self) -> Self { + *self + } +} ///
pub type ShouldBeOpaque = u8; pub type ShouldNotBeOpaque = RandomTemplate; diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index 49185e32be..337d11a9c2 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -7,10 +7,15 @@ ///
#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct nsTArray { pub y: ::std::os::raw::c_uint, } +impl Clone for nsTArray { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Test { diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs index 7d105c2a85..8c648454b0 100644 --- a/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -12,15 +12,25 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct Wrapper { pub _address: u8, } + impl Clone for Wrapper { + fn clone(&self) -> Self { + *self + } + } #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct Wrapper_sentry { pub i_am_wrapper_sentry: ::std::os::raw::c_int, } + impl Clone for Wrapper_sentry { + fn clone(&self) -> Self { + *self + } + } #[repr(C)] #[derive(Debug, Default, Copy)] pub struct sentry { @@ -96,8 +106,8 @@ pub mod root { ); assert_eq!( unsafe { - &(*(0 as *const NotTemplateWrapper_sentry)).i_am_not_template_wrapper_sentry as - *const _ as usize + &(*(0 as *const NotTemplateWrapper_sentry)).i_am_not_template_wrapper_sentry + as *const _ as usize }, 0usize, concat!( @@ -138,8 +148,8 @@ pub mod root { assert_eq!( unsafe { &(*(0 as *const InlineNotTemplateWrapper_sentry)) - .i_am_inline_not_template_wrapper_sentry as *const _ as - usize + .i_am_inline_not_template_wrapper_sentry as *const _ + as usize }, 0usize, concat!( @@ -174,15 +184,25 @@ pub mod root { } } #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct InlineTemplateWrapper { pub _address: u8, } #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct InlineTemplateWrapper_sentry { pub i_am_inline_template_wrapper_sentry: ::std::os::raw::c_int, } + impl Clone for InlineTemplateWrapper_sentry { + fn clone(&self) -> Self { + *self + } + } + impl Clone for InlineTemplateWrapper { + fn clone(&self) -> Self { + *self + } + } #[repr(C)] #[derive(Debug, Default, Copy)] pub struct OuterDoubleWrapper { @@ -373,15 +393,25 @@ pub mod root { } } #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct OutsideNamespaceWrapper { pub _address: u8, } + impl Clone for OutsideNamespaceWrapper { + fn clone(&self) -> Self { + *self + } + } #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] + #[derive(Debug, Default, Copy)] pub struct OutsideNamespaceWrapper_sentry { pub i_am_outside_namespace_wrapper_sentry: ::std::os::raw::c_int, } + impl Clone for OutsideNamespaceWrapper_sentry { + fn clone(&self) -> Self { + *self + } + } #[repr(C)] #[derive(Debug, Default, Copy)] pub struct sentry { diff --git a/tests/expectations/tests/struct_with_typedef_template_arg.rs b/tests/expectations/tests/struct_with_typedef_template_arg.rs index ad4f394a04..bb6f04e1bd 100644 --- a/tests/expectations/tests/struct_with_typedef_template_arg.rs +++ b/tests/expectations/tests/struct_with_typedef_template_arg.rs @@ -5,9 +5,13 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Proxy { pub _address: u8, } -pub type Proxy_foo = - ::std::option::Option; +pub type Proxy_foo = ::std::option::Option; +impl Clone for Proxy { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/template-fun-ty.rs b/tests/expectations/tests/template-fun-ty.rs index 8403f794a6..fa8aa70e8b 100644 --- a/tests/expectations/tests/template-fun-ty.rs +++ b/tests/expectations/tests/template-fun-ty.rs @@ -5,22 +5,37 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Foo { pub _address: u8, } -pub type Foo_FunctionPtr = - ::std::option::Option T>; +pub type Foo_FunctionPtr = ::std::option::Option T>; +impl Clone for Foo { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct RefPtr { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct RefPtr_Proxy { pub _address: u8, } -pub type RefPtr_Proxy_member_function = - ::std::option::Option R>; +pub type RefPtr_Proxy_member_function = ::std::option::Option< + unsafe extern "C" fn(arg1: Args) -> R, +>; +impl Clone for RefPtr_Proxy { + fn clone(&self) -> Self { + *self + } +} +impl Clone for RefPtr { + fn clone(&self) -> Self { + *self + } +} pub type Returner = ::std::option::Option T>; diff --git a/tests/expectations/tests/template-param-usage-1.rs b/tests/expectations/tests/template-param-usage-1.rs index 95e41077b5..f4f7d6f875 100644 --- a/tests/expectations/tests/template-param-usage-1.rs +++ b/tests/expectations/tests/template-param-usage-1.rs @@ -5,7 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct DoesNotUseTemplateParameter { pub x: ::std::os::raw::c_int, } +impl Clone for DoesNotUseTemplateParameter { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/template-param-usage-11.rs b/tests/expectations/tests/template-param-usage-11.rs index 1b2335bb1e..2fca14a31c 100644 --- a/tests/expectations/tests/template-param-usage-11.rs +++ b/tests/expectations/tests/template-param-usage-11.rs @@ -5,7 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct DoesNotUseT { pub _address: u8, } +impl Clone for DoesNotUseT { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/template-param-usage-13.rs b/tests/expectations/tests/template-param-usage-13.rs index 4721968f27..249af0fe85 100644 --- a/tests/expectations/tests/template-param-usage-13.rs +++ b/tests/expectations/tests/template-param-usage-13.rs @@ -5,10 +5,15 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct BaseIgnoresT { pub x: ::std::os::raw::c_int, } +impl Clone for BaseIgnoresT { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct CrtpUsesU { @@ -16,6 +21,8 @@ pub struct CrtpUsesU { pub usage: U, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for CrtpUsesU { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for CrtpUsesU { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/template-param-usage-14.rs b/tests/expectations/tests/template-param-usage-14.rs index d4c8665286..005823d30f 100644 --- a/tests/expectations/tests/template-param-usage-14.rs +++ b/tests/expectations/tests/template-param-usage-14.rs @@ -5,16 +5,28 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct BaseIgnoresT { pub x: ::std::os::raw::c_int, } +impl Clone for BaseIgnoresT { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct CrtpIgnoresU { pub _base: BaseIgnoresT, pub y: ::std::os::raw::c_int, } +impl Clone for CrtpIgnoresU { + fn clone(&self) -> Self { + *self + } +} impl Default for CrtpIgnoresU { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/template-param-usage-15.rs b/tests/expectations/tests/template-param-usage-15.rs index 9b7f30ec9c..41400c2203 100644 --- a/tests/expectations/tests/template-param-usage-15.rs +++ b/tests/expectations/tests/template-param-usage-15.rs @@ -10,15 +10,24 @@ pub struct BaseUsesT { pub usage: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for BaseUsesT { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for BaseUsesT { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy)] pub struct CrtpIgnoresU { pub _base: BaseUsesT, pub y: ::std::os::raw::c_int, } +impl Clone for CrtpIgnoresU { + fn clone(&self) -> Self { + *self + } +} impl Default for CrtpIgnoresU { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/template-param-usage-4.rs b/tests/expectations/tests/template-param-usage-4.rs index 5e9e004c42..218f603e14 100644 --- a/tests/expectations/tests/template-param-usage-4.rs +++ b/tests/expectations/tests/template-param-usage-4.rs @@ -11,10 +11,17 @@ pub struct UsesTemplateParameter { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct UsesTemplateParameter_DoesNotUseTemplateParameters { pub x: ::std::os::raw::c_int, } -impl Default for UsesTemplateParameter { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Clone for UsesTemplateParameter_DoesNotUseTemplateParameters { + fn clone(&self) -> Self { + *self + } +} +impl Default for UsesTemplateParameter { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/template-param-usage-6.rs b/tests/expectations/tests/template-param-usage-6.rs index f76e6326e6..24a5e82b1b 100644 --- a/tests/expectations/tests/template-param-usage-6.rs +++ b/tests/expectations/tests/template-param-usage-6.rs @@ -5,8 +5,13 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct DoesNotUseTemplateParameter { pub x: ::std::os::raw::c_int, } pub type DoesNotUseTemplateParameter_ButAliasDoesUseIt = T; +impl Clone for DoesNotUseTemplateParameter { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/template-param-usage-9.rs b/tests/expectations/tests/template-param-usage-9.rs index 88fea7254d..853ff3334f 100644 --- a/tests/expectations/tests/template-param-usage-9.rs +++ b/tests/expectations/tests/template-param-usage-9.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct DoesNotUse { pub _address: u8, } @@ -19,6 +19,13 @@ pub struct DoesNotUse_IndirectUsage { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for DoesNotUse_IndirectUsage { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for DoesNotUse_IndirectUsage { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl Clone for DoesNotUse { + fn clone(&self) -> Self { + *self + } } diff --git a/tests/expectations/tests/template-with-var.rs b/tests/expectations/tests/template-with-var.rs index 0b0a8cb6b2..22823a3396 100644 --- a/tests/expectations/tests/template-with-var.rs +++ b/tests/expectations/tests/template-with-var.rs @@ -5,7 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct TemplateWithVar { pub _address: u8, } +impl Clone for TemplateWithVar { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 3f397b6ff3..e3077073f0 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -345,8 +345,13 @@ impl Default for PODButContainsDtor { } ///
#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Opaque {} +impl Clone for Opaque { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct POD { @@ -411,7 +416,7 @@ pub struct NestedContainer { pub inc: Incomplete, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for NestedContainer { +impl Default for NestedContainer { fn default() -> Self { unsafe { ::std::mem::zeroed() } } @@ -422,7 +427,7 @@ pub struct Incomplete { pub d: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for Incomplete { +impl Default for Incomplete { fn default() -> Self { unsafe { ::std::mem::zeroed() } } @@ -451,10 +456,15 @@ impl Clone for Untemplated { } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Templated { pub m_untemplated: Untemplated, } +impl Clone for Templated { + fn clone(&self) -> Self { + *self + } +} /// 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. /// @@ -514,103 +524,367 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() { 24usize, concat!( "Size of template specialization: ", - stringify ! ( Foo < :: std :: os :: raw :: c_int > ) + stringify!(Foo<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Foo<::std::os::raw::c_int>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < Foo < :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Foo < :: std :: os :: raw :: c_int > ) ) ); } #[test] fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < :: std :: os :: raw :: c_uint > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_uint > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < :: std :: os :: raw :: c_uint > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_uint > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B<::std::os::raw::c_uint>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<::std::os::raw::c_uint>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*const ::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*const ::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ptr_const_mozilla__Foo_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * const mozilla_Foo > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * const mozilla_Foo > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * const mozilla_Foo > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * const mozilla_Foo > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*const mozilla_Foo>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*const mozilla_Foo>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_array1_ptr_const_mozilla__Foo_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < [ * const mozilla_Foo ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < [ * const mozilla_Foo ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < [ * const mozilla_Foo ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < [ * const mozilla_Foo ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<[*const mozilla_Foo; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<[*const mozilla_Foo; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_const_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_volatile_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_const_bool_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < bool > > ( ) , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( B < bool > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < bool > > ( ) , 1usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < bool > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 1usize, + concat!("Size of template specialization: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::>(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(B) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < u16 > > ( ) , 2usize , concat ! ( "Size of template specialization: " , stringify ! ( B < u16 > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < u16 > > ( ) , 2usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < u16 > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 2usize, + concat!("Size of template specialization: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::>(), + 2usize, + concat!("Alignment of template specialization: ", stringify!(B)) + ); } #[test] fn __bindgen_test_layout_B_open0_array1_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B<[::std::os::raw::c_int; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<[::std::os::raw::c_int; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_array1_ptr_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ptr_array1_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ref_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*mut ::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*mut ::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ref_const_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*const ::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*const ::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ref_ptr_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * mut * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut * mut :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * mut * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut * mut :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*mut *mut ::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*mut *mut ::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_B_open0_ref_array1_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) + ) + ); } #[test] fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { - assert_eq ! ( :: std :: mem :: size_of :: < Foo < :: std :: os :: raw :: c_int > > ( ) , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( Foo < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < Foo < :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Foo < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Foo<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Foo<::std::os::raw::c_int>) + ) + ); } #[test] fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Rooted<*mut ::std::os::raw::c_void>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Rooted<*mut ::std::os::raw::c_void>) + ) + ); } #[test] fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() { - assert_eq ! ( :: std :: mem :: size_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Rooted<*mut ::std::os::raw::c_void>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Rooted<*mut ::std::os::raw::c_void>) + ) + ); } #[test] fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < WithDtor < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( WithDtor < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < WithDtor < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( WithDtor < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(WithDtor<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(WithDtor<::std::os::raw::c_int>) + ) + ); } diff --git a/tests/expectations/tests/template_typedef_transitive_param.rs b/tests/expectations/tests/template_typedef_transitive_param.rs index 7768d522e6..6c9a0ea84e 100644 --- a/tests/expectations/tests/template_typedef_transitive_param.rs +++ b/tests/expectations/tests/template_typedef_transitive_param.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Wrapper { pub _address: u8, } @@ -15,7 +15,14 @@ pub struct Wrapper_Wrapped { pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for Wrapper_Wrapped { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } +impl Default for Wrapper_Wrapped { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } pub type Wrapper_Type = Wrapper_Wrapped; +impl Clone for Wrapper { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/template_typedefs.rs b/tests/expectations/tests/template_typedefs.rs index df16f9f685..50c28a3cd3 100644 --- a/tests/expectations/tests/template_typedefs.rs +++ b/tests/expectations/tests/template_typedefs.rs @@ -6,7 +6,7 @@ pub type foo = ::std::option::Option; #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct Foo { pub _address: u8, } @@ -15,3 +15,8 @@ pub type Foo_FooPtrTypedef = *mut Foo_Char; pub type Foo_nsCOMArrayEnumFunc = ::std::option::Option< unsafe extern "C" fn(aElement: *mut T, aData: *mut ::std::os::raw::c_void) -> bool, >; +impl Clone for Foo { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/templateref_opaque.rs b/tests/expectations/tests/templateref_opaque.rs index 481a31bba6..38ce3497c2 100644 --- a/tests/expectations/tests/templateref_opaque.rs +++ b/tests/expectations/tests/templateref_opaque.rs @@ -5,14 +5,24 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct detail_PointerType { pub _address: u8, } pub type detail_PointerType_Type = *mut T; +impl Clone for detail_PointerType { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct UniquePtr { pub _address: u8, } pub type UniquePtr_Pointer = detail_PointerType; +impl Clone for UniquePtr { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 2bbdcbb148..f33401996c 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -11,20 +11,31 @@ pub struct mozilla_FragmentOrURL { } #[test] fn bindgen_test_layout_mozilla_FragmentOrURL() { - assert_eq!(::std::mem::size_of::() , 1usize , - concat ! ( "Size of: " , stringify ! ( mozilla_FragmentOrURL ) - )); - assert_eq! (::std::mem::align_of::() , 1usize , - concat ! ( - "Alignment of " , stringify ! ( mozilla_FragmentOrURL ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const mozilla_FragmentOrURL ) ) . mIsLocalRef - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( mozilla_FragmentOrURL ) - , "::" , stringify ! ( mIsLocalRef ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_FragmentOrURL)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) + ); + assert_eq!( + unsafe { &(*(0 as *const mozilla_FragmentOrURL)).mIsLocalRef as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(mozilla_FragmentOrURL), + "::", + stringify!(mIsLocalRef) + ) + ); } impl Clone for mozilla_FragmentOrURL { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] @@ -33,29 +44,72 @@ pub struct mozilla_Position { } #[test] fn bindgen_test_layout_mozilla_Position() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( mozilla_Position ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! - ( "Alignment of " , stringify ! ( mozilla_Position ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_Position)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_Position)) + ); } impl Clone for mozilla_Position { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[repr(C)] +#[derive(Copy)] pub struct mozilla_StyleShapeSource { pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1, } #[repr(C)] +#[derive(Copy)] pub union mozilla_StyleShapeSource__bindgen_ty_1 { pub mPosition: *mut mozilla_Position, pub mFragmentOrURL: *mut mozilla_FragmentOrURL, _bindgen_union_align: u64, } +#[test] +fn bindgen_test_layout_mozilla_StyleShapeSource__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!( + "Size of: ", + stringify!(mozilla_StyleShapeSource__bindgen_ty_1) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of ", + stringify!(mozilla_StyleShapeSource__bindgen_ty_1) + ) + ); +} +impl Clone for mozilla_StyleShapeSource__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } +} impl Default for mozilla_StyleShapeSource__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl Clone for mozilla_StyleShapeSource { + fn clone(&self) -> Self { + *self + } } impl Default for mozilla_StyleShapeSource { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] @@ -64,49 +118,91 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . mFoo as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( mFoo ) )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).mFoo as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(mFoo) + ) + ); } impl Clone for Bar { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } impl Default for Bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] +#[derive(Copy)] pub struct nsFoo { pub mBar: mozilla_StyleShapeSource, } #[test] fn bindgen_test_layout_nsFoo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( nsFoo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( nsFoo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const nsFoo ) ) . mBar as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( nsFoo ) , "::" , - stringify ! ( mBar ) )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsFoo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsFoo)) + ); + assert_eq!( + unsafe { &(*(0 as *const nsFoo)).mBar as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(nsFoo), + "::", + stringify!(mBar) + ) + ); +} +impl Clone for nsFoo { + fn clone(&self) -> Self { + *self + } } impl Default for nsFoo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[test] fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 8usize , - concat ! ( - "Size of template specialization: " , stringify ! ( - mozilla_StyleShapeSource ) )); - assert_eq!(::std::mem::align_of::() , 8usize , - concat ! ( - "Alignment of template specialization: " , stringify ! ( - mozilla_StyleShapeSource ) )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(mozilla_StyleShapeSource) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(mozilla_StyleShapeSource) + ) + ); } diff --git a/tests/expectations/tests/typeref_1_0.rs b/tests/expectations/tests/typeref_1_0.rs index a99df0ad9b..19a9216995 100644 --- a/tests/expectations/tests/typeref_1_0.rs +++ b/tests/expectations/tests/typeref_1_0.rs @@ -6,35 +6,47 @@ #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { +impl __BindgenUnionField { #[inline] - pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } + pub fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } #[inline] - pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) } + pub unsafe fn as_ref(&self) -> &T { + ::std::mem::transmute(self) + } #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) } + pub unsafe fn as_mut(&mut self) -> &mut T { + ::std::mem::transmute(self) + } } -impl ::std::default::Default for __BindgenUnionField { +impl ::std::default::Default for __BindgenUnionField { #[inline] - fn default() -> Self { Self::new() } + fn default() -> Self { + Self::new() + } } -impl ::std::clone::Clone for __BindgenUnionField { +impl ::std::clone::Clone for __BindgenUnionField { #[inline] - fn clone(&self) -> Self { Self::new() } + fn clone(&self) -> Self { + Self::new() + } } -impl ::std::marker::Copy for __BindgenUnionField { } -impl ::std::fmt::Debug for __BindgenUnionField { +impl ::std::marker::Copy for __BindgenUnionField {} +impl ::std::fmt::Debug for __BindgenUnionField { fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fmt.write_str("__BindgenUnionField") } } -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) { } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) {} } -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { true } +impl ::std::cmp::PartialEq for __BindgenUnionField { + fn eq(&self, _other: &__BindgenUnionField) -> bool { + true + } } -impl ::std::cmp::Eq for __BindgenUnionField { } +impl ::std::cmp::Eq for __BindgenUnionField {} #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct mozilla_FragmentOrURL { @@ -42,20 +54,31 @@ pub struct mozilla_FragmentOrURL { } #[test] fn bindgen_test_layout_mozilla_FragmentOrURL() { - assert_eq!(::std::mem::size_of::() , 1usize , - concat ! ( "Size of: " , stringify ! ( mozilla_FragmentOrURL ) - )); - assert_eq! (::std::mem::align_of::() , 1usize , - concat ! ( - "Alignment of " , stringify ! ( mozilla_FragmentOrURL ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const mozilla_FragmentOrURL ) ) . mIsLocalRef - as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( mozilla_FragmentOrURL ) - , "::" , stringify ! ( mIsLocalRef ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_FragmentOrURL)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) + ); + assert_eq!( + unsafe { &(*(0 as *const mozilla_FragmentOrURL)).mIsLocalRef as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(mozilla_FragmentOrURL), + "::", + stringify!(mIsLocalRef) + ) + ); } impl Clone for mozilla_FragmentOrURL { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] @@ -64,26 +87,63 @@ pub struct mozilla_Position { } #[test] fn bindgen_test_layout_mozilla_Position() { - assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( - "Size of: " , stringify ! ( mozilla_Position ) )); - assert_eq! (::std::mem::align_of::() , 1usize , concat ! - ( "Alignment of " , stringify ! ( mozilla_Position ) )); + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_Position)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_Position)) + ); } impl Clone for mozilla_Position { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct mozilla_StyleShapeSource { pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct mozilla_StyleShapeSource__bindgen_ty_1 { pub mPosition: __BindgenUnionField<*mut mozilla_Position>, pub mFragmentOrURL: __BindgenUnionField<*mut mozilla_FragmentOrURL>, pub bindgen_union_field: u64, } +#[test] +fn bindgen_test_layout_mozilla_StyleShapeSource__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!( + "Size of: ", + stringify!(mozilla_StyleShapeSource__bindgen_ty_1) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of ", + stringify!(mozilla_StyleShapeSource__bindgen_ty_1) + ) + ); +} +impl Clone for mozilla_StyleShapeSource__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } +} +impl Clone for mozilla_StyleShapeSource { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct Bar { @@ -91,21 +151,36 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( Bar ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( Bar ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const Bar ) ) . mFoo as * const _ as usize } , - 0usize , concat ! ( - "Alignment of field: " , stringify ! ( Bar ) , "::" , - stringify ! ( mFoo ) )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(0 as *const Bar)).mFoo as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(Bar), + "::", + stringify!(mFoo) + ) + ); } impl Clone for Bar { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } impl Default for Bar { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] @@ -114,27 +189,48 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { - assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( - "Size of: " , stringify ! ( nsFoo ) )); - assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( - "Alignment of " , stringify ! ( nsFoo ) )); - assert_eq! (unsafe { - & ( * ( 0 as * const nsFoo ) ) . mBar as * const _ as usize } - , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( nsFoo ) , "::" , - stringify ! ( mBar ) )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsFoo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsFoo)) + ); + assert_eq!( + unsafe { &(*(0 as *const nsFoo)).mBar as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(nsFoo), + "::", + stringify!(mBar) + ) + ); } impl Clone for nsFoo { - fn clone(&self) -> Self { *self } + fn clone(&self) -> Self { + *self + } } #[test] fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { - assert_eq!(::std::mem::size_of::() , 8usize , - concat ! ( - "Size of template specialization: " , stringify ! ( - mozilla_StyleShapeSource ) )); - assert_eq!(::std::mem::align_of::() , 8usize , - concat ! ( - "Alignment of template specialization: " , stringify ! ( - mozilla_StyleShapeSource ) )); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(mozilla_StyleShapeSource) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(mozilla_StyleShapeSource) + ) + ); } diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index f6418fd6b2..a4e85b1b5f 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -5,31 +5,81 @@ #[repr(C)] +#[derive(Copy)] pub struct NastyStruct { pub mIsSome: bool, pub mStorage: NastyStruct__bindgen_ty_1, pub __bindgen_anon_1: NastyStruct__bindgen_ty_2, } #[repr(C)] +#[derive(Copy)] pub union NastyStruct__bindgen_ty_1 { pub mFoo: *mut ::std::os::raw::c_void, pub mDummy: ::std::os::raw::c_ulong, _bindgen_union_align: u64, } +#[test] +fn bindgen_test_layout_NastyStruct__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(NastyStruct__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(NastyStruct__bindgen_ty_1)) + ); +} +impl Clone for NastyStruct__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } +} impl Default for NastyStruct__bindgen_ty_1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] +#[derive(Copy)] pub union NastyStruct__bindgen_ty_2 { pub wat: ::std::os::raw::c_short, pub wut: *mut ::std::os::raw::c_int, _bindgen_union_align: u64, } +#[test] +fn bindgen_test_layout_NastyStruct__bindgen_ty_2() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(NastyStruct__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(NastyStruct__bindgen_ty_2)) + ); +} +impl Clone for NastyStruct__bindgen_ty_2 { + fn clone(&self) -> Self { + *self + } +} impl Default for NastyStruct__bindgen_ty_2 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl Clone for NastyStruct { + fn clone(&self) -> Self { + *self + } } impl Default for NastyStruct { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] pub union Whatever { @@ -37,6 +87,21 @@ pub union Whatever { pub mInt: ::std::os::raw::c_int, _bindgen_union_align: u64, } +#[test] +fn bindgen_test_layout_Whatever() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Whatever)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Whatever)) + ); +} impl Default for Whatever { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } diff --git a/tests/expectations/tests/union_template_1_0.rs b/tests/expectations/tests/union_template_1_0.rs index afe14c7018..f8b15b5613 100644 --- a/tests/expectations/tests/union_template_1_0.rs +++ b/tests/expectations/tests/union_template_1_0.rs @@ -6,60 +6,131 @@ #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { +impl __BindgenUnionField { #[inline] - pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } + pub fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } #[inline] - pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) } + pub unsafe fn as_ref(&self) -> &T { + ::std::mem::transmute(self) + } #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) } + pub unsafe fn as_mut(&mut self) -> &mut T { + ::std::mem::transmute(self) + } } -impl ::std::default::Default for __BindgenUnionField { +impl ::std::default::Default for __BindgenUnionField { #[inline] - fn default() -> Self { Self::new() } + fn default() -> Self { + Self::new() + } } -impl ::std::clone::Clone for __BindgenUnionField { +impl ::std::clone::Clone for __BindgenUnionField { #[inline] - fn clone(&self) -> Self { Self::new() } + fn clone(&self) -> Self { + Self::new() + } } -impl ::std::marker::Copy for __BindgenUnionField { } -impl ::std::fmt::Debug for __BindgenUnionField { +impl ::std::marker::Copy for __BindgenUnionField {} +impl ::std::fmt::Debug for __BindgenUnionField { fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fmt.write_str("__BindgenUnionField") } } -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) { } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) {} } -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { true } +impl ::std::cmp::PartialEq for __BindgenUnionField { + fn eq(&self, _other: &__BindgenUnionField) -> bool { + true + } } -impl ::std::cmp::Eq for __BindgenUnionField { } +impl ::std::cmp::Eq for __BindgenUnionField {} #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct NastyStruct { pub mIsSome: bool, pub mStorage: NastyStruct__bindgen_ty_1, pub __bindgen_anon_1: NastyStruct__bindgen_ty_2, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct NastyStruct__bindgen_ty_1 { pub mFoo: __BindgenUnionField<*mut ::std::os::raw::c_void>, pub mDummy: __BindgenUnionField<::std::os::raw::c_ulong>, pub bindgen_union_field: u64, } +#[test] +fn bindgen_test_layout_NastyStruct__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(NastyStruct__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(NastyStruct__bindgen_ty_1)) + ); +} +impl Clone for NastyStruct__bindgen_ty_1 { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] 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, } +#[test] +fn bindgen_test_layout_NastyStruct__bindgen_ty_2() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(NastyStruct__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(NastyStruct__bindgen_ty_2)) + ); +} +impl Clone for NastyStruct__bindgen_ty_2 { + fn clone(&self) -> Self { + *self + } +} +impl Clone for NastyStruct { + fn clone(&self) -> Self { + *self + } +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct Whatever { pub mTPtr: __BindgenUnionField<*mut ::std::os::raw::c_void>, pub mInt: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u64, } +#[test] +fn bindgen_test_layout_Whatever() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Whatever)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Whatever)) + ); +} +impl Clone for Whatever { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/expectations/tests/variadic_template_function.rs b/tests/expectations/tests/variadic_template_function.rs index e14da64f33..31da85fe4e 100644 --- a/tests/expectations/tests/variadic_template_function.rs +++ b/tests/expectations/tests/variadic_template_function.rs @@ -5,7 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy)] pub struct VariadicFunctionObject { pub _address: u8, } +impl Clone for VariadicFunctionObject { + fn clone(&self) -> Self { + *self + } +}