summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ir/analysis/derive_hash.rs4
-rw-r--r--src/ir/context.rs6
-rw-r--r--src/lib.rs26
-rw-r--r--src/options.rs13
4 files changed, 49 insertions, 0 deletions
diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs
index d2eac677..46790232 100644
--- a/src/ir/analysis/derive_hash.rs
+++ b/src/ir/analysis/derive_hash.rs
@@ -127,6 +127,10 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
}
};
+ if self.ctx.no_hash_by_name(&item) {
+ return self.insert(id)
+ }
+
if item.is_opaque(self.ctx, &()) {
let layout_can_derive = ty.layout(self.ctx).map_or(true, |l| {
l.opaque().can_trivially_derive_hash()
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 0acf8d41..138a69b9 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -2495,6 +2495,12 @@ impl BindgenContext {
let name = item.canonical_path(self)[1..].join("::");
self.options().no_copy_types.matches(&name)
}
+
+ /// Chech if `--no-hash` flag is enabled for this item.
+ pub fn no_hash_by_name(&self, item: &Item) -> bool {
+ let name = item.canonical_path(self)[1..].join("::");
+ self.options().no_hash_types.matches(&name)
+ }
}
/// A builder struct for configuring item resolution options.
diff --git a/src/lib.rs b/src/lib.rs
index 86af0550..deadf478 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -536,6 +536,20 @@ impl Builder {
})
.count();
+ self.options
+ .no_hash_types
+ .get_items()
+ .iter()
+ .map(|item| {
+ output_vector.push("--no-hash".into());
+ output_vector.push(
+ item.trim_left_matches("^")
+ .trim_right_matches("$")
+ .into(),
+ );
+ })
+ .count();
+
output_vector
}
@@ -1179,6 +1193,13 @@ impl Builder {
self.options.no_copy_types.insert(arg);
self
}
+
+ /// Don't derive `Hash` for a given type. Regular
+ /// expressions are supported.
+ pub fn no_hash(mut self, arg: String) -> Builder {
+ self.options.no_hash_types.insert(arg);
+ self
+ }
}
/// Configuration options for generated bindings.
@@ -1369,6 +1390,9 @@ struct BindgenOptions {
/// The set of types that we should not derive `Copy` for.
no_copy_types: RegexSet,
+
+ /// The set of types that we should not derive `Hash` for.
+ no_hash_types: RegexSet,
}
/// TODO(emilio): This is sort of a lie (see the error message that results from
@@ -1388,6 +1412,7 @@ impl BindgenOptions {
self.rustified_enums.build();
self.no_partialeq_types.build();
self.no_copy_types.build();
+ self.no_hash_types.build();
}
/// Update rust target version
@@ -1460,6 +1485,7 @@ impl Default for BindgenOptions {
rustfmt_configuration_file: None,
no_partialeq_types: Default::default(),
no_copy_types: Default::default(),
+ no_hash_types: Default::default(),
}
}
}
diff --git a/src/options.rs b/src/options.rs
index 38b47b6a..d06fb6a2 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -292,6 +292,13 @@ where
.takes_value(true)
.multiple(true)
.number_of_values(1),
+ Arg::with_name("no-hash")
+ .long("no-hash")
+ .help("Avoid deriving Hash for types matching <regex>.")
+ .value_name("regex")
+ .takes_value(true)
+ .multiple(true)
+ .number_of_values(1),
]) // .args()
.get_matches_from(args);
@@ -592,6 +599,12 @@ where
}
}
+ if let Some(no_hash) = matches.values_of("no-hash") {
+ for regex in no_hash {
+ builder = builder.no_hash(String::from(regex));
+ }
+ }
+
let verbose = matches.is_present("verbose");
Ok((builder, output, verbose))