summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2019-01-16 23:34:56 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-03-25 23:59:28 +0100
commit76d1959cb51b32e9bd2092bb87985b64158dd433 (patch)
treea74f47af4049453304044bc0d819575143d2b47d /src
parentd6998132429e287a540633b75ff6ce44facc4dd0 (diff)
ir: Whitelist items that don't generate code to improve derive behavior.
When not whitelisting recursively. Fixes #1454
Diffstat (limited to 'src')
-rw-r--r--src/codegen/mod.rs2
-rw-r--r--src/ir/context.rs22
2 files changed, 24 insertions, 0 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 0956eb7a..8d1327b3 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -610,6 +610,8 @@ impl CodeGenerator for Type {
TypeKind::TypeParam => {
// These items don't need code generation, they only need to be
// converted to rust types in fields, arguments, and such.
+ // NOTE(emilio): If you add to this list, make sure to also add
+ // it to BindgenContext::compute_whitelisted_and_codegen_items.
return;
}
TypeKind::TemplateInstantiation(ref inst) => {
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 914a89b2..0fe720f9 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -2314,6 +2314,28 @@ If you encounter an error missing from this list, please file an issue or a PR!"
return true;
}
+ // Auto-whitelist types that don't need code
+ // generation if not whitelisting recursively, to
+ // make the #[derive] analysis not be lame.
+ if !self.options().whitelist_recursively {
+ match *ty.kind() {
+ TypeKind::Void |
+ TypeKind::NullPtr |
+ TypeKind::Int(..) |
+ TypeKind::Float(..) |
+ TypeKind::Complex(..) |
+ TypeKind::Array(..) |
+ TypeKind::Vector(..) |
+ TypeKind::Pointer(..) |
+ TypeKind::Reference(..) |
+ TypeKind::Function(..) |
+ TypeKind::ResolvedTypeRef(..) |
+ TypeKind::Opaque |
+ TypeKind::TypeParam => return true,
+ _ => {},
+ };
+ }
+
// Unnamed top-level enums are special and we
// whitelist them via the `whitelisted_vars` filter,
// since they're effectively top-level constants,