summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-08-09 18:35:01 -0500
committerGitHub <noreply@github.com>2017-08-09 18:35:01 -0500
commit828d46822459116311cb09dcc9847df1cf9c1dbf (patch)
tree2dc33b49a35db14adcec8ba88bae9db391753920 /src/codegen/mod.rs
parentb6400942670694782d87ec0e2393463646e44eb9 (diff)
parentb4895d96698504dc28dfa64c4c4e4c3f3714a3c8 (diff)
Auto merge of #887 - photoszzt:derive_hash, r=fitzgen
Can derive hash analysis r? @fitzgen Fix: #876 I haven't enable too much test yet. Enable the option for all tests changes more than 200 of them. I want some input on which test is good to enable or write a new test.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs19
1 files changed, 17 insertions, 2 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());