summaryrefslogtreecommitdiff
path: root/libbindgen/src/codegen/mod.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2016-12-05 00:36:05 -0800
committerEmilio Cobos Álvarez <emilio@crisal.io>2016-12-05 09:38:20 +0100
commit161a590d44952d9921ab1cdd721166aceee5ed01 (patch)
tree92e30f8d00c9315540fd08bf97969dca62c79799 /libbindgen/src/codegen/mod.rs
parent8013e0c7bc28e0883363649c94360b4878d1d742 (diff)
codegen: Fix bindgen-injected items in namespaces.
Found while trying to use namespaces in stylo.
Diffstat (limited to 'libbindgen/src/codegen/mod.rs')
-rw-r--r--libbindgen/src/codegen/mod.rs32
1 files changed, 21 insertions, 11 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs
index 7fa76d56..c267cb95 100644
--- a/libbindgen/src/codegen/mod.rs
+++ b/libbindgen/src/codegen/mod.rs
@@ -299,6 +299,16 @@ impl CodeGenerator for Module {
.codegen(ctx, result, whitelisted_items, &());
}
}
+
+ if item.id() == ctx.root_module() {
+ let saw_union = result.saw_union;
+ if saw_union && !ctx.options().unstable_rust {
+ utils::prepend_union_types(ctx, &mut *result);
+ }
+ if ctx.need_bindegen_complex_type() {
+ utils::prepend_complex_type(ctx, &mut *result);
+ }
+ }
};
if !ctx.options().enable_cxx_namespaces {
@@ -912,7 +922,11 @@ impl CodeGenerator for CompInfo {
// NB: In unstable rust we use proper `union` types.
let ty = if is_union && !ctx.options().unstable_rust {
- quote_ty!(ctx.ext_cx(), __BindgenUnionField<$ty>)
+ if ctx.options().enable_cxx_namespaces {
+ quote_ty!(ctx.ext_cx(), root::__BindgenUnionField<$ty>)
+ } else {
+ quote_ty!(ctx.ext_cx(), __BindgenUnionField<$ty>)
+ }
} else {
ty
};
@@ -1745,7 +1759,11 @@ impl ToRustTy for Type {
let float_path = float_kind_rust_type(ctx, fk);
ctx.generated_bindegen_complex();
- quote_ty!(ctx.ext_cx(), __BindgenComplex<$float_path>)
+ if ctx.options().enable_cxx_namespaces {
+ quote_ty!(ctx.ext_cx(), root::__BindgenComplex<$float_path>)
+ } else {
+ quote_ty!(ctx.ext_cx(), __BindgenComplex<$float_path>)
+ }
}
TypeKind::Function(ref fs) => {
let ty = fs.to_rust_ty(ctx, item);
@@ -2006,15 +2024,7 @@ pub fn codegen(context: &mut BindgenContext) -> Vec<P<ast::Item>> {
context.resolve_item(context.root_module())
.codegen(context, &mut result, &whitelisted_items, &());
- let saw_union = result.saw_union;
- let mut result = result.items;
- if saw_union && !context.options().unstable_rust {
- utils::prepend_union_types(context, &mut result);
- }
- if context.need_bindegen_complex_type() {
- utils::prepend_complex_type(context, &mut result);
- }
- result
+ result.items
})
}