From 923ee36d64039b83b0a9ffce7b92e1602fc79abd Mon Sep 17 00:00:00 2001 From: zzhu Date: Wed, 2 Aug 2017 11:19:14 -0700 Subject: [PATCH 01/12] Can derive Hash analysis --- src/codegen/mod.rs | 19 +- src/ir/analysis/derive_hash.rs | 337 +++++++++++++++++++++++++++++++++ src/ir/analysis/mod.rs | 2 + src/ir/context.rs | 38 +++- src/ir/derive.rs | 27 +++ src/ir/function.rs | 19 +- src/ir/item.rs | 8 +- src/ir/layout.rs | 11 +- src/lib.rs | 15 ++ src/options.rs | 7 + 10 files changed, 474 insertions(+), 9 deletions(-) create mode 100644 src/ir/analysis/derive_hash.rs diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 5c00a53d27..9521fb1ed4 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -13,7 +13,7 @@ use ir::comp::{Base, BitfieldUnit, Bitfield, CompInfo, CompKind, Field, FieldData, FieldMethods, Method, MethodKind}; use ir::comment; use ir::context::{BindgenContext, ItemId}; -use ir::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; +use ir::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, CanDeriveHash}; use ir::dot; use ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; use ir::function::{Abi, Function, FunctionSig}; @@ -1440,6 +1440,10 @@ impl CodeGenerator for CompInfo { } } + if item.can_derive_hash(ctx) { + derives.push("Hash"); + } + if !derives.is_empty() { attributes.push(attributes::derives(&derives)) } @@ -3394,12 +3398,23 @@ mod utils { ) .unwrap(); + // The actual memory of the filed will be hashed, so that's why these + // field doesn't do anything with the hash. + let union_field_hash_impl = quote_item!(&ctx.ext_cx(), + impl ::$prefix::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { + } + } + ) + .unwrap(); + let items = vec![union_field_decl, union_field_impl, union_field_default_impl, union_field_clone_impl, union_field_copy_impl, - union_field_debug_impl]; + union_field_debug_impl, + union_field_hash_impl]; let old_items = mem::replace(result, items); result.extend(old_items.into_iter()); diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs new file mode 100644 index 0000000000..2456143cd3 --- /dev/null +++ b/src/ir/analysis/derive_hash.rs @@ -0,0 +1,337 @@ +//! Determining which types for which we can emit `#[derive(Hash)]`. + +use super::{ConstrainResult, MonotoneFramework, generate_dependencies}; +use std::collections::HashSet; +use std::collections::HashMap; +use ir::context::{BindgenContext, ItemId}; +use ir::item::IsOpaque; +use ir::traversal::EdgeKind; +use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT; +use ir::ty::TypeKind; +use ir::comp::Field; +use ir::comp::FieldMethods; +use ir::derive::CanTriviallyDeriveHash; +use ir::comp::CompKind; + +/// An analysis that finds for each IR item whether hash cannot be derived. +/// +/// We use the monotone constraint function `cannot_derive_hash`, defined as +/// follows: +/// +/// * If T is Opaque and layout of the type is known, get this layout as opaque +/// type and check whether it can be derived using trivial checks. +/// * If T is Array type, hash cannot be derived if the length of the array is +/// larger than the limit or the type of data the array contains cannot derive +/// hash. +/// * If T is a type alias, a templated alias or an indirection to another type, +/// hash cannot be derived if the type T refers to cannot be derived hash. +/// * If T is a compound type, hash cannot be derived if any of its base member +/// or field cannot be derived hash. +/// * If T is a pointer, T cannot be derived hash if T is a function pointer +/// and the function signature cannot be derived hash. +/// * If T is an instantiation of an abstract template definition, T cannot be +/// derived hash if any of the template arguments or template definition +/// cannot derive hash. +#[derive(Debug, Clone)] +pub struct CannotDeriveHash<'ctx, 'gen> + where 'gen: 'ctx +{ + ctx: &'ctx BindgenContext<'gen>, + + // The incremental result of this analysis's computation. Everything in this + // set cannot derive hash. + cannot_derive_hash: HashSet, + + // Dependencies saying that if a key ItemId has been inserted into the + // `cannot_derive_hash` set, then each of the ids in Vec need to be + // considered again. + // + // This is a subset of the natural IR graph with reversed edges, where we + // only include the edges from the IR graph that can affect whether a type + // can derive hash or not. + dependencies: HashMap>, +} + +impl<'ctx, 'gen> CannotDeriveHash<'ctx, 'gen> { + fn consider_edge(kind: EdgeKind) -> bool { + match kind { + // These are the only edges that can affect whether a type can derive + // hash or not. + EdgeKind::BaseMember | + EdgeKind::Field | + EdgeKind::TypeReference | + EdgeKind::VarType | + EdgeKind::TemplateArgument | + EdgeKind::TemplateDeclaration | + EdgeKind::TemplateParameterDefinition => true, + + EdgeKind::Constructor | + EdgeKind::Destructor | + EdgeKind::FunctionReturn | + EdgeKind::FunctionParameter | + EdgeKind::InnerType | + EdgeKind::InnerVar | + EdgeKind::Method => false, + EdgeKind::Generic => false, + } + } + + fn insert(&mut self, id: ItemId) -> ConstrainResult { + trace!("inserting {:?} into the cannot_derive_hash set", id); + + let was_not_already_in_set = self.cannot_derive_hash.insert(id); + assert!( + was_not_already_in_set, + "We shouldn't try and insert {:?} twice because if it was \ + already in the set, `constrain` should have exited early.", + id + ); + + ConstrainResult::Changed + } +} + +impl<'ctx, 'gen> MonotoneFramework for CannotDeriveHash<'ctx, 'gen> { + type Node = ItemId; + type Extra = &'ctx BindgenContext<'gen>; + type Output = HashSet; + + fn new(ctx: &'ctx BindgenContext<'gen>) -> CannotDeriveHash<'ctx, 'gen> { + let cannot_derive_hash = HashSet::new(); + let dependencies = generate_dependencies(ctx, Self::consider_edge); + + CannotDeriveHash { + ctx, + cannot_derive_hash, + dependencies, + } + } + + fn initial_worklist(&self) -> Vec { + self.ctx.whitelisted_items().iter().cloned().collect() + } + + fn constrain(&mut self, id: ItemId) -> ConstrainResult { + trace!("constrain: {:?}", id); + + if self.cannot_derive_hash.contains(&id) { + trace!(" already know it cannot derive Hash"); + return ConstrainResult::Same; + } + + let item = self.ctx.resolve_item(id); + let ty = match item.as_type() { + Some(ty) => ty, + None => { + trace!(" not a type; ignoring"); + return ConstrainResult::Same; + } + }; + + if item.is_opaque(self.ctx, &()) { + let layout_can_derive = ty.layout(self.ctx).map_or(true, |l| { + l.opaque().can_trivially_derive_hash() + }); + return if layout_can_derive { + trace!(" we can trivially derive Hash for the layout"); + ConstrainResult::Same + } else { + trace!(" we cannot derive Hash for the layout"); + self.insert(id) + }; + } + + if ty.layout(self.ctx).map_or(false, |l| l.align > RUST_DERIVE_IN_ARRAY_LIMIT) { + // We have to be conservative: the struct *could* have enough + // padding that we emit an array that is longer than + // `RUST_DERIVE_IN_ARRAY_LIMIT`. If we moved padding calculations + // into the IR and computed them before this analysis, then we could + // be precise rather than conservative here. + return self.insert(id); + } + + match *ty.kind() { + // Handle the simple cases. These can derive hash without further + // information. + TypeKind::Void | + TypeKind::NullPtr | + TypeKind::Int(..) | + TypeKind::Enum(..) | + TypeKind::Named | + TypeKind::UnresolvedTypeRef(..) | + TypeKind::BlockPointer | + TypeKind::Reference(..) | + TypeKind::ObjCInterface(..) | + TypeKind::ObjCId | + TypeKind::ObjCSel => { + trace!(" simple type that can always derive Hash"); + ConstrainResult::Same + } + + TypeKind::Complex(..) | + TypeKind::Float(..) => { + trace!(" float cannot derive Hash"); + self.insert(id) + } + + TypeKind::Array(t, len) => { + if self.cannot_derive_hash.contains(&t) { + trace!(" arrays of T for which we cannot derive Hash \ + also cannot derive Hash"); + return self.insert(id); + } + + if len <= RUST_DERIVE_IN_ARRAY_LIMIT { + trace!(" array is small enough to derive Hash"); + ConstrainResult::Same + } else { + trace!(" array is too large to derive Hash"); + self.insert(id) + } + } + + TypeKind::Pointer(inner) => { + let inner_type = self.ctx.resolve_type(inner).canonical_type(self.ctx); + if let TypeKind::Function(ref sig) = *inner_type.kind() { + if !sig.can_trivially_derive_hash() { + trace!(" function pointer that can't trivially derive Hash"); + return self.insert(id); + } + } + trace!(" pointers can derive Hash"); + ConstrainResult::Same + } + + TypeKind::Function(ref sig) => { + if !sig.can_trivially_derive_hash() { + trace!(" function that can't trivially derive Hash"); + return self.insert(id); + } + trace!(" function can derive Hash"); + ConstrainResult::Same + } + + TypeKind::ResolvedTypeRef(t) | + TypeKind::TemplateAlias(t, _) | + TypeKind::Alias(t) => { + if self.cannot_derive_hash.contains(&t) { + trace!(" aliases and type refs to T which cannot derive \ + Hash also cannot derive Hash"); + self.insert(id) + } else { + trace!(" aliases and type refs to T which can derive \ + Hash can also derive Hash"); + ConstrainResult::Same + } + } + + TypeKind::Comp(ref info) => { + assert!( + !info.has_non_type_template_params(), + "The early ty.is_opaque check should have handled this case" + ); + + if info.kind() == CompKind::Union { + if self.ctx.options().unstable_rust { + trace!(" cannot derive Hash for Rust unions"); + return self.insert(id); + } + + if ty.layout(self.ctx) + .map_or(true, + |l| l.opaque().can_trivially_derive_hash()) { + trace!(" union layout can trivially derive Hash"); + return ConstrainResult::Same; + } else { + trace!(" union layout cannot derive Hash"); + return self.insert(id); + } + } + + let bases_cannot_derive = info.base_members() + .iter() + .any(|base| !self.ctx.whitelisted_items().contains(&base.ty) || + self.cannot_derive_hash.contains(&base.ty)); + if bases_cannot_derive { + trace!(" base members cannot derive Hash, so we can't \ + either"); + return self.insert(id); + } + + let fields_cannot_derive = info.fields() + .iter() + .any(|f| { + match *f { + Field::DataMember(ref data) => { + !self.ctx.whitelisted_items().contains(&data.ty()) || + self.cannot_derive_hash.contains(&data.ty()) + } + Field::Bitfields(ref bfu) => { + bfu.bitfields() + .iter().any(|b| { + !self.ctx.whitelisted_items().contains(&b.ty()) || + self.cannot_derive_hash.contains(&b.ty()) + }) + } + } + }); + if fields_cannot_derive { + trace!(" fields cannot derive Hash, so we can't either"); + return self.insert(id); + } + + trace!(" comp can derive Hash"); + ConstrainResult::Same + } + + TypeKind::TemplateInstantiation(ref template) => { + let args_cannot_derive = template.template_arguments() + .iter() + .any(|arg| self.cannot_derive_hash.contains(&arg)); + if args_cannot_derive { + trace!(" template args cannot derive Hash, so \ + insantiation can't either"); + return self.insert(id); + } + + assert!( + !template.template_definition().is_opaque(self.ctx, &()), + "The early ty.is_opaque check should have handled this case" + ); + let def_cannot_derive = self.cannot_derive_hash + .contains(&template.template_definition()); + if def_cannot_derive { + trace!(" template definition cannot derive Hash, so \ + insantiation can't either"); + return self.insert(id); + } + + trace!(" template instantiation can derive Hash"); + ConstrainResult::Same + } + + TypeKind::Opaque => { + unreachable!( + "The early ty.is_opaque check should have handled this case" + ) + } + } + } + + fn each_depending_on(&self, id: ItemId, mut f: F) + where F: FnMut(ItemId), + { + if let Some(edges) = self.dependencies.get(&id) { + for item in edges { + trace!("enqueue {:?} into worklist", item); + f(*item); + } + } + } +} + +impl<'ctx, 'gen> From> for HashSet { + fn from(analysis: CannotDeriveHash<'ctx, 'gen>) -> Self { + analysis.cannot_derive_hash + } +} diff --git a/src/ir/analysis/mod.rs b/src/ir/analysis/mod.rs index f77c088623..28ca09aa42 100644 --- a/src/ir/analysis/mod.rs +++ b/src/ir/analysis/mod.rs @@ -51,6 +51,8 @@ mod derive_copy; pub use self::derive_copy::CannotDeriveCopy; mod has_type_param_in_array; pub use self::has_type_param_in_array::HasTypeParameterInArray; +mod derive_hash; +pub use self::derive_hash::CannotDeriveHash; use ir::context::{BindgenContext, ItemId}; use ir::traversal::{EdgeKind, Trace}; diff --git a/src/ir/context.rs b/src/ir/context.rs index 2e0899ed0f..5caebedaac 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1,12 +1,13 @@ //! Common context that is passed around during parsing and codegen. -use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; +use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, CanDeriveHash}; use super::int::IntKind; use super::item::{IsOpaque, HasTypeParamInArray, Item, ItemAncestors, ItemCanonicalPath, ItemSet}; use super::item_kind::ItemKind; use super::module::{Module, ModuleKind}; use super::analysis::{analyze, UsedTemplateParameters, CannotDeriveDebug, HasVtableAnalysis, - CannotDeriveDefault, CannotDeriveCopy, HasTypeParameterInArray}; + CannotDeriveDefault, CannotDeriveCopy, HasTypeParameterInArray, + CannotDeriveHash}; use super::template::{TemplateInstantiation, TemplateParameters}; use super::traversal::{self, Edge, ItemTraversal}; use super::ty::{FloatKind, Type, TypeKind}; @@ -58,6 +59,12 @@ impl<'a> CanDeriveCopy<'a> for ItemId { } } +impl CanDeriveHash for ItemId { + fn can_derive_hash(&self, ctx: &BindgenContext) -> bool { + ctx.options().derive_hash && ctx.lookup_item_id_can_derive_hash(*self) + } +} + /// A key used to index a resolved type, so we only process it once. /// /// This is almost always a USR string (an unique identifier generated by @@ -194,6 +201,12 @@ pub struct BindgenContext<'ctx> { /// and is always `None` before that and `Some` after. cannot_derive_copy_in_array: Option>, + /// The set of (`ItemId`s of) types that can't derive hash. + /// + /// This is populated when we enter codegen by `compute_can_derive_hash` + /// and is always `None` before that and `Some` after. + cannot_derive_hash: Option>, + /// The set of (`ItemId's of`) types that has vtable. /// /// Populated when we enter codegen by `compute_has_vtable`; always `None` @@ -334,6 +347,7 @@ impl<'ctx> BindgenContext<'ctx> { cannot_derive_default: None, cannot_derive_copy: None, cannot_derive_copy_in_array: None, + cannot_derive_hash: None, have_vtable: None, has_type_param_in_array: None, }; @@ -812,6 +826,7 @@ impl<'ctx> BindgenContext<'ctx> { self.compute_cannot_derive_default(); self.compute_cannot_derive_copy(); self.compute_has_type_param_in_array(); + self.compute_cannot_derive_hash(); let ret = cb(self); self.gen_ctx = None; @@ -1818,8 +1833,25 @@ impl<'ctx> BindgenContext<'ctx> { self.cannot_derive_copy = Some(analyze::(self)); } + /// Compute whether we can derive hash. + fn compute_cannot_derive_hash(&mut self) { + assert!(self.cannot_derive_hash.is_none()); + self.cannot_derive_hash = Some(analyze::(self)); + } + /// Look up whether the item with `id` can - /// derive debug or not. + /// derive hash or not. + pub fn lookup_item_id_can_derive_hash(&self, id: ItemId) -> bool { + assert!(self.in_codegen_phase(), + "We only compute can_derive_debug when we enter codegen"); + + // Look up the computed value for whether the item with `id` can + // derive hash or not. + !self.cannot_derive_hash.as_ref().unwrap().contains(&id) + } + + /// Look up whether the item with `id` can + /// derive copy or not. pub fn lookup_item_id_can_derive_copy(&self, id: ItemId) -> bool { assert!(self.in_codegen_phase(), "We only compute can_derive_debug when we enter codegen"); diff --git a/src/ir/derive.rs b/src/ir/derive.rs index 6d8c2c87c2..128ef9f214 100644 --- a/src/ir/derive.rs +++ b/src/ir/derive.rs @@ -71,3 +71,30 @@ pub trait CanTriviallyDeriveDefault { /// otherwise. fn can_trivially_derive_default(&self) -> bool; } + +/// A trait that encapsulates the logic for whether or not we can derive `Hash` +/// for a given thing. +/// +/// This should ideally be a no-op that just returns `true`, but instead needs +/// to be a recursive method that checks whether all the proper members can +/// derive default or not, because of the limit rust has on 32 items as max in the +/// array. +pub trait CanDeriveHash { + + /// Return `true` if `Default` can be derived for this thing, `false` + /// otherwise. + fn can_derive_hash(&self, + ctx: &BindgenContext) + -> bool; +} + +/// A trait that encapsulates the logic for whether or not we can derive `Hash`. +/// The difference between this trait and the CanDeriveHash is that the type +/// implementing this trait cannot use recursion or lookup result from fix point +/// analysis. It's a helper trait for fix point analysis. +pub trait CanTriviallyDeriveHash { + + /// Return `true` if `Hash` can be derived for this thing, `false` + /// otherwise. + fn can_trivially_derive_hash(&self) -> bool; +} diff --git a/src/ir/function.rs b/src/ir/function.rs index 99ab8772a7..20c026a4ba 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -8,11 +8,13 @@ use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; use clang; use clang_sys::{self, CXCallingConv}; -use ir::derive::CanTriviallyDeriveDebug; +use ir::derive::{CanTriviallyDeriveDebug, CanTriviallyDeriveHash}; use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult}; use std::io; use syntax::abi; +const RUST_DERIVE_FUNPTR_LIMIT: usize = 12; + /// What kind of a function are we looking at? #[derive(Debug, Copy, Clone, PartialEq)] pub enum FunctionKind { @@ -481,7 +483,20 @@ impl Trace for FunctionSig { // Note that copy is always derived, so we don't need to implement it. impl CanTriviallyDeriveDebug for FunctionSig { fn can_trivially_derive_debug(&self) -> bool { - const RUST_DERIVE_FUNPTR_LIMIT: usize = 12; + if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT { + return false; + } + + match self.abi { + Abi::Known(abi::Abi::C) | + Abi::Unknown(..) => true, + _ => false, + } + } +} + +impl CanTriviallyDeriveHash for FunctionSig { + fn can_trivially_derive_hash(&self) -> bool { if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT { return false; } diff --git a/src/ir/item.rs b/src/ir/item.rs index a17f26fbba..237618c8c3 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -5,7 +5,7 @@ use super::annotations::Annotations; use super::comment; use super::comp::MethodKind; use super::context::{BindgenContext, ItemId, PartialType}; -use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; +use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, CanDeriveHash}; use super::dot::DotAttributes; use super::function::{Function, FunctionKind}; use super::item_kind::ItemKind; @@ -294,6 +294,12 @@ impl<'a> CanDeriveCopy<'a> for Item { } } +impl CanDeriveHash for Item { + fn can_derive_hash(&self, ctx: &BindgenContext) -> bool { + ctx.options().derive_hash && ctx.lookup_item_id_can_derive_hash(self.id()) + } +} + /// An item is the base of the bindgen representation, it can be either a /// module, a type, a function, or a variable (see `ItemKind` for more /// information). diff --git a/src/ir/layout.rs b/src/ir/layout.rs index 9ec04d2010..bac664f1f7 100644 --- a/src/ir/layout.rs +++ b/src/ir/layout.rs @@ -1,7 +1,8 @@ //! Intermediate representation for the physical layout of some type. use super::derive::{CanTriviallyDeriveDebug, - CanTriviallyDeriveDefault, CanTriviallyDeriveCopy}; + CanTriviallyDeriveDefault, CanTriviallyDeriveCopy, + CanTriviallyDeriveHash}; use super::ty::{RUST_DERIVE_IN_ARRAY_LIMIT, Type, TypeKind}; use clang; use std::{cmp, mem}; @@ -123,3 +124,11 @@ impl CanTriviallyDeriveCopy for Opaque { .map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) } } + +impl CanTriviallyDeriveHash for Opaque { + + fn can_trivially_derive_hash(&self) -> bool { + self.array_size() + .map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) + } +} diff --git a/src/lib.rs b/src/lib.rs index 3a85382940..bb42117d2d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -242,6 +242,10 @@ impl Builder { output_vector.push("--with-derive-default".into()); } + if self.options.derive_hash { + output_vector.push("--with-derive-hash".into()); + } + if !self.options.generate_comments { output_vector.push("--no-doc-comments".into()); } @@ -652,6 +656,12 @@ impl Builder { self } + /// Set whether `Hash` should be derived by default. + pub fn derive_hash(mut self, doit: bool) -> Self { + self.options.derive_hash = doit; + self + } + /// Emit Clang AST. pub fn emit_clang_ast(mut self) -> Builder { self.options.emit_ast = true; @@ -955,6 +965,10 @@ pub struct BindgenOptions { /// and types. pub derive_default: bool, + /// True if we should derive Hash trait implementations for C/C++ structures + /// and types. + pub derive_hash: bool, + /// True if we can use unstable Rust code in the bindings, false if we /// cannot. pub unstable_rust: bool, @@ -1064,6 +1078,7 @@ impl Default for BindgenOptions { layout_tests: true, derive_debug: true, derive_default: false, + derive_hash: false, enable_cxx_namespaces: false, disable_name_namespacing: false, unstable_rust: false, diff --git a/src/options.rs b/src/options.rs index f2ed549410..706936af65 100644 --- a/src/options.rs +++ b/src/options.rs @@ -62,6 +62,9 @@ pub fn builder_from_flags Arg::with_name("with-derive-default") .long("with-derive-default") .help("Derive Default on any type."), + Arg::with_name("with-derive-hash") + .long("with-derive-hash") + .help("Derive hash on any type."), Arg::with_name("no-doc-comments") .long("no-doc-comments") .help("Avoid including doc comments in the output, see: \ @@ -265,6 +268,10 @@ pub fn builder_from_flags builder = builder.derive_default(true); } + if matches.is_present("with-derive-hash") { + builder = builder.derive_hash(true); + } + if matches.is_present("no-derive-default") { builder = builder.derive_default(false); } From e5e69058910dcad1680754a2932c11c931d9ab2d Mon Sep 17 00:00:00 2001 From: zzhu Date: Wed, 2 Aug 2017 11:23:27 -0700 Subject: [PATCH 02/12] Union related tests for derive Hash --- tests/expectations/tests/union-in-ns.rs | 3 +++ tests/expectations/tests/union_dtor.rs | 3 +++ tests/expectations/tests/union_fields.rs | 5 ++++- tests/expectations/tests/union_template.rs | 11 +++++++---- tests/expectations/tests/union_with_anon_struct.rs | 7 +++++-- .../tests/union_with_anon_struct_bitfield.rs | 7 +++++-- tests/expectations/tests/union_with_anon_union.rs | 7 +++++-- .../tests/union_with_anon_unnamed_struct.rs | 7 +++++-- .../tests/union_with_anon_unnamed_union.rs | 7 +++++-- tests/expectations/tests/union_with_big_member.rs | 5 ++++- tests/expectations/tests/union_with_nesting.rs | 11 +++++++---- tests/headers/union_fields.hpp | 2 ++ tests/headers/union_template.hpp | 2 ++ tests/headers/union_with_anon_struct.h | 2 ++ tests/headers/union_with_anon_struct_bitfield.h | 2 ++ tests/headers/union_with_anon_union.h | 2 ++ tests/headers/union_with_anon_unnamed_struct.h | 2 ++ tests/headers/union_with_anon_unnamed_union.h | 2 ++ tests/headers/union_with_big_member.h | 2 ++ tests/headers/union_with_nesting.h | 2 ++ 20 files changed, 71 insertions(+), 20 deletions(-) diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index 8beb7a92a0..968b1f83ad 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -34,6 +34,9 @@ pub mod root { fmt.write_str("__BindgenUnionField") } } + impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } + } #[allow(unused_imports)] use self::super::root; #[repr(C)] diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index 429ec082af..6f7eba4120 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -28,6 +28,9 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] #[derive(Debug, Default)] pub struct UnionWithDtor { diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 45ce647316..fd4ac5ab56 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -28,8 +28,11 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct nsStyleUnion { pub mInt: __BindgenUnionField<::std::os::raw::c_int>, pub mFloat: __BindgenUnionField, diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index 7f30e7b49f..df5e87ee29 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -28,29 +28,32 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] 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)] +#[derive(Debug, Default, Copy, Clone, Hash)] 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, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] 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, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct Whatever { pub mTPtr: __BindgenUnionField<*mut ::std::os::raw::c_void>, pub mInt: __BindgenUnionField<::std::os::raw::c_int>, diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index f0bb68d577..5afaa8764e 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -28,14 +28,17 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub bar: __BindgenUnionField, pub bindgen_union_field: [u32; 2usize], } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index e6acd10566..ba1cdf47f6 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -28,15 +28,18 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub a: __BindgenUnionField<::std::os::raw::c_int>, pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub _bitfield_1: u32, pub __bindgen_align: [u32; 0usize], diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 668160a772..99c0c8178b 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -28,14 +28,17 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub bar: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub b: __BindgenUnionField<::std::os::raw::c_ushort>, diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 98524422d1..afe12dce67 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -28,15 +28,18 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct pixel { pub rgba: __BindgenUnionField<::std::os::raw::c_uint>, pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct pixel__bindgen_ty_1 { pub r: ::std::os::raw::c_uchar, pub g: ::std::os::raw::c_uchar, diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 1a6f5f4535..67dcd5210c 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -28,15 +28,18 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub b: __BindgenUnionField<::std::os::raw::c_ushort>, pub c: __BindgenUnionField<::std::os::raw::c_uchar>, diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 679832fdec..836fe1a59f 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -28,6 +28,9 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] #[derive(Copy)] pub struct WithBigArray { @@ -59,7 +62,7 @@ impl Default for WithBigArray { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct WithBigArray2 { pub a: __BindgenUnionField<::std::os::raw::c_int>, pub b: __BindgenUnionField<[::std::os::raw::c_char; 33usize]>, diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 7e32f0c0d9..59caccf4fd 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -28,21 +28,24 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub __bindgen_anon_1: foo__bindgen_ty_1__bindgen_ty_1, pub __bindgen_anon_2: foo__bindgen_ty_1__bindgen_ty_2, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub b1: __BindgenUnionField<::std::os::raw::c_ushort>, pub b2: __BindgenUnionField<::std::os::raw::c_ushort>, @@ -75,7 +78,7 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub c1: __BindgenUnionField<::std::os::raw::c_ushort>, pub c2: __BindgenUnionField<::std::os::raw::c_ushort>, diff --git a/tests/headers/union_fields.hpp b/tests/headers/union_fields.hpp index aec3a7fdf4..cc8fcbe45f 100644 --- a/tests/headers/union_fields.hpp +++ b/tests/headers/union_fields.hpp @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// typedef union { int mInt; float mFloat; diff --git a/tests/headers/union_template.hpp b/tests/headers/union_template.hpp index 0d0a9bb31d..f330f6b28c 100644 --- a/tests/headers/union_template.hpp +++ b/tests/headers/union_template.hpp @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// template struct NastyStruct { bool mIsSome; diff --git a/tests/headers/union_with_anon_struct.h b/tests/headers/union_with_anon_struct.h index 7f8dec953f..48adae8bd6 100644 --- a/tests/headers/union_with_anon_struct.h +++ b/tests/headers/union_with_anon_struct.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// union foo { struct { unsigned int a; diff --git a/tests/headers/union_with_anon_struct_bitfield.h b/tests/headers/union_with_anon_struct_bitfield.h index 9668ce4057..027a99eb9f 100644 --- a/tests/headers/union_with_anon_struct_bitfield.h +++ b/tests/headers/union_with_anon_struct_bitfield.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// union foo { int a; struct { diff --git a/tests/headers/union_with_anon_union.h b/tests/headers/union_with_anon_union.h index 212431b895..b2b6fc1280 100644 --- a/tests/headers/union_with_anon_union.h +++ b/tests/headers/union_with_anon_union.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// union foo { union { unsigned int a; diff --git a/tests/headers/union_with_anon_unnamed_struct.h b/tests/headers/union_with_anon_unnamed_struct.h index 79558049ed..70ae15fedf 100644 --- a/tests/headers/union_with_anon_unnamed_struct.h +++ b/tests/headers/union_with_anon_unnamed_struct.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// union pixel { unsigned int rgba; struct { diff --git a/tests/headers/union_with_anon_unnamed_union.h b/tests/headers/union_with_anon_unnamed_union.h index 7580771ae0..1044360973 100644 --- a/tests/headers/union_with_anon_unnamed_union.h +++ b/tests/headers/union_with_anon_unnamed_union.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// union foo { unsigned int a; union { diff --git a/tests/headers/union_with_big_member.h b/tests/headers/union_with_big_member.h index 6347d6cad3..abc0062e28 100644 --- a/tests/headers/union_with_big_member.h +++ b/tests/headers/union_with_big_member.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// union WithBigArray { int a; int b[33]; diff --git a/tests/headers/union_with_nesting.h b/tests/headers/union_with_nesting.h index cd907d57f2..e40f521249 100644 --- a/tests/headers/union_with_nesting.h +++ b/tests/headers/union_with_nesting.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// union foo { unsigned int a; struct { From b0fea0e2f1d026ee2d95ac2e8403e4afed7a3ee8 Mon Sep 17 00:00:00 2001 From: Zhiting Zhu Date: Thu, 3 Aug 2017 22:27:52 -0700 Subject: [PATCH 03/12] Struct related tests for derive Hash --- .../struct_containing_forward_declared_struct.rs | 4 ++-- tests/expectations/tests/struct_typedef.rs | 4 ++-- tests/expectations/tests/struct_typedef_ns.rs | 4 ++-- tests/expectations/tests/struct_with_anon_struct.rs | 4 ++-- .../tests/struct_with_anon_struct_array.rs | 6 +++--- .../tests/struct_with_anon_struct_pointer.rs | 4 ++-- tests/expectations/tests/struct_with_anon_union.rs | 7 +++++-- .../tests/struct_with_anon_unnamed_struct.rs | 4 ++-- .../tests/struct_with_anon_unnamed_union.rs | 7 +++++-- tests/expectations/tests/struct_with_bitfields.rs | 2 +- tests/expectations/tests/struct_with_derive_debug.rs | 4 ++-- tests/expectations/tests/struct_with_nesting.rs | 11 +++++++---- tests/expectations/tests/struct_with_packing.rs | 2 +- tests/expectations/tests/struct_with_struct.rs | 4 ++-- .../tests/struct_with_typedef_template_arg.rs | 2 +- .../struct_containing_forward_declared_struct.h | 1 + tests/headers/struct_typedef.h | 2 ++ tests/headers/struct_typedef_ns.hpp | 2 +- tests/headers/struct_with_anon_struct.h | 2 ++ tests/headers/struct_with_anon_struct_array.h | 2 ++ tests/headers/struct_with_anon_struct_pointer.h | 1 + tests/headers/struct_with_anon_union.h | 2 ++ tests/headers/struct_with_anon_unnamed_struct.h | 1 + tests/headers/struct_with_anon_unnamed_union.h | 1 + tests/headers/struct_with_bitfields.h | 2 ++ tests/headers/struct_with_derive_debug.h | 2 ++ tests/headers/struct_with_large_array.hpp | 2 ++ tests/headers/struct_with_nesting.h | 2 ++ tests/headers/struct_with_packing.h | 2 ++ tests/headers/struct_with_struct.h | 2 ++ tests/headers/struct_with_typedef_template_arg.hpp | 1 + 31 files changed, 65 insertions(+), 31 deletions(-) diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 6b24373290..b72d67c99e 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct a { pub val_a: *mut b, } @@ -28,7 +28,7 @@ impl Default for a { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct b { pub val_b: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index 4f41e1875a..c01d396397 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct typedef_named_struct { pub has_name: bool, } @@ -26,7 +26,7 @@ impl Clone for typedef_named_struct { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct _bindgen_ty_1 { pub no_name: *mut ::std::os::raw::c_void, } diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index e436beb2fe..4723432163 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -12,7 +12,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Hash)] pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } @@ -41,7 +41,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Hash)] pub struct _bindgen_ty_1 { pub foo: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index 015e7d868e..26e06c0b89 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index 8934e8a6d6..a2ab1b2b6b 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -5,13 +5,13 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub bar: [foo__bindgen_ty_1; 2usize], pub baz: [[[foo__bindgen_ty_2; 4usize]; 3usize]; 2usize], } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, @@ -37,7 +37,7 @@ impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_2 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index cba5b8a601..cfe5dbd70d 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct foo { pub bar: *mut foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index 5984ba6e59..84be35ed2a 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -28,13 +28,16 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub b: __BindgenUnionField<::std::os::raw::c_ushort>, diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index a7374bc444..8a5d6194ad 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 09dbbb59f1..226f7db9f1 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -28,13 +28,16 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub a: __BindgenUnionField<::std::os::raw::c_uint>, pub b: __BindgenUnionField<::std::os::raw::c_ushort>, diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index b93b441f9d..97cefe0691 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct bitfield { pub _bitfield_1: u8, pub e: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index b2a77b2772..2fd00fb182 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct LittleArray { pub a: [::std::os::raw::c_int; 32usize], } @@ -48,7 +48,7 @@ impl Default for BigArray { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct WithLittleArray { pub a: LittleArray, } diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 1a8e887d05..63df2729f7 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -28,14 +28,17 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub a: ::std::os::raw::c_uint, pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub b: __BindgenUnionField<::std::os::raw::c_uint>, pub __bindgen_anon_1: __BindgenUnionField, @@ -43,7 +46,7 @@ pub struct foo__bindgen_ty_1 { pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, @@ -75,7 +78,7 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub d1: ::std::os::raw::c_uchar, pub d2: ::std::os::raw::c_uchar, diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index abeb0b8361..7e587a072d 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -5,7 +5,7 @@ #[repr(C, packed)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct a { pub b: ::std::os::raw::c_char, pub c: ::std::os::raw::c_short, diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index 1ad359f37d..d6509a14b8 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct foo__bindgen_ty_1 { pub x: ::std::os::raw::c_uint, pub y: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/struct_with_typedef_template_arg.rs b/tests/expectations/tests/struct_with_typedef_template_arg.rs index 9066e037c7..7566bf4a8c 100644 --- a/tests/expectations/tests/struct_with_typedef_template_arg.rs +++ b/tests/expectations/tests/struct_with_typedef_template_arg.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct Proxy { pub _address: u8, } diff --git a/tests/headers/struct_containing_forward_declared_struct.h b/tests/headers/struct_containing_forward_declared_struct.h index d38aca2fc7..6882819273 100644 --- a/tests/headers/struct_containing_forward_declared_struct.h +++ b/tests/headers/struct_containing_forward_declared_struct.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash struct a { struct b* val_a; }; diff --git a/tests/headers/struct_typedef.h b/tests/headers/struct_typedef.h index fdce9a721d..f8eacd871b 100644 --- a/tests/headers/struct_typedef.h +++ b/tests/headers/struct_typedef.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// typedef struct { _Bool has_name; } typedef_named_struct; diff --git a/tests/headers/struct_typedef_ns.hpp b/tests/headers/struct_typedef_ns.hpp index bc89eb2be3..62a8ceac0e 100644 --- a/tests/headers/struct_typedef_ns.hpp +++ b/tests/headers/struct_typedef_ns.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces +// bindgen-flags: --with-derive-hash --enable-cxx-namespaces namespace whatever { typedef struct { diff --git a/tests/headers/struct_with_anon_struct.h b/tests/headers/struct_with_anon_struct.h index 1617d7a8dc..e6a8ab97c5 100644 --- a/tests/headers/struct_with_anon_struct.h +++ b/tests/headers/struct_with_anon_struct.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// struct foo { struct { int a; diff --git a/tests/headers/struct_with_anon_struct_array.h b/tests/headers/struct_with_anon_struct_array.h index 9ea977e8d7..459e274a23 100644 --- a/tests/headers/struct_with_anon_struct_array.h +++ b/tests/headers/struct_with_anon_struct_array.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// struct foo { struct { int a; diff --git a/tests/headers/struct_with_anon_struct_pointer.h b/tests/headers/struct_with_anon_struct_pointer.h index 0c486d84f5..de628402fa 100644 --- a/tests/headers/struct_with_anon_struct_pointer.h +++ b/tests/headers/struct_with_anon_struct_pointer.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash struct foo { struct { int a; diff --git a/tests/headers/struct_with_anon_union.h b/tests/headers/struct_with_anon_union.h index 3a92b94072..45ddb3c401 100644 --- a/tests/headers/struct_with_anon_union.h +++ b/tests/headers/struct_with_anon_union.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// struct foo { union { unsigned int a; diff --git a/tests/headers/struct_with_anon_unnamed_struct.h b/tests/headers/struct_with_anon_unnamed_struct.h index f8ac422599..5962a12cff 100644 --- a/tests/headers/struct_with_anon_unnamed_struct.h +++ b/tests/headers/struct_with_anon_unnamed_struct.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash struct foo { struct { unsigned int a; diff --git a/tests/headers/struct_with_anon_unnamed_union.h b/tests/headers/struct_with_anon_unnamed_union.h index 7158e727c6..949547c1ca 100644 --- a/tests/headers/struct_with_anon_unnamed_union.h +++ b/tests/headers/struct_with_anon_unnamed_union.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash struct foo { union { unsigned int a; diff --git a/tests/headers/struct_with_bitfields.h b/tests/headers/struct_with_bitfields.h index ece512cd95..88a167a0cc 100644 --- a/tests/headers/struct_with_bitfields.h +++ b/tests/headers/struct_with_bitfields.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// struct bitfield { unsigned short a :1, diff --git a/tests/headers/struct_with_derive_debug.h b/tests/headers/struct_with_derive_debug.h index 98ba1b3d60..d13bb46610 100644 --- a/tests/headers/struct_with_derive_debug.h +++ b/tests/headers/struct_with_derive_debug.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// struct LittleArray { int a[32]; }; diff --git a/tests/headers/struct_with_large_array.hpp b/tests/headers/struct_with_large_array.hpp index fc67b333a3..c9aaa697d3 100644 --- a/tests/headers/struct_with_large_array.hpp +++ b/tests/headers/struct_with_large_array.hpp @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// struct S { char large_array[33]; }; diff --git a/tests/headers/struct_with_nesting.h b/tests/headers/struct_with_nesting.h index 9d7fa17627..30f40bcec4 100644 --- a/tests/headers/struct_with_nesting.h +++ b/tests/headers/struct_with_nesting.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// struct foo { unsigned int a; union { diff --git a/tests/headers/struct_with_packing.h b/tests/headers/struct_with_packing.h index 1b9fe13193..2184e8ec7c 100644 --- a/tests/headers/struct_with_packing.h +++ b/tests/headers/struct_with_packing.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// struct a { char b; short c; diff --git a/tests/headers/struct_with_struct.h b/tests/headers/struct_with_struct.h index 78b1cc81c6..975b0af4ad 100644 --- a/tests/headers/struct_with_struct.h +++ b/tests/headers/struct_with_struct.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// struct foo { struct { unsigned int x; diff --git a/tests/headers/struct_with_typedef_template_arg.hpp b/tests/headers/struct_with_typedef_template_arg.hpp index 7fed21ab18..f299e3227b 100644 --- a/tests/headers/struct_with_typedef_template_arg.hpp +++ b/tests/headers/struct_with_typedef_template_arg.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash template struct Proxy { typedef void (*foo)(T* bar); From a529e92870c8710d10f870dd09c824091d91f856 Mon Sep 17 00:00:00 2001 From: Zhiting Zhu Date: Fri, 4 Aug 2017 10:17:53 -0700 Subject: [PATCH 04/12] Class related tests for derive Hash --- tests/expectations/tests/class.rs | 11 +++++---- tests/expectations/tests/class_nested.rs | 14 +++++------ tests/expectations/tests/class_no_members.rs | 6 ++--- tests/expectations/tests/class_static.rs | 2 +- .../expectations/tests/class_static_const.rs | 2 +- tests/expectations/tests/class_use_as.rs | 4 ++-- tests/expectations/tests/class_with_dtor.rs | 4 ++-- .../tests/class_with_inner_struct.rs | 23 +++++++++++-------- .../expectations/tests/class_with_typedef.rs | 4 ++-- tests/headers/class.hpp | 2 ++ tests/headers/class_nested.hpp | 1 + tests/headers/class_no_members.hpp | 1 + tests/headers/class_static.hpp | 1 + tests/headers/class_static_const.hpp | 1 + tests/headers/class_use_as.hpp | 1 + tests/headers/class_with_dtor.hpp | 1 + tests/headers/class_with_inner_struct.hpp | 1 + tests/headers/class_with_typedef.hpp | 1 + 18 files changed, 48 insertions(+), 32 deletions(-) diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index 26e6a62c3e..b628ab111c 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -61,6 +61,9 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] #[derive(Copy)] pub struct C { @@ -165,7 +168,7 @@ impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default)] +#[derive(Debug, Default, Hash)] pub struct WithDtor { pub b: ::std::os::raw::c_int, } @@ -200,7 +203,7 @@ impl Default for IncompleteArrayNonCopiable { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Union { pub d: __BindgenUnionField, pub i: __BindgenUnionField<::std::os::raw::c_int>, @@ -227,7 +230,7 @@ impl Clone for Union { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct WithUnion { pub data: Union, } @@ -247,7 +250,7 @@ impl Clone for WithUnion { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct RealAbstractionWithTonsOfMethods { pub _address: u8, } diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 11e2f9396e..4172d46789 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct A { pub member_a: ::std::os::raw::c_int, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct A_B { pub member_b: ::std::os::raw::c_int, } @@ -30,7 +30,7 @@ impl Clone for A_B { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct A_C { pub baz: ::std::os::raw::c_int, } @@ -50,7 +50,7 @@ impl Clone for A_C { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct A_D { pub foo: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -93,7 +93,7 @@ extern "C" { pub static mut baz: A_D<::std::os::raw::c_int>; } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct D { pub member: A_B, } @@ -113,13 +113,13 @@ impl Clone for D { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct Templated { pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct Templated_Templated_inner { pub member_ptr: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index 41b97a9c9d..e78964fe3b 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct whatever { pub _address: u8, } @@ -20,7 +20,7 @@ impl Clone for whatever { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct whatever_child { pub _address: u8, } @@ -35,7 +35,7 @@ impl Clone for whatever_child { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct whatever_child_with_member { pub m_member: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/class_static.rs b/tests/expectations/tests/class_static.rs index b48fd0522c..97dcbf799a 100644 --- a/tests/expectations/tests/class_static.rs +++ b/tests/expectations/tests/class_static.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct MyClass { pub _address: u8, } diff --git a/tests/expectations/tests/class_static_const.rs b/tests/expectations/tests/class_static_const.rs index b8e91bd334..a599ed89a6 100644 --- a/tests/expectations/tests/class_static_const.rs +++ b/tests/expectations/tests/class_static_const.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct A { pub _address: u8, } diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index 15cc61f6ba..a8d26d29c4 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -6,7 +6,7 @@ ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct whatever { pub replacement: ::std::os::raw::c_int, } @@ -26,7 +26,7 @@ impl Clone for whatever { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct container { pub c: whatever, } diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index cf36f119e7..8686c41c89 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct HandleWithDtor { pub ptr: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -15,7 +15,7 @@ impl Default for HandleWithDtor { } pub type HandleValue = HandleWithDtor<::std::os::raw::c_int>; #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct WithoutDtor { pub shouldBeWithDtor: HandleValue, } diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index f4b03b4e46..4ccafab43a 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -28,15 +28,18 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct A { pub c: ::std::os::raw::c_uint, pub named_union: A__bindgen_ty_1, pub __bindgen_anon_1: A__bindgen_ty_2, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct A_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, @@ -62,7 +65,7 @@ impl Clone for A_Segment { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct A__bindgen_ty_1 { pub f: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, @@ -83,7 +86,7 @@ impl Clone for A__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct A__bindgen_ty_2 { pub d: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, @@ -123,12 +126,12 @@ impl Clone for A { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct B { pub d: ::std::os::raw::c_uint, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct B_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, @@ -176,13 +179,13 @@ pub enum StepSyntax { FunctionalWithEndKeyword = 3, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct C { pub d: ::std::os::raw::c_uint, pub __bindgen_anon_1: C__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct C__bindgen_ty_1 { pub mFunc: __BindgenUnionField, pub __bindgen_anon_1: __BindgenUnionField, @@ -234,7 +237,7 @@ impl Clone for C__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct C__bindgen_ty_1__bindgen_ty_2 { pub mStepSyntax: StepSyntax, pub mSteps: ::std::os::raw::c_uint, @@ -283,7 +286,7 @@ impl Clone for C__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct C_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index 9dba86759c..f41aa22858 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -6,7 +6,7 @@ pub type AnotherInt = ::std::os::raw::c_int; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct C { pub c: C_MyInt, pub ptr: *mut C_MyInt, @@ -85,7 +85,7 @@ impl C { } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct D { pub _base: C, pub ptr: *mut C_MyInt, diff --git a/tests/headers/class.hpp b/tests/headers/class.hpp index 1de164710d..3e183cdf5b 100644 --- a/tests/headers/class.hpp +++ b/tests/headers/class.hpp @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// class C { int a; // More than rust limits (32) diff --git a/tests/headers/class_nested.hpp b/tests/headers/class_nested.hpp index 208bc4be0a..e01fc947a5 100644 --- a/tests/headers/class_nested.hpp +++ b/tests/headers/class_nested.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash class A { public: int member_a; diff --git a/tests/headers/class_no_members.hpp b/tests/headers/class_no_members.hpp index a448355866..03f916a9f8 100644 --- a/tests/headers/class_no_members.hpp +++ b/tests/headers/class_no_members.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash // bindgen-flags: -- -std=c++11 class whatever { diff --git a/tests/headers/class_static.hpp b/tests/headers/class_static.hpp index 21ab232139..1e38e5a510 100644 --- a/tests/headers/class_static.hpp +++ b/tests/headers/class_static.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash class MyClass { public: static const int* example; diff --git a/tests/headers/class_static_const.hpp b/tests/headers/class_static_const.hpp index 150afe8bd3..9259918331 100644 --- a/tests/headers/class_static_const.hpp +++ b/tests/headers/class_static_const.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash using int32_t = int; typedef unsigned int uint32_t; diff --git a/tests/headers/class_use_as.hpp b/tests/headers/class_use_as.hpp index a4e36ded18..6924255d1d 100644 --- a/tests/headers/class_use_as.hpp +++ b/tests/headers/class_use_as.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash /** *
diff --git a/tests/headers/class_with_dtor.hpp b/tests/headers/class_with_dtor.hpp index b9bf74e1ac..9cc2bad450 100644 --- a/tests/headers/class_with_dtor.hpp +++ b/tests/headers/class_with_dtor.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash template diff --git a/tests/headers/class_with_inner_struct.hpp b/tests/headers/class_with_inner_struct.hpp index ec729fe66c..781a01dbfd 100644 --- a/tests/headers/class_with_inner_struct.hpp +++ b/tests/headers/class_with_inner_struct.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash // bindgen-flags: -- -std=c++11 class A { diff --git a/tests/headers/class_with_typedef.hpp b/tests/headers/class_with_typedef.hpp index 8707cffefb..7abb6f772b 100644 --- a/tests/headers/class_with_typedef.hpp +++ b/tests/headers/class_with_typedef.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash typedef int AnotherInt; class C { From 8fa9cd9e613c1231a16e54e1d9a26b62b47c7819 Mon Sep 17 00:00:00 2001 From: Zhiting Zhu Date: Fri, 4 Aug 2017 10:49:56 -0700 Subject: [PATCH 05/12] Opaque related tests for derive Hash --- .../tests/issue-801-opaque-sloppiness.rs | 4 ++-- ...ssue-807-opaque-types-methods-being-generated.rs | 10 +++++----- tests/expectations/tests/jsval_layout_opaque.rs | 13 ++++++++----- .../tests/opaque-template-inst-member-2.rs | 10 +++++++--- .../tests/opaque-template-inst-member.rs | 6 +++++- .../opaque-template-instantiation-namespaced.rs | 10 +++++----- .../tests/opaque-template-instantiation.rs | 6 +++--- tests/expectations/tests/opaque-tracing.rs | 2 +- tests/expectations/tests/opaque_in_struct.rs | 4 ++-- tests/expectations/tests/opaque_pointer.rs | 6 +++--- tests/expectations/tests/opaque_typedef.rs | 2 +- tests/headers/issue-801-opaque-sloppiness.hpp | 2 +- ...sue-807-opaque-types-methods-being-generated.hpp | 2 +- tests/headers/jsval_layout_opaque.hpp | 1 + tests/headers/opaque-template-inst-member-2.hpp | 10 +++++----- tests/headers/opaque-template-inst-member.hpp | 10 +++++----- .../opaque-template-instantiation-namespaced.hpp | 2 +- tests/headers/opaque-template-instantiation.hpp | 2 +- tests/headers/opaque-tracing.hpp | 2 +- tests/headers/opaque_in_struct.hpp | 1 + tests/headers/opaque_pointer.hpp | 1 + tests/headers/opaque_typedef.hpp | 2 +- 22 files changed, 61 insertions(+), 47 deletions(-) diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs index 7a7afb8689..cd2c4fac0f 100644 --- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -10,7 +10,7 @@ pub struct A { _unused: [u8; 0], } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct B { pub _bindgen_opaque_blob: u8, } @@ -29,7 +29,7 @@ extern "C" { pub static mut B_a: A; } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct C { pub b: B, } diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index f22a9612d3..2826ec5d23 100644 --- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Pupper { pub _address: u8, } @@ -20,7 +20,7 @@ impl Clone for Pupper { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Doggo { pub _address: u8, } @@ -35,7 +35,7 @@ impl Clone for Doggo { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct SuchWow { pub _address: u8, } @@ -50,7 +50,7 @@ impl Clone for SuchWow { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Opaque { pub _bindgen_opaque_blob: u8, } @@ -89,7 +89,7 @@ extern "C" { pub static mut Opaque_MAJESTIC_AF: Doggo; } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Whitelisted { pub some_member: Opaque, } diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 980adbcf65..536d8c5973 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -28,6 +28,9 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47; pub const JSVAL_PAYLOAD_MASK: ::std::os::raw::c_ulonglong = 140737488355327; pub const JSVAL_TAG_MASK: ::std::os::raw::c_longlong = -140737488355328; @@ -96,7 +99,7 @@ pub enum JSWhyMagic { JS_WHY_MAGIC_COUNT = 18, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct jsval_layout { pub asBits: __BindgenUnionField, pub debugView: __BindgenUnionField, @@ -108,7 +111,7 @@ pub struct jsval_layout { pub bindgen_union_field: u64, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct jsval_layout__bindgen_ty_1 { pub _bitfield_1: u64, pub __bindgen_align: [u64; 0usize], @@ -214,12 +217,12 @@ impl jsval_layout__bindgen_ty_1 { } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct jsval_layout__bindgen_ty_2 { pub payload: jsval_layout__bindgen_ty_2__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub i32: __BindgenUnionField, pub u32: __BindgenUnionField, @@ -326,7 +329,7 @@ impl Clone for jsval_layout { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Value { pub data: jsval_layout, } diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index 65efefb2bc..8c098c8fd4 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -4,12 +4,15 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/// This is like `opaque-template-inst-member.hpp` except exercising the cases +/// where we are OK to derive Debug/Hash. #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct OpaqueTemplate { } +/// Should derive Debug/Hash. #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct ContainsOpaqueTemplate { pub mBlah: u32, pub mBaz: ::std::os::raw::c_int, @@ -36,8 +39,9 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { impl Clone for ContainsOpaqueTemplate { fn clone(&self) -> Self { *self } } +/// Should also derive Debug/Hash. #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct InheritsOpaqueTemplate { pub _base: u8, pub wow: *mut ::std::os::raw::c_char, diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index 9f0969cd09..11c3cc8400 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -5,9 +5,11 @@ #[repr(C)] -#[derive(Default, Copy, Clone)] +#[derive(Default, Copy, Clone, Hash)] pub struct OpaqueTemplate { } +/// 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)] pub struct ContainsOpaqueTemplate { pub mBlah: [u32; 101usize], @@ -35,6 +37,8 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { impl Default for ContainsOpaqueTemplate { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +/// This shold not end up deriving Debug/Hash either, for similar reasons, although +/// we're exercising base member edges now. #[repr(C)] pub struct InheritsOpaqueTemplate { pub _base: [u8; 401usize], diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 00c5582509..396edbd663 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -12,7 +12,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Copy, Clone)] + #[derive(Debug, Copy, Clone, Hash)] pub struct Template { pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -21,7 +21,7 @@ pub mod root { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Hash)] pub struct Foo { pub c: ::std::os::raw::c_char, } @@ -41,7 +41,7 @@ pub mod root { fn clone(&self) -> Self { *self } } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Hash)] pub struct Bar { pub i: ::std::os::raw::c_int, } @@ -61,7 +61,7 @@ pub mod root { fn clone(&self) -> Self { *self } } #[repr(C)] - #[derive(Debug, Copy)] + #[derive(Debug, Copy, Hash)] pub struct ContainsInstantiation { pub not_opaque: root::zoidberg::Template, } @@ -89,7 +89,7 @@ pub mod root { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] - #[derive(Debug, Default, Copy)] + #[derive(Debug, Default, Copy, Hash)] pub struct ContainsOpaqueInstantiation { pub opaque: u32, } diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index f3ef2a06da..aafe702fa3 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct Template { pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -14,7 +14,7 @@ impl Default for Template { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct ContainsInstantiation { pub not_opaque: Template<::std::os::raw::c_char>, } @@ -39,7 +39,7 @@ impl Default for ContainsInstantiation { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct ContainsOpaqueInstantiation { pub opaque: u32, } diff --git a/tests/expectations/tests/opaque-tracing.rs b/tests/expectations/tests/opaque-tracing.rs index fc91a6cebf..5113ccf308 100644 --- a/tests/expectations/tests/opaque-tracing.rs +++ b/tests/expectations/tests/opaque-tracing.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Container { pub _bindgen_opaque_blob: [u32; 2usize], } diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index d41cbf10a9..db85246a0c 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -6,7 +6,7 @@ ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct opaque { pub _bindgen_opaque_blob: u32, } @@ -21,7 +21,7 @@ impl Clone for opaque { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct container { pub contained: opaque, } diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index feb22439c6..2e566dc4f8 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -6,7 +6,7 @@ ///
#[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct OtherOpaque { pub _bindgen_opaque_blob: u32, } @@ -22,11 +22,11 @@ impl Clone for OtherOpaque { } ///
#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct Opaque { } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct WithOpaquePtr { pub whatever: *mut u8, pub other: u32, diff --git a/tests/expectations/tests/opaque_typedef.rs b/tests/expectations/tests/opaque_typedef.rs index a19a71acf3..53cf6f64eb 100644 --- a/tests/expectations/tests/opaque_typedef.rs +++ b/tests/expectations/tests/opaque_typedef.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct RandomTemplate { pub _address: u8, } diff --git a/tests/headers/issue-801-opaque-sloppiness.hpp b/tests/headers/issue-801-opaque-sloppiness.hpp index 503bba397e..275be02382 100644 --- a/tests/headers/issue-801-opaque-sloppiness.hpp +++ b/tests/headers/issue-801-opaque-sloppiness.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type "B" --whitelist-type "C" +// bindgen-flags: --opaque-type "B" --whitelist-type "C" --with-derive-hash class A; diff --git a/tests/headers/issue-807-opaque-types-methods-being-generated.hpp b/tests/headers/issue-807-opaque-types-methods-being-generated.hpp index bdb7cd533a..f21334278a 100644 --- a/tests/headers/issue-807-opaque-types-methods-being-generated.hpp +++ b/tests/headers/issue-807-opaque-types-methods-being-generated.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --whitelist-type Whitelisted --opaque-type Opaque -- -std=c++11 +// bindgen-flags: --whitelist-type Whitelisted --opaque-type Opaque --with-derive-hash -- -std=c++11 // These types are not explicitly whitelisted, but are reachable through the // opaque type. diff --git a/tests/headers/jsval_layout_opaque.hpp b/tests/headers/jsval_layout_opaque.hpp index 8f36f77ded..4a4f367b90 100644 --- a/tests/headers/jsval_layout_opaque.hpp +++ b/tests/headers/jsval_layout_opaque.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash // bindgen-flags: -- -std=c++11 /** diff --git a/tests/headers/opaque-template-inst-member-2.hpp b/tests/headers/opaque-template-inst-member-2.hpp index d4386f482c..9d31fa3122 100644 --- a/tests/headers/opaque-template-inst-member-2.hpp +++ b/tests/headers/opaque-template-inst-member-2.hpp @@ -1,20 +1,20 @@ -// bindgen-flags: --opaque-type 'OpaqueTemplate' +// bindgen-flags: --opaque-type 'OpaqueTemplate' --with-derive-hash -// This is like `opaque-template-inst-member.hpp` except exercising the cases -// where we are OK to derive Debug. +/// This is like `opaque-template-inst-member.hpp` except exercising the cases +/// where we are OK to derive Debug/Hash. template class OpaqueTemplate { T mData; }; -// Should derive Debug. +/// Should derive Debug/Hash. class ContainsOpaqueTemplate { OpaqueTemplate mBlah; int mBaz; }; -// Should also derive Debug. +/// Should also derive Debug/Hash. class InheritsOpaqueTemplate : public OpaqueTemplate { char* wow; }; diff --git a/tests/headers/opaque-template-inst-member.hpp b/tests/headers/opaque-template-inst-member.hpp index 7748007bcc..d5954144cc 100644 --- a/tests/headers/opaque-template-inst-member.hpp +++ b/tests/headers/opaque-template-inst-member.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type 'OpaqueTemplate' +// bindgen-flags: --opaque-type 'OpaqueTemplate' --with-derive-hash template class OpaqueTemplate { @@ -6,15 +6,15 @@ class OpaqueTemplate { bool mCannotDebug[400]; }; -// This should not end up deriving Debug because its `mBlah` field cannot derive -// Debug because the instantiation's definition cannot derive Debug. +/// 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. class ContainsOpaqueTemplate { OpaqueTemplate mBlah; int mBaz; }; -// This shold not end up deriving Debug either, for similar reasons, although -// we're exercising base member edges now. +/// This shold not end up deriving Debug/Hash either, for similar reasons, although +/// we're exercising base member edges now. class InheritsOpaqueTemplate : public OpaqueTemplate { char* wow; }; diff --git a/tests/headers/opaque-template-instantiation-namespaced.hpp b/tests/headers/opaque-template-instantiation-namespaced.hpp index 31fb0d523d..85513fdf2b 100644 --- a/tests/headers/opaque-template-instantiation-namespaced.hpp +++ b/tests/headers/opaque-template-instantiation-namespaced.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --opaque-type 'zoidberg::Template' -- -std=c++14 +// bindgen-flags: --enable-cxx-namespaces --opaque-type 'zoidberg::Template' --with-derive-hash -- -std=c++14 namespace zoidberg { diff --git a/tests/headers/opaque-template-instantiation.hpp b/tests/headers/opaque-template-instantiation.hpp index 7589b53c8d..fe29948df4 100644 --- a/tests/headers/opaque-template-instantiation.hpp +++ b/tests/headers/opaque-template-instantiation.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type 'Template' -- -std=c++14 +// bindgen-flags: --opaque-type 'Template' --with-derive-hash -- -std=c++14 template class Template { diff --git a/tests/headers/opaque-tracing.hpp b/tests/headers/opaque-tracing.hpp index 7356245e55..42ef3ccf58 100644 --- a/tests/headers/opaque-tracing.hpp +++ b/tests/headers/opaque-tracing.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type=.* --whitelist-function=foo +// bindgen-flags: --opaque-type=.* --whitelist-function=foo --with-derive-hash class Container; diff --git a/tests/headers/opaque_in_struct.hpp b/tests/headers/opaque_in_struct.hpp index 3cffeb200a..771b80bc73 100644 --- a/tests/headers/opaque_in_struct.hpp +++ b/tests/headers/opaque_in_struct.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash /**
*/ diff --git a/tests/headers/opaque_pointer.hpp b/tests/headers/opaque_pointer.hpp index 53f8ce1fa8..cc99df9950 100644 --- a/tests/headers/opaque_pointer.hpp +++ b/tests/headers/opaque_pointer.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash /** *
diff --git a/tests/headers/opaque_typedef.hpp b/tests/headers/opaque_typedef.hpp index 2564073857..f39f2fce0f 100644 --- a/tests/headers/opaque_typedef.hpp +++ b/tests/headers/opaque_typedef.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++11 +// bindgen-flags: --with-derive-hash -- -std=c++11 template class RandomTemplate; From 8d209f327432159cc2253068812073f594124d36 Mon Sep 17 00:00:00 2001 From: Zhiting Zhu Date: Fri, 4 Aug 2017 13:20:56 -0700 Subject: [PATCH 06/12] Function related tests for derive Hash --- tests/expectations/tests/derive-fn-ptr.rs | 36 +++++++++++++++++++ .../expectations/tests/func_ptr_in_struct.rs | 2 +- tests/headers/derive-fn-ptr.h | 10 ++++++ tests/headers/func_ptr.h | 2 ++ tests/headers/func_ptr_in_struct.h | 3 +- 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs index 1d9a480eae..fca1f4e56c 100644 --- a/tests/expectations/tests/derive-fn-ptr.rs +++ b/tests/expectations/tests/derive-fn-ptr.rs @@ -44,3 +44,39 @@ impl Clone for Foo { impl Default for Foo { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +pub type my_fun2_t = + ::std::option::Option; +#[repr(C)] +#[derive(Debug, Copy, Hash)] +pub struct Bar { + pub callback: my_fun2_t, +} +#[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 ) ) . callback as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( callback ) )); +} +impl Clone for Bar { + fn clone(&self) -> Self { *self } +} +impl Default for Bar { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index f52c56baaa..a855d8cf3f 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -7,7 +7,7 @@ #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum baz { } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct Foo { pub bar: ::std::option::Option Date: Fri, 4 Aug 2017 15:18:42 -0700 Subject: [PATCH 07/12] Complex float tests for derive Hash --- tests/expectations/tests/complex.rs | 4 ++-- tests/headers/complex.h | 1 + tests/headers/complex_global.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index 22eb92b83e..08d5d453e4 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -31,7 +31,7 @@ impl Clone for TestDouble { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct TestDoublePtr { pub mMember: *mut __BindgenComplex, } @@ -74,7 +74,7 @@ impl Clone for TestFloat { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct TestFloatPtr { pub mMember: *mut __BindgenComplex, } diff --git a/tests/headers/complex.h b/tests/headers/complex.h index 04877a4ee4..9696b6062d 100644 --- a/tests/headers/complex.h +++ b/tests/headers/complex.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash #define COMPLEX_TEST(ty_, name_) \ struct Test##name_ { \ diff --git a/tests/headers/complex_global.h b/tests/headers/complex_global.h index d9f9fb0163..7b9e887260 100644 --- a/tests/headers/complex_global.h +++ b/tests/headers/complex_global.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash float _Complex globalValueFloat; double _Complex globalValueDouble; long double _Complex globalValueLongDouble; From e358a00e88e5d69608dd0c4967a4e2e0c78f323f Mon Sep 17 00:00:00 2001 From: Zhiting Zhu Date: Fri, 4 Aug 2017 15:36:48 -0700 Subject: [PATCH 08/12] Anonymous related tests for derive Hash --- tests/expectations/tests/anon_enum_trait.rs | 4 ++-- tests/expectations/tests/anon_struct_in_union.rs | 9 ++++++--- tests/expectations/tests/anon_union.rs | 13 ++++++++----- tests/headers/anon_enum.hpp | 1 + tests/headers/anon_enum_trait.hpp | 1 + tests/headers/anon_struct_in_union.h | 1 + tests/headers/anon_union.hpp | 1 + 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index 699d49c2d7..38ed0268e0 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)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct DataType { pub _address: u8, } @@ -27,7 +27,7 @@ pub const DataType_type_: DataType__bindgen_ty_1 = #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum DataType__bindgen_ty_1 { generic_type = 0, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Foo { pub _address: u8, } diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index bfb100152d..b482031931 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -28,19 +28,22 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct s { pub u: s__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct s__bindgen_ty_1 { pub field: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct s__bindgen_ty_1_inner { pub b: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index 97cd40f5ad..71c2d4f706 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -28,8 +28,11 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct TErrorResult { pub mResult: ::std::os::raw::c_int, pub __bindgen_anon_1: TErrorResult__bindgen_ty_1, @@ -42,17 +45,17 @@ pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum TErrorResult_UnionState { HasMessage = 0, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct TErrorResult_Message { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct TErrorResult_DOMExceptionInfo { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct TErrorResult__bindgen_ty_1 { pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, @@ -62,7 +65,7 @@ impl Default for TErrorResult { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct ErrorResult { pub _base: TErrorResult, } diff --git a/tests/headers/anon_enum.hpp b/tests/headers/anon_enum.hpp index 1961fe6cf7..1a55a8d148 100644 --- a/tests/headers/anon_enum.hpp +++ b/tests/headers/anon_enum.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash struct Test { int foo; float bar; diff --git a/tests/headers/anon_enum_trait.hpp b/tests/headers/anon_enum_trait.hpp index e1ec394c30..22137392a8 100644 --- a/tests/headers/anon_enum_trait.hpp +++ b/tests/headers/anon_enum_trait.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash template class DataType { diff --git a/tests/headers/anon_struct_in_union.h b/tests/headers/anon_struct_in_union.h index 880a8b5453..2e6ac5e989 100644 --- a/tests/headers/anon_struct_in_union.h +++ b/tests/headers/anon_struct_in_union.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash struct s { union { struct inner { diff --git a/tests/headers/anon_union.hpp b/tests/headers/anon_union.hpp index 126f6a6ee3..26bb842f8f 100644 --- a/tests/headers/anon_union.hpp +++ b/tests/headers/anon_union.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash template struct TErrorResult { enum UnionState { From df820a20ca904268033a04506b8c96b416ad90ba Mon Sep 17 00:00:00 2001 From: Zhiting Zhu Date: Fri, 4 Aug 2017 15:54:53 -0700 Subject: [PATCH 09/12] Template related tests for derive Hash --- .../tests/anonymous-template-types.rs | 8 ++-- .../tests/empty_template_param_name.rs | 2 +- tests/expectations/tests/template-fun-ty.rs | 6 +-- tests/expectations/tests/template.rs | 42 +++++++++---------- tests/expectations/tests/template_alias.rs | 2 +- .../tests/template_alias_namespace.rs | 2 +- .../template_typedef_transitive_param.rs | 4 +- .../expectations/tests/templateref_opaque.rs | 4 +- tests/headers/anonymous-template-types.hpp | 2 +- tests/headers/empty_template_param_name.hpp | 1 + tests/headers/template-fun-ty.hpp | 1 + tests/headers/template.hpp | 2 +- tests/headers/template_alias.hpp | 2 +- tests/headers/template_alias_namespace.hpp | 2 +- .../template_typedef_transitive_param.hpp | 1 + tests/headers/templateref_opaque.hpp | 1 + 16 files changed, 43 insertions(+), 39 deletions(-) diff --git a/tests/expectations/tests/anonymous-template-types.rs b/tests/expectations/tests/anonymous-template-types.rs index 0f19d86e0c..6d231330b4 100644 --- a/tests/expectations/tests/anonymous-template-types.rs +++ b/tests/expectations/tests/anonymous-template-types.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct Foo { pub t_member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -14,12 +14,12 @@ impl Default for Foo { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct Bar { pub member: ::std::os::raw::c_char, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct Quux { pub v_member: V, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -28,7 +28,7 @@ impl Default for Quux { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct Lobo { pub also_member: ::std::os::raw::c_char, } diff --git a/tests/expectations/tests/empty_template_param_name.rs b/tests/expectations/tests/empty_template_param_name.rs index f182d9c269..07f27e54da 100644 --- a/tests/expectations/tests/empty_template_param_name.rs +++ b/tests/expectations/tests/empty_template_param_name.rs @@ -6,7 +6,7 @@ pub type __void_t = ::std::os::raw::c_void; #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct __iterator_traits { pub _address: u8, } diff --git a/tests/expectations/tests/template-fun-ty.rs b/tests/expectations/tests/template-fun-ty.rs index 30571266a1..a4c8ad440a 100644 --- a/tests/expectations/tests/template-fun-ty.rs +++ b/tests/expectations/tests/template-fun-ty.rs @@ -5,19 +5,19 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct Foo { pub _address: u8, } pub type Foo_FunctionPtr = ::std::option::Option T>; #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct RefPtr { pub _address: u8, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct RefPtr_Proxy { pub _address: u8, } diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index f1cc8a2509..141af8fac9 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -5,7 +5,7 @@ #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct Foo { pub m_member: T, pub m_member_ptr: *mut T, @@ -16,7 +16,7 @@ impl Default for Foo { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct B { pub m_member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -29,7 +29,7 @@ extern "C" { pub fn bar(foo: Foo<::std::os::raw::c_int>); } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct C { pub mB: B<::std::os::raw::c_uint>, pub mBConstPtr: B<*const ::std::os::raw::c_int>, @@ -87,13 +87,13 @@ impl Default for C { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct D { pub m_foo: D_MyFoo, } pub type D_MyFoo = Foo<::std::os::raw::c_int>; #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct D_U { pub m_nested_foo: D_MyFoo, pub m_baz: Z, @@ -106,7 +106,7 @@ impl Default for D { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct Rooted { pub prev: *mut T, pub next: *mut Rooted<*mut ::std::os::raw::c_void>, @@ -117,7 +117,7 @@ impl Default for Rooted { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct RootedContainer { pub root: Rooted<*mut ::std::os::raw::c_void>, } @@ -140,7 +140,7 @@ impl Default for RootedContainer { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct WithDtor { pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -150,7 +150,7 @@ impl Default for WithDtor { } pub type WithDtorIntFwd = WithDtor<::std::os::raw::c_int>; #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct PODButContainsDtor { pub member: WithDtorIntFwd, } @@ -171,11 +171,11 @@ impl Default for PODButContainsDtor { } ///
#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct Opaque { } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct POD { pub opaque_member: u32, } @@ -196,7 +196,7 @@ impl Clone for POD { } ///
#[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct NestedReplaced { pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -205,7 +205,7 @@ impl Default for NestedReplaced { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct NestedBase { pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -214,7 +214,7 @@ impl Default for NestedBase { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct Incomplete { pub d: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -223,7 +223,7 @@ impl Default for Incomplete { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct NestedContainer { pub c: T, pub nested: NestedReplaced, @@ -234,7 +234,7 @@ impl Default for NestedContainer { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Untemplated { pub _address: u8, } @@ -249,7 +249,7 @@ impl Clone for Untemplated { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct Templated { pub m_untemplated: Untemplated, } @@ -258,7 +258,7 @@ pub struct Templated { /// ///
#[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct ReplacedWithoutDestructor { pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -267,7 +267,7 @@ impl Default for ReplacedWithoutDestructor { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct ShouldNotBeCopiable { pub m_member: ReplacedWithoutDestructor, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -276,7 +276,7 @@ impl Default for ShouldNotBeCopiable { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct ShouldNotBeCopiableAsWell { pub m_member: ReplacedWithoutDestructorFwd, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -289,7 +289,7 @@ impl Default for ShouldNotBeCopiableAsWell { /// ///
#[repr(C)] -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct ReplacedWithoutDestructorFwd { pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, diff --git a/tests/expectations/tests/template_alias.rs b/tests/expectations/tests/template_alias.rs index a718e704b9..537fc3761f 100644 --- a/tests/expectations/tests/template_alias.rs +++ b/tests/expectations/tests/template_alias.rs @@ -6,7 +6,7 @@ pub type JS_detail_Wrapped = T; #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct JS_Rooted { pub ptr: JS_detail_Wrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, diff --git a/tests/expectations/tests/template_alias_namespace.rs b/tests/expectations/tests/template_alias_namespace.rs index 2fb88a8131..ba94dd7db2 100644 --- a/tests/expectations/tests/template_alias_namespace.rs +++ b/tests/expectations/tests/template_alias_namespace.rs @@ -17,7 +17,7 @@ pub mod root { pub type Wrapped = T; } #[repr(C)] - #[derive(Debug, Copy, Clone)] + #[derive(Debug, Copy, Clone, Hash)] pub struct Rooted { pub ptr: root::JS::detail::Wrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, diff --git a/tests/expectations/tests/template_typedef_transitive_param.rs b/tests/expectations/tests/template_typedef_transitive_param.rs index 05604223a0..6a0026fb6d 100644 --- a/tests/expectations/tests/template_typedef_transitive_param.rs +++ b/tests/expectations/tests/template_typedef_transitive_param.rs @@ -5,12 +5,12 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct Wrapper { pub _address: u8, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct Wrapper_Wrapped { pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, diff --git a/tests/expectations/tests/templateref_opaque.rs b/tests/expectations/tests/templateref_opaque.rs index 5f6a7459f8..a20dd69101 100644 --- a/tests/expectations/tests/templateref_opaque.rs +++ b/tests/expectations/tests/templateref_opaque.rs @@ -5,13 +5,13 @@ #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct detail_PointerType { pub _address: u8, } pub type detail_PointerType_Type = *mut T; #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct UniquePtr { pub _address: u8, } diff --git a/tests/headers/anonymous-template-types.hpp b/tests/headers/anonymous-template-types.hpp index 9ada71a908..34924fc943 100644 --- a/tests/headers/anonymous-template-types.hpp +++ b/tests/headers/anonymous-template-types.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++14 +// bindgen-flags: --with-derive-hash -- -std=c++14 template struct Foo { diff --git a/tests/headers/empty_template_param_name.hpp b/tests/headers/empty_template_param_name.hpp index 0e9f3c341f..ef212d5555 100644 --- a/tests/headers/empty_template_param_name.hpp +++ b/tests/headers/empty_template_param_name.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash // bindgen-flags: -- -std=c++11 template using __void_t = void; diff --git a/tests/headers/template-fun-ty.hpp b/tests/headers/template-fun-ty.hpp index 1e8e1c25f7..cc33fb74db 100644 --- a/tests/headers/template-fun-ty.hpp +++ b/tests/headers/template-fun-ty.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash template class Foo { diff --git a/tests/headers/template.hpp b/tests/headers/template.hpp index 168eac9c2d..c3dff4f74c 100644 --- a/tests/headers/template.hpp +++ b/tests/headers/template.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++11 +// bindgen-flags: --with-derive-hash -- -std=c++11 // template class Foo { T m_member; diff --git a/tests/headers/template_alias.hpp b/tests/headers/template_alias.hpp index 646d9f40fd..684bf286fc 100644 --- a/tests/headers/template_alias.hpp +++ b/tests/headers/template_alias.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++14 +// bindgen-flags: --with-derive-hash -- -std=c++14 namespace JS { namespace detail { diff --git a/tests/headers/template_alias_namespace.hpp b/tests/headers/template_alias_namespace.hpp index bd6371663a..b24e4bd383 100644 --- a/tests/headers/template_alias_namespace.hpp +++ b/tests/headers/template_alias_namespace.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces -- -std=c++14 +// bindgen-flags: --with-derive-hash --enable-cxx-namespaces -- -std=c++14 namespace JS { namespace detail { diff --git a/tests/headers/template_typedef_transitive_param.hpp b/tests/headers/template_typedef_transitive_param.hpp index 2269ac369e..2c50cda6f1 100644 --- a/tests/headers/template_typedef_transitive_param.hpp +++ b/tests/headers/template_typedef_transitive_param.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash template struct Wrapper { struct Wrapped { diff --git a/tests/headers/templateref_opaque.hpp b/tests/headers/templateref_opaque.hpp index ca154c34c9..1dcf4778f6 100644 --- a/tests/headers/templateref_opaque.hpp +++ b/tests/headers/templateref_opaque.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash namespace detail { template From e967d18c2c7465bd2f3432e4f39776ffa4f1f3ad Mon Sep 17 00:00:00 2001 From: Zhiting Zhu Date: Fri, 4 Aug 2017 17:53:35 -0700 Subject: [PATCH 10/12] Layout related tests for derive Hash --- .../issue-648-derive-debug-with-padding.rs | 6 +-- tests/expectations/tests/layout_array.rs | 6 +-- .../tests/layout_array_too_long.rs | 8 ++-- tests/expectations/tests/layout_eth_conf.rs | 39 ++++++++++--------- tests/expectations/tests/layout_mbuf.rs | 29 +++++++------- .../issue-648-derive-debug-with-padding.h | 7 ++-- tests/headers/layout_array.h | 1 + tests/headers/layout_array_too_long.h | 1 + tests/headers/layout_eth_conf.h | 3 +- tests/headers/layout_mbuf.h | 3 +- 10 files changed, 57 insertions(+), 46 deletions(-) diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index bcd5141efb..0e22eedfb2 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -5,7 +5,7 @@ /// We emit a `[u8; 63usize]` padding field for this struct, which cannot derive -/// Debug because 63 is over the hard coded limit. (Yes, this struct doesn't end +/// Debug/Hash because 63 is over the hard coded limit. (Yes, this struct doesn't end /// up with the reight alignment, we're waiting on `#[repr(align="N")]` to land /// in rustc). #[repr(C)] @@ -30,8 +30,8 @@ impl Clone for NoDebug { impl Default for NoDebug { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } -/// This should derive Debug because the padding size is less than the max derive -/// Debug impl for arrays. However, we conservatively don't derive Debug because +/// This should derive Debug/Hash because the padding size is less than the max derive +/// Debug/Hash impl for arrays. However, we conservatively don't derive Debug/Hash because /// we determine Debug derive-ability before we compute padding, which happens at /// codegen. (Again, we expect to get the alignment wrong for similar reasons.) #[repr(C)] diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index bccd5004a3..8ec289d429 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -106,7 +106,7 @@ impl Default for rte_mempool_ops { } /// The rte_spinlock_t type. #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_spinlock_t { /// < lock status 0 = unlocked, 1 = locked pub locked: ::std::os::raw::c_int, @@ -181,7 +181,7 @@ pub struct malloc_heap { pub total_size: usize, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct malloc_heap__bindgen_ty_1 { pub lh_first: *mut malloc_elem, } @@ -239,7 +239,7 @@ impl Default for malloc_heap { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct malloc_elem { pub _address: u8, } diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index 9c825625f5..6078e2cc23 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -20,7 +20,7 @@ pub enum _bindgen_ty_1 { } /// @internal fragmented mbuf #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct ip_frag { /// < offset into the packet pub ofs: u16, @@ -59,7 +59,7 @@ impl Default for ip_frag { } /// @internal to uniquely indetify fragmented datagram. #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct ip_frag_key { /// < src address, first 8 bytes used for IPv4 pub src_dst: [u64; 4usize], @@ -115,7 +115,7 @@ pub struct ip_frag_pkt { pub __bindgen_padding_0: [u64; 6usize], } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct ip_frag_pkt__bindgen_ty_1 { pub tqe_next: *mut ip_frag_pkt, pub tqe_prev: *mut *mut ip_frag_pkt, @@ -196,7 +196,7 @@ impl Default for ip_frag_pkt { } /// < fragment mbuf #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf { pub _address: u8, } diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index a51e40bceb..6cf37ac5dc 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -28,6 +28,9 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} pub const ETH_MQ_RX_RSS_FLAG: ::std::os::raw::c_uint = 1; pub const ETH_MQ_RX_DCB_FLAG: ::std::os::raw::c_uint = 2; pub const ETH_MQ_RX_VMDQ_FLAG: ::std::os::raw::c_uint = 4; @@ -76,7 +79,7 @@ pub enum rte_eth_rx_mq_mode { } /// A structure used to configure the RX features of an Ethernet port. #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_eth_rxmode { /// The multi-queue packet distribution mode to be used, e.g. RSS. pub mq_mode: rte_eth_rx_mq_mode, @@ -494,7 +497,7 @@ pub enum rte_eth_tx_mq_mode { } /// A structure used to configure the TX features of an Ethernet port. #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_eth_txmode { /// < TX multi-queues mode. pub mq_mode: rte_eth_tx_mq_mode, @@ -665,7 +668,7 @@ impl rte_eth_txmode { /// types of IPv4/IPv6 packets to which the RSS hashing must be applied. /// Supplying an *rss_hf* equal to zero disables the RSS feature. #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_eth_rss_conf { /// < If not NULL, 40-byte hash key. pub rss_key: *mut u8, @@ -742,7 +745,7 @@ pub struct rte_eth_vmdq_dcb_conf { pub dcb_tc: [u8; 8usize], } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { /// < The vlan id of the received frame pub vlan_id: u16, @@ -822,7 +825,7 @@ impl Default for rte_eth_vmdq_dcb_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_eth_dcb_rx_conf { /// < Possible DCB TCs, 4 or 8 TCs pub nb_tcs: rte_eth_nb_tcs, @@ -854,7 +857,7 @@ impl Default for rte_eth_dcb_rx_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_eth_vmdq_dcb_tx_conf { /// < With DCB, 16 or 32 pools. pub nb_queue_pools: rte_eth_nb_pools, @@ -888,7 +891,7 @@ impl Default for rte_eth_vmdq_dcb_tx_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_eth_dcb_tx_conf { /// < Possible DCB TCs, 4 or 8 TCs. pub nb_tcs: rte_eth_nb_tcs, @@ -920,7 +923,7 @@ impl Default for rte_eth_dcb_tx_conf { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_eth_vmdq_tx_conf { /// < VMDq mode, 64 pools. pub nb_queue_pools: rte_eth_nb_pools, @@ -963,7 +966,7 @@ pub struct rte_eth_vmdq_rx_conf { pub pool_map: [rte_eth_vmdq_rx_conf__bindgen_ty_1; 64usize], } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { /// < The vlan id of the received frame pub vlan_id: u16, @@ -1076,7 +1079,7 @@ pub enum rte_fdir_status_mode { } /// A structure used to define the input for IPV4 flow #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_eth_ipv4_flow { /// < IPv4 source address in big endian. pub src_ip: u32, @@ -1126,7 +1129,7 @@ impl Clone for rte_eth_ipv4_flow { } /// A structure used to define the input for IPV6 flow #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_eth_ipv6_flow { /// < IPv6 source address in big endian. pub src_ip: [u32; 4usize], @@ -1177,7 +1180,7 @@ impl Clone for rte_eth_ipv6_flow { /// A structure used to configure FDIR masks that are used by the device /// to match the various fields of RX packet headers. #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_eth_fdir_masks { /// < Bit mask for vlan_tci in big endian pub vlan_tci_mask: u16, @@ -1263,7 +1266,7 @@ pub enum rte_eth_payload_type { /// A structure used to select bytes extracted from the protocol layers to /// flexible payload for filter #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_eth_flex_payload_cfg { /// < Payload type pub type_: rte_eth_payload_type, @@ -1298,7 +1301,7 @@ impl Default for rte_eth_flex_payload_cfg { /// A structure used to define FDIR masks for flexible payload /// for each flow type #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_eth_fdir_flex_mask { pub flow_type: u16, pub mask: [u8; 16usize], @@ -1328,7 +1331,7 @@ impl Clone for rte_eth_fdir_flex_mask { /// A structure used to define all flexible payload related setting /// include flex payload and flex mask #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_eth_fdir_flex_conf { /// < The number of following payload cfg pub nb_payloads: u16, @@ -1377,7 +1380,7 @@ impl Default for rte_eth_fdir_flex_conf { /// /// If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct rte_fdir_conf { /// < Flow Director mode. pub mode: rte_fdir_mode, @@ -1435,7 +1438,7 @@ impl Default for rte_fdir_conf { } /// A structure used to enable/disable specific device interrupts. #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_intr_conf { /// enable/disable lsc interrupt. 0 (default) - disable, 1 enable pub lsc: u16, @@ -1548,7 +1551,7 @@ impl Default for rte_eth_conf__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_eth_conf__bindgen_ty_2 { pub vmdq_dcb_tx_conf: __BindgenUnionField, pub dcb_tx_conf: __BindgenUnionField, diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index 77198c3500..5e08af3c4b 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -28,6 +28,9 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} pub const RTE_CACHE_LINE_MIN_SIZE: ::std::os::raw::c_uint = 64; pub const RTE_CACHE_LINE_SIZE: ::std::os::raw::c_uint = 64; pub type phys_addr_t = u64; @@ -36,7 +39,7 @@ pub type MARKER8 = [u8; 0usize]; pub type MARKER64 = [u64; 0usize]; /// The atomic counter structure. #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_atomic16_t { /// < An internal counter value. pub cnt: i16, @@ -110,7 +113,7 @@ pub struct rte_mbuf { /// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC /// config option. #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_1 { /// < Atomically accessed refcnt pub refcnt_atomic: __BindgenUnionField, @@ -141,7 +144,7 @@ impl Clone for rte_mbuf__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_2 { /// < L2/L3/L4 and tunnel information. pub packet_type: __BindgenUnionField, @@ -149,7 +152,7 @@ pub struct rte_mbuf__bindgen_ty_2 { pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { pub _bitfield_1: [u8; 4usize], pub __bindgen_align: [u32; 0usize], @@ -472,7 +475,7 @@ impl Clone for rte_mbuf__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_3 { /// < RSS hash result if RSS enabled pub rss: __BindgenUnionField, @@ -485,20 +488,20 @@ pub struct rte_mbuf__bindgen_ty_3 { pub bindgen_union_field: [u32; 2usize], } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1 { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, pub hi: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { pub __bindgen_anon_1: __BindgenUnionField, pub lo: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { pub hash: u16, pub id: u16, @@ -582,7 +585,7 @@ impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { pub lo: u32, pub hi: u32, @@ -646,7 +649,7 @@ impl Clone for rte_mbuf__bindgen_ty_3 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_4 { /// < Can be used for external metadata pub userdata: __BindgenUnionField<*mut ::std::os::raw::c_void>, @@ -677,7 +680,7 @@ impl Clone for rte_mbuf__bindgen_ty_4 { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_5 { /// < combined for easy fetch pub tx_offload: __BindgenUnionField, @@ -685,7 +688,7 @@ pub struct rte_mbuf__bindgen_ty_5 { pub bindgen_union_field: u64, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { pub _bitfield_1: [u16; 4usize], pub __bindgen_align: [u64; 0usize], @@ -1082,7 +1085,7 @@ impl Default for rte_mbuf { } /// < Pool from which mbuf was allocated. #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_mempool { pub _address: u8, } diff --git a/tests/headers/issue-648-derive-debug-with-padding.h b/tests/headers/issue-648-derive-debug-with-padding.h index 2bd5927a00..fbe986789c 100644 --- a/tests/headers/issue-648-derive-debug-with-padding.h +++ b/tests/headers/issue-648-derive-debug-with-padding.h @@ -1,6 +1,7 @@ +// bindgen-flags: --with-derive-hash /** * We emit a `[u8; 63usize]` padding field for this struct, which cannot derive - * Debug because 63 is over the hard coded limit. (Yes, this struct doesn't end + * Debug/Hash because 63 is over the hard coded limit. (Yes, this struct doesn't end * up with the reight alignment, we're waiting on `#[repr(align="N")]` to land * in rustc). */ @@ -10,8 +11,8 @@ struct NoDebug { } __attribute__((__aligned__(64))); /** - * This should derive Debug because the padding size is less than the max derive - * Debug impl for arrays. However, we conservatively don't derive Debug because + * This should derive Debug/Hash because the padding size is less than the max derive + * Debug/Hash impl for arrays. However, we conservatively don't derive Debug/Hash because * we determine Debug derive-ability before we compute padding, which happens at * codegen. (Again, we expect to get the alignment wrong for similar reasons.) */ diff --git a/tests/headers/layout_array.h b/tests/headers/layout_array.h index 4b99e0ed42..fb071df686 100644 --- a/tests/headers/layout_array.h +++ b/tests/headers/layout_array.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/tests/headers/layout_array_too_long.h b/tests/headers/layout_array_too_long.h index 9be037abef..61f0c26921 100644 --- a/tests/headers/layout_array_too_long.h +++ b/tests/headers/layout_array_too_long.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/tests/headers/layout_eth_conf.h b/tests/headers/layout_eth_conf.h index a742ee5f99..7333f52801 100644 --- a/tests/headers/layout_eth_conf.h +++ b/tests/headers/layout_eth_conf.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; @@ -424,4 +425,4 @@ struct rte_eth_conf { uint32_t dcb_capability_en; struct rte_fdir_conf fdir_conf; /**< FDIR configuration. */ struct rte_intr_conf intr_conf; /**< Interrupt mode configuration. */ -}; \ No newline at end of file +}; diff --git a/tests/headers/layout_mbuf.h b/tests/headers/layout_mbuf.h index dc1c1b242b..9166bac792 100644 --- a/tests/headers/layout_mbuf.h +++ b/tests/headers/layout_mbuf.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash #define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */ @@ -184,4 +185,4 @@ struct rte_mbuf { /** Timesync flags for use with IEEE1588. */ uint16_t timesync; -} __rte_cache_aligned; \ No newline at end of file +} __rte_cache_aligned; From 3edb811aef594b8731ca2a4878a3fb2a6f3ae61b Mon Sep 17 00:00:00 2001 From: Zhiting Zhu Date: Fri, 4 Aug 2017 17:54:55 -0700 Subject: [PATCH 11/12] Misc tests for derive Hash --- tests/expectations/tests/16-byte-alignment.rs | 15 +++++++++------ tests/expectations/tests/char.rs | 2 +- tests/expectations/tests/issue-493.rs | 13 ++++++++----- tests/expectations/tests/typeref.rs | 15 +++++++++------ tests/expectations/tests/use-core.rs | 7 +++++-- tests/headers/16-byte-alignment.h | 1 + tests/headers/char.h | 2 ++ tests/headers/issue-493.hpp | 3 ++- tests/headers/typeref.hpp | 1 + tests/headers/use-core.h | 2 +- 10 files changed, 39 insertions(+), 22 deletions(-) diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index c60d69c3a8..1068f3f553 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -28,22 +28,25 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_ipv4_tuple { pub src_addr: u32, pub dst_addr: u32, pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_ipv4_tuple__bindgen_ty_1 { pub __bindgen_anon_1: __BindgenUnionField, pub sctp_tag: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, @@ -116,21 +119,21 @@ impl Clone for rte_ipv4_tuple { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_ipv6_tuple { pub src_addr: [u8; 16usize], pub dst_addr: [u8; 16usize], pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_ipv6_tuple__bindgen_ty_1 { pub __bindgen_anon_1: __BindgenUnionField, pub sctp_tag: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, diff --git a/tests/expectations/tests/char.rs b/tests/expectations/tests/char.rs index be92e54515..f34e075d5b 100644 --- a/tests/expectations/tests/char.rs +++ b/tests/expectations/tests/char.rs @@ -8,7 +8,7 @@ pub type Char = ::std::os::raw::c_char; pub type SChar = ::std::os::raw::c_schar; pub type UChar = ::std::os::raw::c_uchar; #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct Test { pub ch: ::std::os::raw::c_char, pub u: ::std::os::raw::c_uchar, diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index 89f03457cc..d25bb4a0fd 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -28,8 +28,11 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct basic_string { pub _address: u8, } @@ -37,7 +40,7 @@ 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)] +#[derive(Debug, Copy, Clone, Hash)] pub struct basic_string___long { pub __cap_: basic_string_size_type, pub __size_: basic_string_size_type, @@ -52,13 +55,13 @@ pub const basic_string___min_cap: basic_string__bindgen_ty_1 = #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_1 { __min_cap = 0, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] 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)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct basic_string___short__bindgen_ty_1 { pub __size_: __BindgenUnionField<::std::os::raw::c_uchar>, pub __lx: __BindgenUnionField, @@ -83,7 +86,7 @@ pub const basic_string___n_words: basic_string__bindgen_ty_2 = #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_2 { __n_words = 0, } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] pub struct basic_string___raw { pub __words: *mut basic_string_size_type, } diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 53119f090e..43427f08f5 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -28,8 +28,11 @@ impl ::std::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct nsFoo { pub mBar: mozilla_StyleShapeSource, } @@ -49,7 +52,7 @@ impl Clone for nsFoo { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct mozilla_FragmentOrURL { pub mIsLocalRef: bool, } @@ -71,7 +74,7 @@ impl Clone for mozilla_FragmentOrURL { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct mozilla_Position { pub _address: u8, } @@ -86,19 +89,19 @@ impl Clone for mozilla_Position { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct mozilla_StyleShapeSource { pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1, } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, Hash)] pub struct mozilla_StyleShapeSource__bindgen_ty_1 { pub mPosition: __BindgenUnionField<*mut mozilla_Position>, pub mFragmentOrURL: __BindgenUnionField<*mut mozilla_FragmentOrURL>, pub bindgen_union_field: u64, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct Bar { pub mFoo: *mut nsFoo, } diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index 14ac137385..fd89783f8a 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -29,8 +29,11 @@ impl ::core::fmt::Debug for __BindgenUnionField { fmt.write_str("__BindgenUnionField") } } +impl ::core::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) { } +} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Hash)] pub struct foo { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, @@ -65,7 +68,7 @@ impl Default for foo { fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Hash)] pub struct _bindgen_ty_1 { pub bar: __BindgenUnionField<::std::os::raw::c_int>, pub baz: __BindgenUnionField<::std::os::raw::c_long>, diff --git a/tests/headers/16-byte-alignment.h b/tests/headers/16-byte-alignment.h index 7a7f7548eb..cca4d285ab 100644 --- a/tests/headers/16-byte-alignment.h +++ b/tests/headers/16-byte-alignment.h @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash typedef unsigned char uint8_t; typedef unsigned short uint16_t; diff --git a/tests/headers/char.h b/tests/headers/char.h index ae38653ed1..8db9ccf057 100644 --- a/tests/headers/char.h +++ b/tests/headers/char.h @@ -1,3 +1,5 @@ +// bindgen-flags: --with-derive-hash +// typedef char Char; typedef signed char SChar; typedef unsigned char UChar; diff --git a/tests/headers/issue-493.hpp b/tests/headers/issue-493.hpp index 975ef5ceea..ea39c83c8d 100644 --- a/tests/headers/issue-493.hpp +++ b/tests/headers/issue-493.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash template class basic_string { @@ -44,4 +45,4 @@ class basic_string __raw __r; }; }; -}; \ No newline at end of file +}; diff --git a/tests/headers/typeref.hpp b/tests/headers/typeref.hpp index b94c98ef6b..c417bdb65b 100644 --- a/tests/headers/typeref.hpp +++ b/tests/headers/typeref.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --with-derive-hash struct nsFoo; namespace mozilla { diff --git a/tests/headers/use-core.h b/tests/headers/use-core.h index 0e8a8d6e5d..b34a71e77c 100644 --- a/tests/headers/use-core.h +++ b/tests/headers/use-core.h @@ -1,4 +1,4 @@ -// bindgen-flags: --use-core --raw-line "extern crate core;" +// bindgen-flags: --use-core --raw-line "extern crate core;" --with-derive-hash struct foo { int a, b; From b4895d96698504dc28dfa64c4c4e4c3f3714a3c8 Mon Sep 17 00:00:00 2001 From: Zhiting Zhu Date: Tue, 8 Aug 2017 16:06:26 -0700 Subject: [PATCH 12/12] Small dedicated tests for derive Hash --- .../struct_with_anon_struct_array_float.rs | 0 .../tests/derive-hash-blacklisting.rs | 56 +++++++++++ ...rive-hash-struct-with-anon-struct-float.rs | 53 ++++++++++ .../derive-hash-struct-with-float-array.rs | 27 +++++ .../tests/derive-hash-struct-with-pointer.rs | 99 +++++++++++++++++++ .../tests/derive-hash-template-def-float.rs | 17 ++++ .../tests/derive-hash-template-inst-float.rs | 84 ++++++++++++++++ tests/headers/derive-hash-blacklisting.hpp | 17 ++++ ...erive-hash-struct-with-anon-struct-float.h | 9 ++ .../derive-hash-struct-with-float-array.h | 6 ++ .../headers/derive-hash-struct-with-pointer.h | 18 ++++ .../derive-hash-template-def-float.hpp | 8 ++ .../derive-hash-template-inst-float.hpp | 17 ++++ 13 files changed, 411 insertions(+) create mode 100644 tests/expectations/struct_with_anon_struct_array_float.rs create mode 100644 tests/expectations/tests/derive-hash-blacklisting.rs create mode 100644 tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs create mode 100644 tests/expectations/tests/derive-hash-struct-with-float-array.rs create mode 100644 tests/expectations/tests/derive-hash-struct-with-pointer.rs create mode 100644 tests/expectations/tests/derive-hash-template-def-float.rs create mode 100644 tests/expectations/tests/derive-hash-template-inst-float.rs create mode 100644 tests/headers/derive-hash-blacklisting.hpp create mode 100644 tests/headers/derive-hash-struct-with-anon-struct-float.h create mode 100644 tests/headers/derive-hash-struct-with-float-array.h create mode 100644 tests/headers/derive-hash-struct-with-pointer.h create mode 100644 tests/headers/derive-hash-template-def-float.hpp create mode 100644 tests/headers/derive-hash-template-inst-float.hpp diff --git a/tests/expectations/struct_with_anon_struct_array_float.rs b/tests/expectations/struct_with_anon_struct_array_float.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expectations/tests/derive-hash-blacklisting.rs b/tests/expectations/tests/derive-hash-blacklisting.rs new file mode 100644 index 0000000000..c345d1aa4a --- /dev/null +++ b/tests/expectations/tests/derive-hash-blacklisting.rs @@ -0,0 +1,56 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + +#[repr(C)] #[derive(Debug, Hash, Copy, Clone)] pub struct Blacklisted {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell> } + +/// This would derive(Hash) if it didn't contain a blacklisted type, +/// causing us to conservatively avoid deriving hash for it. +#[repr(C)] +#[derive(Debug, Copy)] +pub struct WhitelistedOne { + pub a: Blacklisted<::std::os::raw::c_int>, +} +#[test] +fn bindgen_test_layout_WhitelistedOne() { + assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( + "Size of: " , stringify ! ( WhitelistedOne ) )); + assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( + "Alignment of " , stringify ! ( WhitelistedOne ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WhitelistedOne ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WhitelistedOne ) , "::" + , stringify ! ( a ) )); +} +impl Clone for WhitelistedOne { + fn clone(&self) -> Self { *self } +} +impl Default for WhitelistedOne { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +/// This can't derive(Hash) even if it didn't contain a blacklisted type. +#[repr(C)] +#[derive(Debug, Copy)] +pub struct WhitelistedTwo { + pub b: Blacklisted, +} +#[test] +fn bindgen_test_layout_WhitelistedTwo() { + assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( + "Size of: " , stringify ! ( WhitelistedTwo ) )); + assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( + "Alignment of " , stringify ! ( WhitelistedTwo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WhitelistedTwo ) ) . b as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WhitelistedTwo ) , "::" + , stringify ! ( b ) )); +} +impl Clone for WhitelistedTwo { + fn clone(&self) -> Self { *self } +} +impl Default for WhitelistedTwo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs new file mode 100644 index 0000000000..051a3636ff --- /dev/null +++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -0,0 +1,53 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +/// A struct containing a struct containing a float that cannot derive hash. +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct foo { + pub bar: foo__bindgen_ty_1, +} +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct foo__bindgen_ty_1 { + pub a: f32, + pub b: f32, +} +#[test] +fn bindgen_test_layout_foo__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::() , 8usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); +} +impl Clone for foo__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); +} +impl Clone for foo { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs new file mode 100644 index 0000000000..bb4a6b5d17 --- /dev/null +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -0,0 +1,27 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +/// A struct containing an array of floats that cannot derive hash. +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct foo { + pub bar: [f32; 3usize], +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!(::std::mem::size_of::() , 12usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); +} +impl Clone for foo { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs new file mode 100644 index 0000000000..007fd2f95e --- /dev/null +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -0,0 +1,99 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +/// Pointers can derive hash +#[repr(C)] +#[derive(Debug, Copy, Hash)] +pub struct ConstPtrMutObj { + pub bar: *const ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_ConstPtrMutObj() { + assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( + "Size of: " , stringify ! ( ConstPtrMutObj ) )); + assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( + "Alignment of " , stringify ! ( ConstPtrMutObj ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ConstPtrMutObj ) ) . bar as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ConstPtrMutObj ) , "::" + , stringify ! ( bar ) )); +} +impl Clone for ConstPtrMutObj { + fn clone(&self) -> Self { *self } +} +impl Default for ConstPtrMutObj { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +#[repr(C)] +#[derive(Debug, Copy, Hash)] +pub struct MutPtrMutObj { + pub bar: *mut ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_MutPtrMutObj() { + assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( + "Size of: " , stringify ! ( MutPtrMutObj ) )); + assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( + "Alignment of " , stringify ! ( MutPtrMutObj ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const MutPtrMutObj ) ) . bar as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( MutPtrMutObj ) , "::" , + stringify ! ( bar ) )); +} +impl Clone for MutPtrMutObj { + fn clone(&self) -> Self { *self } +} +impl Default for MutPtrMutObj { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +#[repr(C)] +#[derive(Debug, Copy, Hash)] +pub struct MutPtrConstObj { + pub bar: *const ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_MutPtrConstObj() { + assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( + "Size of: " , stringify ! ( MutPtrConstObj ) )); + assert_eq! (::std::mem::align_of::() , 8usize , concat ! ( + "Alignment of " , stringify ! ( MutPtrConstObj ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const MutPtrConstObj ) ) . bar as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( MutPtrConstObj ) , "::" + , stringify ! ( bar ) )); +} +impl Clone for MutPtrConstObj { + fn clone(&self) -> Self { *self } +} +impl Default for MutPtrConstObj { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +#[repr(C)] +#[derive(Debug, Copy, Hash)] +pub struct ConstPtrConstObj { + pub bar: *const ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_ConstPtrConstObj() { + assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( + "Size of: " , stringify ! ( ConstPtrConstObj ) )); + assert_eq! (::std::mem::align_of::() , 8usize , concat ! + ( "Alignment of " , stringify ! ( ConstPtrConstObj ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ConstPtrConstObj ) ) . bar as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ConstPtrConstObj ) , + "::" , stringify ! ( bar ) )); +} +impl Clone for ConstPtrConstObj { + fn clone(&self) -> Self { *self } +} +impl Default for ConstPtrConstObj { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/derive-hash-template-def-float.rs b/tests/expectations/tests/derive-hash-template-def-float.rs new file mode 100644 index 0000000000..e1d7836c11 --- /dev/null +++ b/tests/expectations/tests/derive-hash-template-def-float.rs @@ -0,0 +1,17 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +/// Template definition containing a float, which cannot derive hash. +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct foo { + pub data: T, + pub b: f32, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for foo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs new file mode 100644 index 0000000000..dd18053f2a --- /dev/null +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -0,0 +1,84 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +/// Template definition that doesn't contain float can derive hash +#[repr(C)] +#[derive(Debug, Copy, Clone, Hash)] +pub struct foo { + pub data: T, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for foo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +/// Can derive hash when instantiated with int +#[repr(C)] +#[derive(Debug, Copy, Hash)] +pub struct IntStr { + pub a: foo<::std::os::raw::c_int>, +} +#[test] +fn bindgen_test_layout_IntStr() { + assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( + "Size of: " , stringify ! ( IntStr ) )); + assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( + "Alignment of " , stringify ! ( IntStr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const IntStr ) ) . a as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( IntStr ) , "::" , + stringify ! ( a ) )); +} +impl Clone for IntStr { + fn clone(&self) -> Self { *self } +} +impl Default for IntStr { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +/// Cannot derive hash when instantiated with float +#[repr(C)] +#[derive(Debug, Copy)] +pub struct FloatStr { + pub a: foo, +} +#[test] +fn bindgen_test_layout_FloatStr() { + assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( + "Size of: " , stringify ! ( FloatStr ) )); + assert_eq! (::std::mem::align_of::() , 4usize , concat ! ( + "Alignment of " , stringify ! ( FloatStr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FloatStr ) ) . a as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( FloatStr ) , "::" , + stringify ! ( a ) )); +} +impl Clone for FloatStr { + fn clone(&self) -> Self { *self } +} +impl Default for FloatStr { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +#[test] +fn __bindgen_test_layout_foo_open0_int_close0_instantiation() { + assert_eq!(::std::mem::size_of::>() , 4usize , + concat ! ( + "Size of template specialization: " , stringify ! ( + foo<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::>() , 4usize , + concat ! ( + "Alignment of template specialization: " , stringify ! ( + foo<::std::os::raw::c_int> ) )); +} +#[test] +fn __bindgen_test_layout_foo_open0_float_close0_instantiation() { + assert_eq!(::std::mem::size_of::>() , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( foo ) + )); + assert_eq!(::std::mem::align_of::>() , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + foo ) )); +} diff --git a/tests/headers/derive-hash-blacklisting.hpp b/tests/headers/derive-hash-blacklisting.hpp new file mode 100644 index 0000000000..ee819c1753 --- /dev/null +++ b/tests/headers/derive-hash-blacklisting.hpp @@ -0,0 +1,17 @@ +// bindgen-flags: --with-derive-hash --whitelist-type 'Whitelisted.*' --blacklist-type Blacklisted --raw-line "#[repr(C)] #[derive(Debug, Hash, Copy, Clone)] pub struct Blacklisted {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell> }" +// +template +struct Blacklisted { + T t; +}; + +/// This would derive(Hash) if it didn't contain a blacklisted type, +/// causing us to conservatively avoid deriving hash for it. +struct WhitelistedOne { + Blacklisted a; +}; + +/// This can't derive(Hash) even if it didn't contain a blacklisted type. +struct WhitelistedTwo { + Blacklisted b; +}; diff --git a/tests/headers/derive-hash-struct-with-anon-struct-float.h b/tests/headers/derive-hash-struct-with-anon-struct-float.h new file mode 100644 index 0000000000..2b76cd2371 --- /dev/null +++ b/tests/headers/derive-hash-struct-with-anon-struct-float.h @@ -0,0 +1,9 @@ +// bindgen-flags: --with-derive-hash +// +/// A struct containing a struct containing a float that cannot derive hash. +struct foo { + struct { + float a; + float b; + } bar; +}; diff --git a/tests/headers/derive-hash-struct-with-float-array.h b/tests/headers/derive-hash-struct-with-float-array.h new file mode 100644 index 0000000000..53f0c79da5 --- /dev/null +++ b/tests/headers/derive-hash-struct-with-float-array.h @@ -0,0 +1,6 @@ +// bindgen-flags: --with-derive-hash +// +/// A struct containing an array of floats that cannot derive hash. +struct foo { + float bar[3]; +}; diff --git a/tests/headers/derive-hash-struct-with-pointer.h b/tests/headers/derive-hash-struct-with-pointer.h new file mode 100644 index 0000000000..262b6fb4e9 --- /dev/null +++ b/tests/headers/derive-hash-struct-with-pointer.h @@ -0,0 +1,18 @@ +// bindgen-flags: --with-derive-hash +// +/// Pointers can derive hash +struct ConstPtrMutObj { + int* const bar; +}; + +struct MutPtrMutObj { + int* bar; +}; + +struct MutPtrConstObj { + const int* bar; +}; + +struct ConstPtrConstObj { + const int* const bar; +}; diff --git a/tests/headers/derive-hash-template-def-float.hpp b/tests/headers/derive-hash-template-def-float.hpp new file mode 100644 index 0000000000..28885ed109 --- /dev/null +++ b/tests/headers/derive-hash-template-def-float.hpp @@ -0,0 +1,8 @@ +// bindgen-flags: --with-derive-hash +// +/// Template definition containing a float, which cannot derive hash. +template +struct foo { + T data; + float b; +}; diff --git a/tests/headers/derive-hash-template-inst-float.hpp b/tests/headers/derive-hash-template-inst-float.hpp new file mode 100644 index 0000000000..59af69bd89 --- /dev/null +++ b/tests/headers/derive-hash-template-inst-float.hpp @@ -0,0 +1,17 @@ +// bindgen-flags: --with-derive-hash +// +/// Template definition that doesn't contain float can derive hash +template +struct foo { + T data; +}; + +/// Can derive hash when instantiated with int +struct IntStr { + foo a; +}; + +/// Cannot derive hash when instantiated with float +struct FloatStr { + foo a; +};