summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorVarphone Wong <varphone@qq.com>2020-11-25 17:24:46 +0800
committerEmilio Cobos Álvarez <emilio@crisal.io>2020-11-26 11:12:02 +0100
commitd8082613e2c33efbd7b5347d4c1809578d49bd7b (patch)
tree44d0ed6a92b46bbb75f02536d4d52291c6787348 /src/codegen/mod.rs
parent30fb4eccb3cf3068e4132e68ba832ec148c2b786 (diff)
Add --no-default <regex> flag
Sometimes, we need customize the implement of `Default` for certain types, In these cases, the `nodefault` annotation can be used to prevent bindgen to autoderive the `Default` traits for a type.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 754c2c8b..15aea22a 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -118,7 +118,7 @@ fn derives_of_item(item: &Item, ctx: &BindgenContext) -> DerivableTraits {
derivable_traits |= DerivableTraits::DEBUG;
}
- if item.can_derive_default(ctx) {
+ if item.can_derive_default(ctx) && !item.annotations().disallow_default() {
derivable_traits |= DerivableTraits::DEFAULT;
}
@@ -1900,8 +1900,10 @@ impl CodeGenerator for CompInfo {
}
if !derivable_traits.contains(DerivableTraits::DEFAULT) {
- needs_default_impl =
- ctx.options().derive_default && !self.is_forward_declaration();
+ needs_default_impl = ctx.options().derive_default &&
+ !self.is_forward_declaration() &&
+ !ctx.no_default_by_name(item) &&
+ !item.annotations().disallow_default();
}
let all_template_params = item.all_template_params(ctx);