summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-02-08 06:49:51 -0800
committerGitHub <noreply@github.com>2017-02-08 06:49:51 -0800
commitddfa1e049917ad1caed834ebaf9fcfd1636dbfb9 (patch)
treedef5ca75fc7880c77d51b1009c81ddb686bae3d4
parent8264afa875d686688680123859f8820e19c8028c (diff)
parent60361505fbce24fb564edc56e1b9bb7299932457 (diff)
Auto merge of #489 - emilio:use-core, r=fitzgen
codegen: Fix remaining cases of missing core prefix. Fixes #488 r? @fitzgen
-rw-r--r--src/codegen/helpers.rs4
-rw-r--r--src/codegen/mod.rs9
-rw-r--r--tests/expectations/tests/use-core.rs55
-rw-r--r--tests/headers/use-core.h5
4 files changed, 68 insertions, 5 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs
index 06dadab0..9e19637c 100644
--- a/src/codegen/helpers.rs
+++ b/src/codegen/helpers.rs
@@ -89,7 +89,9 @@ pub mod ast_ty {
let prefix = ctx.rust_ident_raw(prefix);
quote_ty!(ctx.ext_cx(), $prefix::$ident)
}
- None => quote_ty!(ctx.ext_cx(), ::std::os::raw::$ident),
+ None => {
+ quote_ty!(ctx.ext_cx(), ::std::os::raw::$ident)
+ }
}
}
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 5ee43173..d3e204ce 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -1644,9 +1644,10 @@ impl MethodCodegen for Method {
// If it's a constructor, we need to insert an extra parameter with a
// variable called `__bindgen_tmp` we're going to create.
if self.is_constructor() {
+ let prefix = ctx.trait_prefix();
let tmp_variable_decl =
quote_stmt!(ctx.ext_cx(),
- let mut __bindgen_tmp = ::std::mem::uninitialized())
+ let mut __bindgen_tmp = ::$prefix::mem::uninitialized())
.unwrap();
stmts.push(tmp_variable_decl);
exprs[0] = quote_expr!(ctx.ext_cx(), &mut __bindgen_tmp);
@@ -2601,9 +2602,9 @@ mod utils {
.unwrap();
let union_field_debug_impl = quote_item!(ctx.ext_cx(),
- impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
- fn fmt(&self, fmt: &mut ::std::fmt::Formatter)
- -> ::std::fmt::Result {
+ impl<T> ::$prefix::fmt::Debug for __BindgenUnionField<T> {
+ fn fmt(&self, fmt: &mut ::$prefix::fmt::Formatter)
+ -> ::$prefix::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs
index dd13156f..c2996f74 100644
--- a/tests/expectations/tests/use-core.rs
+++ b/tests/expectations/tests/use-core.rs
@@ -6,6 +6,30 @@
extern crate core;
#[repr(C)]
+pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>);
+impl <T> __BindgenUnionField<T> {
+ #[inline]
+ pub fn new() -> Self { __BindgenUnionField(::core::marker::PhantomData) }
+ #[inline]
+ pub unsafe fn as_ref(&self) -> &T { ::core::mem::transmute(self) }
+ #[inline]
+ pub unsafe fn as_mut(&mut self) -> &mut T { ::core::mem::transmute(self) }
+}
+impl <T> ::core::default::Default for __BindgenUnionField<T> {
+ #[inline]
+ fn default() -> Self { Self::new() }
+}
+impl <T> ::core::clone::Clone for __BindgenUnionField<T> {
+ #[inline]
+ fn clone(&self) -> Self { Self::new() }
+}
+impl <T> ::core::marker::Copy for __BindgenUnionField<T> { }
+impl <T> ::core::fmt::Debug for __BindgenUnionField<T> {
+ fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
+#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
pub a: ::std::os::raw::c_int,
@@ -40,5 +64,36 @@ impl Clone for foo {
impl Default for foo {
fn default() -> Self { unsafe { ::core::mem::zeroed() } }
}
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct _bindgen_ty_1 {
+ pub bar: __BindgenUnionField<::std::os::raw::c_int>,
+ pub baz: __BindgenUnionField<::std::os::raw::c_long>,
+ pub bindgen_union_field: u64,
+}
+#[test]
+fn bindgen_test_layout__bindgen_ty_1() {
+ assert_eq!(::core::mem::size_of::<_bindgen_ty_1>() , 8usize , concat ! (
+ "Size of: " , stringify ! ( _bindgen_ty_1 ) ));
+ assert_eq! (::core::mem::align_of::<_bindgen_ty_1>() , 8usize , concat ! (
+ "Alignment of " , stringify ! ( _bindgen_ty_1 ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const _bindgen_ty_1 ) ) . bar as * const _ as
+ usize } , 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
+ , stringify ! ( bar ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const _bindgen_ty_1 ) ) . baz as * const _ as
+ usize } , 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
+ , stringify ! ( baz ) ));
+}
+impl Clone for _bindgen_ty_1 {
+ fn clone(&self) -> Self { *self }
+}
+extern "C" {
+ #[link_name = "bazz"]
+ pub static mut bazz: _bindgen_ty_1;
+}
pub type fooFunction =
::core::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)>;
diff --git a/tests/headers/use-core.h b/tests/headers/use-core.h
index 42bb10d9..0e8a8d6e 100644
--- a/tests/headers/use-core.h
+++ b/tests/headers/use-core.h
@@ -5,4 +5,9 @@ struct foo {
void* bar;
};
+union {
+ int bar;
+ long baz;
+} bazz;
+
typedef void (*fooFunction)(int bar);