summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/codegen/mod.rs19
-rw-r--r--src/ir/analysis/derive_hash.rs337
-rw-r--r--src/ir/analysis/mod.rs2
-rw-r--r--src/ir/context.rs38
-rw-r--r--src/ir/derive.rs27
-rw-r--r--src/ir/function.rs19
-rw-r--r--src/ir/item.rs8
-rw-r--r--src/ir/layout.rs11
-rw-r--r--src/lib.rs15
-rw-r--r--src/options.rs7
-rw-r--r--tests/expectations/struct_with_anon_struct_array_float.rs0
-rw-r--r--tests/expectations/tests/16-byte-alignment.rs15
-rw-r--r--tests/expectations/tests/anon_enum_trait.rs4
-rw-r--r--tests/expectations/tests/anon_struct_in_union.rs9
-rw-r--r--tests/expectations/tests/anon_union.rs13
-rw-r--r--tests/expectations/tests/anonymous-template-types.rs8
-rw-r--r--tests/expectations/tests/char.rs2
-rw-r--r--tests/expectations/tests/class.rs11
-rw-r--r--tests/expectations/tests/class_nested.rs14
-rw-r--r--tests/expectations/tests/class_no_members.rs6
-rw-r--r--tests/expectations/tests/class_static.rs2
-rw-r--r--tests/expectations/tests/class_static_const.rs2
-rw-r--r--tests/expectations/tests/class_use_as.rs4
-rw-r--r--tests/expectations/tests/class_with_dtor.rs4
-rw-r--r--tests/expectations/tests/class_with_inner_struct.rs23
-rw-r--r--tests/expectations/tests/class_with_typedef.rs4
-rw-r--r--tests/expectations/tests/complex.rs4
-rw-r--r--tests/expectations/tests/derive-fn-ptr.rs36
-rw-r--r--tests/expectations/tests/derive-hash-blacklisting.rs56
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs53
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-float-array.rs27
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-pointer.rs99
-rw-r--r--tests/expectations/tests/derive-hash-template-def-float.rs17
-rw-r--r--tests/expectations/tests/derive-hash-template-inst-float.rs84
-rw-r--r--tests/expectations/tests/empty_template_param_name.rs2
-rw-r--r--tests/expectations/tests/func_ptr_in_struct.rs2
-rw-r--r--tests/expectations/tests/issue-493.rs13
-rw-r--r--tests/expectations/tests/issue-648-derive-debug-with-padding.rs6
-rw-r--r--tests/expectations/tests/issue-801-opaque-sloppiness.rs4
-rw-r--r--tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs10
-rw-r--r--tests/expectations/tests/jsval_layout_opaque.rs13
-rw-r--r--tests/expectations/tests/layout_array.rs6
-rw-r--r--tests/expectations/tests/layout_array_too_long.rs8
-rw-r--r--tests/expectations/tests/layout_eth_conf.rs39
-rw-r--r--tests/expectations/tests/layout_mbuf.rs29
-rw-r--r--tests/expectations/tests/opaque-template-inst-member-2.rs10
-rw-r--r--tests/expectations/tests/opaque-template-inst-member.rs6
-rw-r--r--tests/expectations/tests/opaque-template-instantiation-namespaced.rs10
-rw-r--r--tests/expectations/tests/opaque-template-instantiation.rs6
-rw-r--r--tests/expectations/tests/opaque-tracing.rs2
-rw-r--r--tests/expectations/tests/opaque_in_struct.rs4
-rw-r--r--tests/expectations/tests/opaque_pointer.rs6
-rw-r--r--tests/expectations/tests/opaque_typedef.rs2
-rw-r--r--tests/expectations/tests/struct_containing_forward_declared_struct.rs4
-rw-r--r--tests/expectations/tests/struct_typedef.rs4
-rw-r--r--tests/expectations/tests/struct_typedef_ns.rs4
-rw-r--r--tests/expectations/tests/struct_with_anon_struct.rs4
-rw-r--r--tests/expectations/tests/struct_with_anon_struct_array.rs6
-rw-r--r--tests/expectations/tests/struct_with_anon_struct_pointer.rs4
-rw-r--r--tests/expectations/tests/struct_with_anon_union.rs7
-rw-r--r--tests/expectations/tests/struct_with_anon_unnamed_struct.rs4
-rw-r--r--tests/expectations/tests/struct_with_anon_unnamed_union.rs7
-rw-r--r--tests/expectations/tests/struct_with_bitfields.rs2
-rw-r--r--tests/expectations/tests/struct_with_derive_debug.rs4
-rw-r--r--tests/expectations/tests/struct_with_nesting.rs11
-rw-r--r--tests/expectations/tests/struct_with_packing.rs2
-rw-r--r--tests/expectations/tests/struct_with_struct.rs4
-rw-r--r--tests/expectations/tests/struct_with_typedef_template_arg.rs2
-rw-r--r--tests/expectations/tests/template-fun-ty.rs6
-rw-r--r--tests/expectations/tests/template.rs42
-rw-r--r--tests/expectations/tests/template_alias.rs2
-rw-r--r--tests/expectations/tests/template_alias_namespace.rs2
-rw-r--r--tests/expectations/tests/template_typedef_transitive_param.rs4
-rw-r--r--tests/expectations/tests/templateref_opaque.rs4
-rw-r--r--tests/expectations/tests/typeref.rs15
-rw-r--r--tests/expectations/tests/union-in-ns.rs3
-rw-r--r--tests/expectations/tests/union_dtor.rs3
-rw-r--r--tests/expectations/tests/union_fields.rs5
-rw-r--r--tests/expectations/tests/union_template.rs11
-rw-r--r--tests/expectations/tests/union_with_anon_struct.rs7
-rw-r--r--tests/expectations/tests/union_with_anon_struct_bitfield.rs7
-rw-r--r--tests/expectations/tests/union_with_anon_union.rs7
-rw-r--r--tests/expectations/tests/union_with_anon_unnamed_struct.rs7
-rw-r--r--tests/expectations/tests/union_with_anon_unnamed_union.rs7
-rw-r--r--tests/expectations/tests/union_with_big_member.rs5
-rw-r--r--tests/expectations/tests/union_with_nesting.rs11
-rw-r--r--tests/expectations/tests/use-core.rs7
-rw-r--r--tests/headers/16-byte-alignment.h1
-rw-r--r--tests/headers/anon_enum.hpp1
-rw-r--r--tests/headers/anon_enum_trait.hpp1
-rw-r--r--tests/headers/anon_struct_in_union.h1
-rw-r--r--tests/headers/anon_union.hpp1
-rw-r--r--tests/headers/anonymous-template-types.hpp2
-rw-r--r--tests/headers/char.h2
-rw-r--r--tests/headers/class.hpp2
-rw-r--r--tests/headers/class_nested.hpp1
-rw-r--r--tests/headers/class_no_members.hpp1
-rw-r--r--tests/headers/class_static.hpp1
-rw-r--r--tests/headers/class_static_const.hpp1
-rw-r--r--tests/headers/class_use_as.hpp1
-rw-r--r--tests/headers/class_with_dtor.hpp1
-rw-r--r--tests/headers/class_with_inner_struct.hpp1
-rw-r--r--tests/headers/class_with_typedef.hpp1
-rw-r--r--tests/headers/complex.h1
-rw-r--r--tests/headers/complex_global.h1
-rw-r--r--tests/headers/derive-fn-ptr.h10
-rw-r--r--tests/headers/derive-hash-blacklisting.hpp17
-rw-r--r--tests/headers/derive-hash-struct-with-anon-struct-float.h9
-rw-r--r--tests/headers/derive-hash-struct-with-float-array.h6
-rw-r--r--tests/headers/derive-hash-struct-with-pointer.h18
-rw-r--r--tests/headers/derive-hash-template-def-float.hpp8
-rw-r--r--tests/headers/derive-hash-template-inst-float.hpp17
-rw-r--r--tests/headers/empty_template_param_name.hpp1
-rw-r--r--tests/headers/func_ptr.h2
-rw-r--r--tests/headers/func_ptr_in_struct.h3
-rw-r--r--tests/headers/issue-493.hpp3
-rw-r--r--tests/headers/issue-648-derive-debug-with-padding.h7
-rw-r--r--tests/headers/issue-801-opaque-sloppiness.hpp2
-rw-r--r--tests/headers/issue-807-opaque-types-methods-being-generated.hpp2
-rw-r--r--tests/headers/jsval_layout_opaque.hpp1
-rw-r--r--tests/headers/layout_array.h1
-rw-r--r--tests/headers/layout_array_too_long.h1
-rw-r--r--tests/headers/layout_eth_conf.h3
-rw-r--r--tests/headers/layout_mbuf.h3
-rw-r--r--tests/headers/opaque-template-inst-member-2.hpp10
-rw-r--r--tests/headers/opaque-template-inst-member.hpp10
-rw-r--r--tests/headers/opaque-template-instantiation-namespaced.hpp2
-rw-r--r--tests/headers/opaque-template-instantiation.hpp2
-rw-r--r--tests/headers/opaque-tracing.hpp2
-rw-r--r--tests/headers/opaque_in_struct.hpp1
-rw-r--r--tests/headers/opaque_pointer.hpp1
-rw-r--r--tests/headers/opaque_typedef.hpp2
-rw-r--r--tests/headers/struct_containing_forward_declared_struct.h1
-rw-r--r--tests/headers/struct_typedef.h2
-rw-r--r--tests/headers/struct_typedef_ns.hpp2
-rw-r--r--tests/headers/struct_with_anon_struct.h2
-rw-r--r--tests/headers/struct_with_anon_struct_array.h2
-rw-r--r--tests/headers/struct_with_anon_struct_pointer.h1
-rw-r--r--tests/headers/struct_with_anon_union.h2
-rw-r--r--tests/headers/struct_with_anon_unnamed_struct.h1
-rw-r--r--tests/headers/struct_with_anon_unnamed_union.h1
-rw-r--r--tests/headers/struct_with_bitfields.h2
-rw-r--r--tests/headers/struct_with_derive_debug.h2
-rw-r--r--tests/headers/struct_with_large_array.hpp2
-rw-r--r--tests/headers/struct_with_nesting.h2
-rw-r--r--tests/headers/struct_with_packing.h2
-rw-r--r--tests/headers/struct_with_struct.h2
-rw-r--r--tests/headers/struct_with_typedef_template_arg.hpp1
-rw-r--r--tests/headers/template-fun-ty.hpp1
-rw-r--r--tests/headers/template.hpp2
-rw-r--r--tests/headers/template_alias.hpp2
-rw-r--r--tests/headers/template_alias_namespace.hpp2
-rw-r--r--tests/headers/template_typedef_transitive_param.hpp1
-rw-r--r--tests/headers/templateref_opaque.hpp1
-rw-r--r--tests/headers/typeref.hpp1
-rw-r--r--tests/headers/union_fields.hpp2
-rw-r--r--tests/headers/union_template.hpp2
-rw-r--r--tests/headers/union_with_anon_struct.h2
-rw-r--r--tests/headers/union_with_anon_struct_bitfield.h2
-rw-r--r--tests/headers/union_with_anon_union.h2
-rw-r--r--tests/headers/union_with_anon_unnamed_struct.h2
-rw-r--r--tests/headers/union_with_anon_unnamed_union.h2
-rw-r--r--tests/headers/union_with_big_member.h2
-rw-r--r--tests/headers/union_with_nesting.h2
-rw-r--r--tests/headers/use-core.h2
165 files changed, 1344 insertions, 260 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 5c00a53d..9521fb1e 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<T> ::$prefix::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::$prefix::hash::Hasher>(&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 00000000..2456143c
--- /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<ItemId>,
+
+ // Dependencies saying that if a key ItemId has been inserted into the
+ // `cannot_derive_hash` set, then each of the ids in Vec<ItemId> 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<ItemId, Vec<ItemId>>,
+}
+
+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<ItemId>;
+
+ 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<ItemId> {
+ 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<F>(&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<CannotDeriveHash<'ctx, 'gen>> for HashSet<ItemId> {
+ 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 f77c0886..28ca09aa 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 2e0899ed..5caebeda 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<HashSet<ItemId>>,
+ /// 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<HashSet<ItemId>>,
+
/// 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::<CannotDeriveCopy>(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::<CannotDeriveHash>(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 6d8c2c87..128ef9f2 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 99ab8772..20c026a4 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 a17f26fb..237618c8 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 9ec04d20..bac664f1 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 3a853829..bb42117d 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 f2ed5494..706936af 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -62,6 +62,9 @@ pub fn builder_from_flags<I>
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<I>
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);
}
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 00000000..e69de29b
--- /dev/null
+++ b/tests/expectations/struct_with_anon_struct_array_float.rs
diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs
index c60d69c3..1068f3f5 100644
--- a/tests/expectations/tests/16-byte-alignment.rs
+++ b/tests/expectations/tests/16-byte-alignment.rs
@@ -28,22 +28,25 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>,
pub sctp_tag: __BindgenUnionField<u32>,
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<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>,
pub sctp_tag: __BindgenUnionField<u32>,
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/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs
index 699d49c2..38ed0268 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 bfb10015..b4820319 100644
--- a/tests/expectations/tests/anon_struct_in_union.rs
+++ b/tests/expectations/tests/anon_struct_in_union.rs
@@ -28,19 +28,22 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<s__bindgen_ty_1_inner>,
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 97cd40f5..71c2d4f7 100644
--- a/tests/expectations/tests/anon_union.rs
+++ b/tests/expectations/tests/anon_union.rs
@@ -28,8 +28,11 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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/expectations/tests/anonymous-template-types.rs b/tests/expectations/tests/anonymous-template-types.rs
index 0f19d86e..6d231330 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<T> {
pub t_member: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -14,12 +14,12 @@ impl <T> Default for Foo<T> {
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<V> {
pub v_member: V,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<V>>,
@@ -28,7 +28,7 @@ impl <V> Default for Quux<V> {
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/char.rs b/tests/expectations/tests/char.rs
index be92e545..f34e075d 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/class.rs b/tests/expectations/tests/class.rs
index 26e6a62c..b628ab11 100644
--- a/tests/expectations/tests/class.rs
+++ b/tests/expectations/tests/class.rs
@@ -61,6 +61,9 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<f32>,
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 11e2f939..4172d467 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<T> {
pub foo: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -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<T> {
pub member: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
#[repr(C)]
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, Hash)]
pub struct Templated_Templated_inner<T> {
pub member_ptr: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs
index 41b97a9c..e78964fe 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 b48fd052..97dcbf79 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 b8e91bd3..a599ed89 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 15cc61f6..a8d26d29 100644
--- a/tests/expectations/tests/class_use_as.rs
+++ b/tests/expectations/tests/class_use_as.rs
@@ -6,7 +6,7 @@
/// <div rustbindgen="true" replaces="whatever"></div>
#[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 cf36f119..8686c41c 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<T> {
pub ptr: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -15,7 +15,7 @@ impl <T> Default for HandleWithDtor<T> {
}
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 f4b03b4e..4ccafab4 100644
--- a/tests/expectations/tests/class_with_inner_struct.rs
+++ b/tests/expectations/tests/class_with_inner_struct.rs
@@ -28,15 +28,18 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<C__bindgen_ty_1__bindgen_ty_1>,
pub __bindgen_anon_1: __BindgenUnionField<C__bindgen_ty_1__bindgen_ty_2>,
@@ -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 9dba8675..f41aa228 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/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs
index 22eb92b8..08d5d453 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<f64>,
}
@@ -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<f32>,
}
diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs
index 1d9a480e..fca1f4e5 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<unsafe extern "C" fn(arg1: ::std::os::raw::c_int,
+ arg2: ::std::os::raw::c_int,
+ arg3: ::std::os::raw::c_int,
+ arg4: ::std::os::raw::c_int,
+ arg5: ::std::os::raw::c_int,
+ arg6: ::std::os::raw::c_int,
+ arg7: ::std::os::raw::c_int,
+ arg8: ::std::os::raw::c_int,
+ arg9: ::std::os::raw::c_int,
+ arg10: ::std::os::raw::c_int,
+ arg11: ::std::os::raw::c_int,
+ arg12: ::std::os::raw::c_int)>;
+#[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::<Bar>() , 8usize , concat ! (
+ "Size of: " , stringify ! ( Bar ) ));
+ assert_eq! (::std::mem::align_of::<Bar>() , 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/derive-hash-blacklisting.rs b/tests/expectations/tests/derive-hash-blacklisting.rs
new file mode 100644
index 00000000..c345d1aa
--- /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: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }
+
+/// 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::<WhitelistedOne>() , 4usize , concat ! (
+ "Size of: " , stringify ! ( WhitelistedOne ) ));
+ assert_eq! (::std::mem::align_of::<WhitelistedOne>() , 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<f32>,
+}
+#[test]
+fn bindgen_test_layout_WhitelistedTwo() {
+ assert_eq!(::std::mem::size_of::<WhitelistedTwo>() , 4usize , concat ! (
+ "Size of: " , stringify ! ( WhitelistedTwo ) ));
+ assert_eq! (::std::mem::align_of::<WhitelistedTwo>() , 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 00000000..051a3636
--- /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::<foo__bindgen_ty_1>() , 8usize , concat !
+ ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
+ assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 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::<foo>() , 8usize , concat ! (
+ "Size of: " , stringify ! ( foo ) ));
+ assert_eq! (::std::mem::align_of::<foo>() , 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 00000000..bb4a6b5d
--- /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::<foo>() , 12usize , concat ! (
+ "Size of: " , stringify ! ( foo ) ));
+ assert_eq! (::std::mem::align_of::<foo>() , 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 00000000..007fd2f9
--- /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::<ConstPtrMutObj>() , 8usize , concat ! (
+ "Size of: " , stringify ! ( ConstPtrMutObj ) ));
+ assert_eq! (::std::mem::align_of::<ConstPtrMutObj>() , 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::<MutPtrMutObj>() , 8usize , concat ! (
+ "Size of: " , stringify ! ( MutPtrMutObj ) ));
+ assert_eq! (::std::mem::align_of::<MutPtrMutObj>() , 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::<MutPtrConstObj>() , 8usize , concat ! (
+ "Size of: " , stringify ! ( MutPtrConstObj ) ));
+ assert_eq! (::std::mem::align_of::<MutPtrConstObj>() , 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::<ConstPtrConstObj>() , 8usize , concat ! (
+ "Size of: " , stringify ! ( ConstPtrConstObj ) ));
+ assert_eq! (::std::mem::align_of::<ConstPtrConstObj>() , 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 00000000..e1d7836c
--- /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<T> {
+ pub data: T,
+ pub b: f32,
+ pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
+}
+impl <T> Default for foo<T> {
+ 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 00000000..dd18053f
--- /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<T> {
+ pub data: T,
+ pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
+}
+impl <T> Default for foo<T> {
+ 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::<IntStr>() , 4usize , concat ! (
+ "Size of: " , stringify ! ( IntStr ) ));
+ assert_eq! (::std::mem::align_of::<IntStr>() , 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<f32>,
+}
+#[test]
+fn bindgen_test_layout_FloatStr() {
+ assert_eq!(::std::mem::size_of::<FloatStr>() , 4usize , concat ! (
+ "Size of: " , stringify ! ( FloatStr ) ));
+ assert_eq! (::std::mem::align_of::<FloatStr>() , 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::<foo<::std::os::raw::c_int>>() , 4usize ,
+ concat ! (
+ "Size of template specialization: " , stringify ! (
+ foo<::std::os::raw::c_int> ) ));
+ assert_eq!(::std::mem::align_of::<foo<::std::os::raw::c_int>>() , 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::<foo<f32>>() , 4usize , concat ! (
+ "Size of template specialization: " , stringify ! ( foo<f32> )
+ ));
+ assert_eq!(::std::mem::align_of::<foo<f32>>() , 4usize , concat ! (
+ "Alignment of template specialization: " , stringify ! (
+ foo<f32> ) ));
+}
diff --git a/tests/expectations/tests/empty_template_param_name.rs b/tests/expectations/tests/empty_template_param_name.rs
index f182d9c2..07f27e54 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/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs
index f52c56ba..a855d8cf 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<unsafe extern "C" fn(x:
::std::os::raw::c_int,
diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs
index 89f03457..d25bb4a0 100644
--- a/tests/expectations/tests/issue-493.rs
+++ b/tests/expectations/tests/issue-493.rs
@@ -28,8 +28,11 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<basic_string_value_type>,
@@ -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/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs
index bcd5141e..0e22eedf 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/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs
index 7a7afb86..cd2c4fac 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 f22a9612..2826ec5d 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 980adbcf..536d8c59 100644
--- a/tests/expectations/tests/jsval_layout_opaque.rs
+++ b/tests/expectations/tests/jsval_layout_opaque.rs
@@ -28,6 +28,9 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<u64>,
pub debugView: __BindgenUnionField<jsval_layout__bindgen_ty_1>,
@@ -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<i32>,
pub u32: __BindgenUnionField<u32>,
@@ -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/layout_array.rs b/tests/expectations/tests/layout_array.rs
index bccd5004..8ec289d4 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 9c825625..6078e2cc 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 <src addr, dst_addr, id> 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 a51e40bc..6cf37ac5 100644
--- a/tests/expectations/tests/layout_eth_conf.rs
+++ b/tests/expectations/tests/layout_eth_conf.rs
@@ -28,6 +28,9 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<rte_eth_vmdq_dcb_tx_conf>,
pub dcb_tx_conf: __BindgenUnionField<rte_eth_dcb_tx_conf>,
diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs
index 77198c35..5e08af3c 100644
--- a/tests/expectations/tests/layout_mbuf.rs
+++ b/tests/expectations/tests/layout_mbuf.rs
@@ -28,6 +28,9 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<rte_atomic16_t>,
@@ -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<u32>,
@@ -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<u32>,
@@ -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<rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1>,
pub lo: __BindgenUnionField<u32>,
pub bindgen_union_field: u32,
}
#[repr(C)]
-#[derive(Debug, 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<u64>,
@@ -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/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs
index 65efefb2..8c098c8f 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 9f0969cd..11c3cc84 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 00c55825..396edbd6 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<T> {
pub member: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -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<root::zoidberg::Foo>,
}
@@ -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 f3ef2a06..aafe702f 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<T> {
pub member: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -14,7 +14,7 @@ impl <T> Default for Template<T> {
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 fc91a6ce..5113ccf3 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 d41cbf10..db85246a 100644
--- a/tests/expectations/tests/opaque_in_struct.rs
+++ b/tests/expectations/tests/opaque_in_struct.rs
@@ -6,7 +6,7 @@
/// <div rustbindgen opaque>
#[repr(C)]
-#[derive(Debug, 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 feb22439..2e566dc4 100644
--- a/tests/expectations/tests/opaque_pointer.rs
+++ b/tests/expectations/tests/opaque_pointer.rs
@@ -6,7 +6,7 @@
/// <div rustbindgen opaque></div>
#[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 {
}
/// <div rustbindgen opaque></div>
#[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 a19a71ac..53cf6f64 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/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs
index 6b243732..b72d67c9 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 4f41e187..c01d3963 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 e436beb2..47234321 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 015e7d86..26e06c0b 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 8934e8a6..a2ab1b2b 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 cba5b8a6..cfe5dbd7 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 5984ba6e..84be35ed 100644
--- a/tests/expectations/tests/struct_with_anon_union.rs
+++ b/tests/expectations/tests/struct_with_anon_union.rs
@@ -28,13 +28,16 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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 a7374bc4..8a5d6194 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 09dbbb59..226f7db9 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 <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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 b93b441f..97cefe06 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 b2a77b27..2fd00fb1 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 1a8e887d..63df2729 100644
--- a/tests/expectations/tests/struct_with_nesting.rs
+++ b/tests/expectations/tests/struct_with_nesting.rs
@@ -28,14 +28,17 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<foo__bindgen_ty_1__bindgen_ty_1>,
@@ -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 abeb0b83..7e587a07 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 1ad359f3..d6509a14 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 9066e037..7566bf4a 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/expectations/tests/template-fun-ty.rs b/tests/expectations/tests/template-fun-ty.rs
index 30571266..a4c8ad44 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<T> =
::std::option::Option<unsafe extern "C" fn() -> 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 f1cc8a25..141af8fa 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<T> {
pub m_member: T,
pub m_member_ptr: *mut T,
@@ -16,7 +16,7 @@ impl <T> Default for Foo<T> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, Hash)]
pub struct B<T> {
pub m_member: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -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<Z> {
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<T> {
pub prev: *mut T,
pub next: *mut Rooted<*mut ::std::os::raw::c_void>,
@@ -117,7 +117,7 @@ impl <T> Default for Rooted<T> {
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<T> {
pub member: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -150,7 +150,7 @@ impl <T> Default for WithDtor<T> {
}
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 {
}
/// <div rustbindgen opaque>
#[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 {
}
/// <div rustbindgen replaces="NestedReplaced"></div>
#[repr(C)]
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, Hash)]
pub struct NestedReplaced<T> {
pub buff: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -205,7 +205,7 @@ impl <T> Default for NestedReplaced<T> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, Hash)]
pub struct NestedBase<T> {
pub buff: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -214,7 +214,7 @@ impl <T> Default for NestedBase<T> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, Hash)]
pub struct Incomplete<T> {
pub d: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -223,7 +223,7 @@ impl <T> Default for Incomplete<T> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, Hash)]
pub struct NestedContainer<T> {
pub c: T,
pub nested: NestedReplaced<T>,
@@ -234,7 +234,7 @@ impl <T> Default for NestedContainer<T> {
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 {
///
/// <div rustbindgen replaces="ReplacedWithoutDestructor"></div>
#[repr(C)]
-#[derive(Debug)]
+#[derive(Debug, Hash)]
pub struct ReplacedWithoutDestructor<T> {
pub buff: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -267,7 +267,7 @@ impl <T> Default for ReplacedWithoutDestructor<T> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
-#[derive(Debug)]
+#[derive(Debug, Hash)]
pub struct ShouldNotBeCopiable<T> {
pub m_member: ReplacedWithoutDestructor<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -276,7 +276,7 @@ impl <T> Default for ShouldNotBeCopiable<T> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
-#[derive(Debug)]
+#[derive(Debug, Hash)]
pub struct ShouldNotBeCopiableAsWell<U> {
pub m_member: ReplacedWithoutDestructorFwd<U>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
@@ -289,7 +289,7 @@ impl <U> Default for ShouldNotBeCopiableAsWell<U> {
///
/// <div rustbindgen replaces="ReplacedWithoutDestructorFwd"></div>
#[repr(C)]
-#[derive(Debug)]
+#[derive(Debug, Hash)]
pub struct ReplacedWithoutDestructorFwd<T> {
pub buff: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
diff --git a/tests/expectations/tests/template_alias.rs b/tests/expectations/tests/template_alias.rs
index a718e704..537fc376 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> = T;
#[repr(C)]
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, Hash)]
pub struct JS_Rooted<T> {
pub ptr: JS_detail_Wrapped<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
diff --git a/tests/expectations/tests/template_alias_namespace.rs b/tests/expectations/tests/template_alias_namespace.rs
index 2fb88a81..ba94dd7d 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> = T;
}
#[repr(C)]
- #[derive(Debug, Copy, Clone)]
+ #[derive(Debug, Copy, Clone, Hash)]
pub struct Rooted<T> {
pub ptr: root::JS::detail::Wrapped<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
diff --git a/tests/expectations/tests/template_typedef_transitive_param.rs b/tests/expectations/tests/template_typedef_transitive_param.rs
index 05604223..6a0026fb 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<T> {
pub t: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
diff --git a/tests/expectations/tests/templateref_opaque.rs b/tests/expectations/tests/templateref_opaque.rs
index 5f6a7459..a20dd691 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<T> = *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/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs
index 53119f09..43427f08 100644
--- a/tests/expectations/tests/typeref.rs
+++ b/tests/expectations/tests/typeref.rs
@@ -28,8 +28,11 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs
index 8beb7a92..968b1f83 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 <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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 429ec082..6f7eba41 100644
--- a/tests/expectations/tests/union_dtor.rs
+++ b/tests/expectations/tests/union_dtor.rs
@@ -28,6 +28,9 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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 45ce6473..fd4ac5ab 100644
--- a/tests/expectations/tests/union_fields.rs
+++ b/tests/expectations/tests/union_fields.rs
@@ -28,8 +28,11 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<f32>,
diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs
index 7f30e7b4..df5e87ee 100644
--- a/tests/expectations/tests/union_template.rs
+++ b/tests/expectations/tests/union_template.rs
@@ -28,29 +28,32 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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 f0bb68d5..5afaa876 100644
--- a/tests/expectations/tests/union_with_anon_struct.rs
+++ b/tests/expectations/tests/union_with_anon_struct.rs
@@ -28,14 +28,17 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Hash)]
pub struct foo {
pub bar: __BindgenUnionField<foo__bindgen_ty_1>,
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 e6acd105..ba1cdf47 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 <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<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 {
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 668160a7..99c0c817 100644
--- a/tests/expectations/tests/union_with_anon_union.rs
+++ b/tests/expectations/tests/union_with_anon_union.rs
@@ -28,14 +28,17 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Hash)]
pub struct foo {
pub bar: __BindgenUnionField<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 {
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 98524422..afe12dce 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 <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<pixel__bindgen_ty_1>,
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 1a6f5f45..67dcd521 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 <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<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 {
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 679832fd..836fe1a5 100644
--- a/tests/expectations/tests/union_with_big_member.rs
+++ b/tests/expectations/tests/union_with_big_member.rs
@@ -28,6 +28,9 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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 7e32f0c0..59caccf4 100644
--- a/tests/expectations/tests/union_with_nesting.rs
+++ b/tests/expectations/tests/union_with_nesting.rs
@@ -28,21 +28,24 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&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<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 {
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/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs
index 14ac1373..fd89783f 100644
--- a/tests/expectations/tests/use-core.rs
+++ b/tests/expectations/tests/use-core.rs
@@ -29,8 +29,11 @@ impl <T> ::core::fmt::Debug for __BindgenUnionField<T> {
fmt.write_str("__BindgenUnionField")
}
}
+impl <T> ::core::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::core::hash::Hasher>(&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 7a7f7548..cca4d285 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/anon_enum.hpp b/tests/headers/anon_enum.hpp
index 1961fe6c..1a55a8d1 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 e1ec394c..22137392 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<typename _Tp>
class DataType {
diff --git a/tests/headers/anon_struct_in_union.h b/tests/headers/anon_struct_in_union.h
index 880a8b54..2e6ac5e9 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 126f6a6e..26bb842f 100644
--- a/tests/headers/anon_union.hpp
+++ b/tests/headers/anon_union.hpp
@@ -1,3 +1,4 @@
+// bindgen-flags: --with-derive-hash
template<typename T>
struct TErrorResult {
enum UnionState {
diff --git a/tests/headers/anonymous-template-types.hpp b/tests/headers/anonymous-template-types.hpp
index 9ada71a9..34924fc9 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 <typename T, typename>
struct Foo {
diff --git a/tests/headers/char.h b/tests/headers/char.h
index ae38653e..8db9ccf0 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/class.hpp b/tests/headers/class.hpp
index 1de16471..3e183cdf 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 208bc4be..e01fc947 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 a4483558..03f916a9 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 21ab2321..1e38e5a5 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 150afe8b..92599183 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 a4e36ded..6924255d 100644
--- a/tests/headers/class_use_as.hpp
+++ b/tests/headers/class_use_as.hpp
@@ -1,3 +1,4 @@
+// bindgen-flags: --with-derive-hash
/**
* <div rustbindgen="true" replaces="whatever"></div>
diff --git a/tests/headers/class_with_dtor.hpp b/tests/headers/class_with_dtor.hpp
index b9bf74e1..9cc2bad4 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 <typename T>
diff --git a/tests/headers/class_with_inner_struct.hpp b/tests/headers/class_with_inner_struct.hpp
index ec729fe6..781a01db 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 8707cffe..7abb6f77 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 {
diff --git a/tests/headers/complex.h b/tests/headers/complex.h
index 04877a4e..9696b606 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 d9f9fb01..7b9e8872 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;
diff --git a/tests/headers/derive-fn-ptr.h b/tests/headers/derive-fn-ptr.h
index 39ff76d6..fb89daad 100644
--- a/tests/headers/derive-fn-ptr.h
+++ b/tests/headers/derive-fn-ptr.h
@@ -1,3 +1,5 @@
+// bindgen-flags: --with-derive-hash
+//
typedef void (*my_fun_t)(int, int, int, int,
int, int, int, int,
int, int, int, int,
@@ -6,3 +8,11 @@ typedef void (*my_fun_t)(int, int, int, int,
struct Foo {
my_fun_t callback;
};
+
+typedef void (*my_fun2_t)(int, int, int, int,
+ int, int, int, int,
+ int, int, int, int);
+
+struct Bar {
+ my_fun2_t callback;
+};
diff --git a/tests/headers/derive-hash-blacklisting.hpp b/tests/headers/derive-hash-blacklisting.hpp
new file mode 100644
index 00000000..ee819c17
--- /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: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }"
+//
+template<class T>
+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<int> a;
+};
+
+/// This can't derive(Hash) even if it didn't contain a blacklisted type.
+struct WhitelistedTwo {
+ Blacklisted<float> 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 00000000..2b76cd23
--- /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 00000000..53f0c79d
--- /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 00000000..262b6fb4
--- /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 00000000..28885ed1
--- /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<typename T>
+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 00000000..59af69bd
--- /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<typename T>
+struct foo {
+ T data;
+};
+
+/// Can derive hash when instantiated with int
+struct IntStr {
+ foo<int> a;
+};
+
+/// Cannot derive hash when instantiated with float
+struct FloatStr {
+ foo<float> a;
+};
diff --git a/tests/headers/empty_template_param_name.hpp b/tests/headers/empty_template_param_name.hpp
index 0e9f3c34..ef212d55 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<typename...> using __void_t = void;
diff --git a/tests/headers/func_ptr.h b/tests/headers/func_ptr.h
index a4662f3d..377c172f 100644
--- a/tests/headers/func_ptr.h
+++ b/tests/headers/func_ptr.h
@@ -1 +1,3 @@
+// bindgen-flags: --with-derive-hash
+//
int (*foo) (int x, int y);
diff --git a/tests/headers/func_ptr_in_struct.h b/tests/headers/func_ptr_in_struct.h
index 988db5b3..6340e3a6 100644
--- a/tests/headers/func_ptr_in_struct.h
+++ b/tests/headers/func_ptr_in_struct.h
@@ -1,4 +1,5 @@
-
+// bindgen-flags: --with-derive-hash
+//
enum baz;
struct Foo {
diff --git a/tests/headers/issue-493.hpp b/tests/headers/issue-493.hpp
index 975ef5ce..ea39c83c 100644
--- a/tests/headers/issue-493.hpp
+++ b/tests/headers/issue-493.hpp
@@ -1,3 +1,4 @@
+// bindgen-flags: --with-derive-hash
template<class _CharT, class _Traits, class _Allocator>
class basic_string
{
@@ -44,4 +45,4 @@ public:
__raw __r;
};
};
-}; \ No newline at end of file
+};
diff --git a/tests/headers/issue-648-derive-debug-with-padding.h b/tests/headers/issue-648-derive-debug-with-padding.h
index 2bd5927a..fbe98678 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/issue-801-opaque-sloppiness.hpp b/tests/headers/issue-801-opaque-sloppiness.hpp
index 503bba39..275be023 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 bdb7cd53..f2133427 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 8f36f77d..4a4f367b 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/layout_array.h b/tests/headers/layout_array.h
index 4b99e0ed..fb071df6 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 9be037ab..61f0c269 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 a742ee5f..7333f528 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 dc1c1b24..9166bac7 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;
diff --git a/tests/headers/opaque-template-inst-member-2.hpp b/tests/headers/opaque-template-inst-member-2.hpp
index d4386f48..9d31fa31 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<typename T>
class OpaqueTemplate {
T mData;
};
-// Should derive Debug.
+/// Should derive Debug/Hash.
class ContainsOpaqueTemplate {
OpaqueTemplate<int> mBlah;
int mBaz;
};
-// Should also derive Debug.
+/// Should also derive Debug/Hash.
class InheritsOpaqueTemplate : public OpaqueTemplate<bool> {
char* wow;
};
diff --git a/tests/headers/opaque-template-inst-member.hpp b/tests/headers/opaque-template-inst-member.hpp
index 7748007b..d5954144 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<typename T>
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<int> 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<bool> {
char* wow;
};
diff --git a/tests/headers/opaque-template-instantiation-namespaced.hpp b/tests/headers/opaque-template-instantiation-namespaced.hpp
index 31fb0d52..85513fdf 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<zoidberg::Bar>' -- -std=c++14
+// bindgen-flags: --enable-cxx-namespaces --opaque-type 'zoidberg::Template<zoidberg::Bar>' --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 7589b53c..fe29948d 100644
--- a/tests/headers/opaque-template-instantiation.hpp
+++ b/tests/headers/opaque-template-instantiation.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --opaque-type 'Template<int>' -- -std=c++14
+// bindgen-flags: --opaque-type 'Template<int>' --with-derive-hash -- -std=c++14
template <typename T>
class Template {
diff --git a/tests/headers/opaque-tracing.hpp b/tests/headers/opaque-tracing.hpp
index 7356245e..42ef3ccf 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 3cffeb20..771b80bc 100644
--- a/tests/headers/opaque_in_struct.hpp
+++ b/tests/headers/opaque_in_struct.hpp
@@ -1,3 +1,4 @@
+// bindgen-flags: --with-derive-hash
/** <div rustbindgen opaque> */
diff --git a/tests/headers/opaque_pointer.hpp b/tests/headers/opaque_pointer.hpp
index 53f8ce1f..cc99df99 100644
--- a/tests/headers/opaque_pointer.hpp
+++ b/tests/headers/opaque_pointer.hpp
@@ -1,3 +1,4 @@
+// bindgen-flags: --with-derive-hash
/**
* <div rustbindgen opaque></div>
diff --git a/tests/headers/opaque_typedef.hpp b/tests/headers/opaque_typedef.hpp
index 25640738..f39f2fce 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<typename T>
class RandomTemplate;
diff --git a/tests/headers/struct_containing_forward_declared_struct.h b/tests/headers/struct_containing_forward_declared_struct.h
index d38aca2f..68828192 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 fdce9a72..f8eacd87 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 bc89eb2b..62a8ceac 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 1617d7a8..e6a8ab97 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 9ea977e8..459e274a 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 0c486d84..de628402 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 3a92b940..45ddb3c4 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 f8ac4225..5962a12c 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 7158e727..949547c1 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 ece512cd..88a167a0 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 98ba1b3d..d13bb466 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 fc67b333..c9aaa697 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 9d7fa176..30f40bce 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 1b9fe131..2184e8ec 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 78b1cc81..975b0af4 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 7fed21ab..f299e322 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<typename T, typename ...Args>
struct Proxy {
typedef void (*foo)(T* bar);
diff --git a/tests/headers/template-fun-ty.hpp b/tests/headers/template-fun-ty.hpp
index 1e8e1c25..cc33fb74 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 <typename T>
class Foo
{
diff --git a/tests/headers/template.hpp b/tests/headers/template.hpp
index 168eac9c..c3dff4f7 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<typename T, typename U> class Foo {
T m_member;
diff --git a/tests/headers/template_alias.hpp b/tests/headers/template_alias.hpp
index 646d9f40..684bf286 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 bd637166..b24e4bd3 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 2269ac36..2c50cda6 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<typename T>
struct Wrapper {
struct Wrapped {
diff --git a/tests/headers/templateref_opaque.hpp b/tests/headers/templateref_opaque.hpp
index ca154c34..1dcf4778 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<typename T>
diff --git a/tests/headers/typeref.hpp b/tests/headers/typeref.hpp
index b94c98ef..c417bdb6 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/union_fields.hpp b/tests/headers/union_fields.hpp
index aec3a7fd..cc8fcbe4 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 0d0a9bb3..f330f6b2 100644
--- a/tests/headers/union_template.hpp
+++ b/tests/headers/union_template.hpp
@@ -1,3 +1,5 @@
+// bindgen-flags: --with-derive-hash
+//
template<typename T>
struct NastyStruct {
bool mIsSome;
diff --git a/tests/headers/union_with_anon_struct.h b/tests/headers/union_with_anon_struct.h
index 7f8dec95..48adae8b 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 9668ce40..027a99eb 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 212431b8..b2b6fc12 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 79558049..70ae15fe 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 7580771a..10443609 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 6347d6ca..abc0062e 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 cd907d57..e40f5212 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 {
diff --git a/tests/headers/use-core.h b/tests/headers/use-core.h
index 0e8a8d6e..b34a71e7 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;