Skip to content

codegen: Always implement debug for __BindgenUnionField. #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1930,8 +1930,10 @@ mod utils {
pub fn prepend_union_types(ctx: &BindgenContext,
result: &mut Vec<P<ast::Item>>) {
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<T>(
::$prefix::marker::PhantomData<T>);
Expand Down Expand Up @@ -1983,11 +1985,22 @@ 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 {
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);
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/anon_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct TErrorResult<T> {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
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,
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/class_with_inner_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct A {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/jsval_layout_opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
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;
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/struct_with_anon_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/struct_with_anon_unnamed_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/struct_with_nesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/typeref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct nsFoo {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/union_dtor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug)]
pub struct UnionWithDtor {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/union_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
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 {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/union_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NastyStruct<T> {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/union_with_anon_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/union_with_anon_struct_bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/union_with_anon_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/union_with_anon_unnamed_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct pixel {
Expand Down
6 changes: 5 additions & 1 deletion tests/expectations/tests/union_with_anon_unnamed_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
Expand Down
21 changes: 20 additions & 1 deletion tests/expectations/tests/union_with_big_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(non_snake_case)]


#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
Expand All @@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Copy)]
pub struct WithBigArray {
Expand All @@ -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::<WithBigArray2>() , 36usize);
assert_eq!(::std::mem::align_of::<WithBigArray2>() , 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>,
Expand Down
Loading