diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index a0b26eadb6..3f7c87e84d 100755
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -1930,8 +1930,10 @@ mod utils {
pub fn prepend_union_types(ctx: &BindgenContext,
result: &mut Vec
>) {
let prefix = ctx.trait_prefix();
+
+ // TODO(emilio): The fmt::Debug impl could be way nicer with
+ // std::intrinsics::type_name, but...
let union_field_decl = quote_item!(ctx.ext_cx(),
- #[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(
::$prefix::marker::PhantomData);
@@ -1983,11 +1985,22 @@ mod utils {
)
.unwrap();
+ let union_field_debug_impl = quote_item!(ctx.ext_cx(),
+ impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter)
+ -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+ }
+ )
+ .unwrap();
+
let items = vec![
union_field_decl, union_field_impl,
union_field_default_impl,
union_field_clone_impl,
union_field_copy_impl,
+ union_field_debug_impl,
];
let old_items = mem::replace(result, items);
diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs
index 0b1da364a2..8af416c32c 100644
--- a/tests/expectations/tests/anon_union.rs
+++ b/tests/expectations/tests/anon_union.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct TErrorResult {
diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs
index 4f736342e6..579c24a44b 100644
--- a/tests/expectations/tests/class.rs
+++ b/tests/expectations/tests/class.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
pub struct C {
pub a: ::std::os::raw::c_int,
diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs
index ca8eb73b09..ab51396dbf 100644
--- a/tests/expectations/tests/class_with_inner_struct.rs
+++ b/tests/expectations/tests/class_with_inner_struct.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct A {
diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs
index fa611f2045..91f898af88 100644
--- a/tests/expectations/tests/jsval_layout_opaque.rs
+++ b/tests/expectations/tests/jsval_layout_opaque.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47;
pub const JSVAL_PAYLOAD_MASK: ::std::os::raw::c_ulonglong = 140737488355327;
pub const JSVAL_TAG_MASK: ::std::os::raw::c_longlong = -140737488355328;
diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs
index 7c4a7d82d4..0d2e937ac3 100644
--- a/tests/expectations/tests/struct_with_anon_union.rs
+++ b/tests/expectations/tests/struct_with_anon_union.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs
index 0763f5907a..2914eb41ff 100644
--- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs
+++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs
index 0aacb6b3d3..97a0949ea2 100644
--- a/tests/expectations/tests/struct_with_nesting.rs
+++ b/tests/expectations/tests/struct_with_nesting.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs
index a8fe14cdbe..da9441462c 100644
--- a/tests/expectations/tests/typeref.rs
+++ b/tests/expectations/tests/typeref.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct nsFoo {
diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs
index 4d1fa25a38..9be626ffa8 100644
--- a/tests/expectations/tests/union_dtor.rs
+++ b/tests/expectations/tests/union_dtor.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug)]
pub struct UnionWithDtor {
diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs
index 49bdca13b3..495e80f984 100644
--- a/tests/expectations/tests/union_fields.rs
+++ b/tests/expectations/tests/union_fields.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct _bindgen_ty_1 {
diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs
index 0114e30663..fc92afb83e 100644
--- a/tests/expectations/tests/union_template.rs
+++ b/tests/expectations/tests/union_template.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NastyStruct {
diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs
index 406dd231ed..f0a2151223 100644
--- a/tests/expectations/tests/union_with_anon_struct.rs
+++ b/tests/expectations/tests/union_with_anon_struct.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs
index 91d9fa5974..548b0dc48a 100644
--- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs
+++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs
index c7ca3411c6..9527855640 100644
--- a/tests/expectations/tests/union_with_anon_union.rs
+++ b/tests/expectations/tests/union_with_anon_union.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs
index 33d75affb6..2d6fab97b7 100644
--- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs
+++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct pixel {
diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs
index c47850f59e..eb214017fe 100644
--- a/tests/expectations/tests/union_with_anon_unnamed_union.rs
+++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs
index 521a5ff4c7..b921f33c95 100644
--- a/tests/expectations/tests/union_with_big_member.rs
+++ b/tests/expectations/tests/union_with_big_member.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Copy)]
pub struct WithBigArray {
@@ -40,6 +44,21 @@ impl Clone for WithBigArray {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct WithBigArray2 {
+ pub a: __BindgenUnionField<::std::os::raw::c_int>,
+ pub b: __BindgenUnionField<[::std::os::raw::c_char; 33usize]>,
+ pub bindgen_union_field: [u32; 9usize],
+}
+#[test]
+fn bindgen_test_layout_WithBigArray2() {
+ assert_eq!(::std::mem::size_of::() , 36usize);
+ assert_eq!(::std::mem::align_of::() , 4usize);
+}
+impl Clone for WithBigArray2 {
+ fn clone(&self) -> Self { *self }
+}
+#[repr(C)]
#[derive(Copy)]
pub struct WithBigMember {
pub a: __BindgenUnionField<::std::os::raw::c_int>,
diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs
index 6ed81adb49..61c08a2a3e 100644
--- a/tests/expectations/tests/union_with_nesting.rs
+++ b/tests/expectations/tests/union_with_nesting.rs
@@ -4,7 +4,6 @@
#![allow(non_snake_case)]
-#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField(::std::marker::PhantomData);
impl __BindgenUnionField {
@@ -24,6 +23,11 @@ impl ::std::clone::Clone for __BindgenUnionField {
fn clone(&self) -> Self { Self::new() }
}
impl ::std::marker::Copy for __BindgenUnionField { }
+impl ::std::fmt::Debug for __BindgenUnionField {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
diff --git a/tests/headers/union_with_big_member.h b/tests/headers/union_with_big_member.h
index 06682ef191..6347d6cad3 100644
--- a/tests/headers/union_with_big_member.h
+++ b/tests/headers/union_with_big_member.h
@@ -3,6 +3,11 @@ union WithBigArray {
int b[33];
};
+union WithBigArray2 {
+ int a;
+ char b[33];
+};
+
union WithBigMember {
int a;
union WithBigArray b;