diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-12-07 17:02:09 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-07 17:02:09 -0800 |
commit | 47e4ec7477a110265117a07bc290987b532861f9 (patch) | |
tree | 893205e74e5e7aca8f26a2672489d2d1322f4cea /libbindgen/src/codegen/mod.rs | |
parent | ec298aebd3114a8f20865eb8994c4b4f9a820a8e (diff) | |
parent | 161a590d44952d9921ab1cdd721166aceee5ed01 (diff) |
Auto merge of #319 - emilio:union-in-ns, r=fitzgen
codegen: Fix bindgen-injected items in namespaces.
Found while trying to use namespaces in stylo.
r? @fitzgen
Diffstat (limited to 'libbindgen/src/codegen/mod.rs')
-rw-r--r-- | libbindgen/src/codegen/mod.rs | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs index ff18ab83..d2e2b96c 100644 --- a/libbindgen/src/codegen/mod.rs +++ b/libbindgen/src/codegen/mod.rs @@ -303,6 +303,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 { @@ -916,7 +926,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 }; @@ -1747,7 +1761,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); @@ -2008,15 +2026,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 }) } |