Skip to content

Commit e20f4c9

Browse files
author
bors-servo
authored
Auto merge of #248 - emilio:union-debug-again, r=fitzgen
codegen: Always implement debug for __BindgenUnionField. Our debug-detection code assumes so. Fixes #246 r? @fitzgen
2 parents d5a8fa2 + 89ee7e0 commit e20f4c9

20 files changed

+124
-19
lines changed

src/codegen/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1930,8 +1930,10 @@ mod utils {
19301930
pub fn prepend_union_types(ctx: &BindgenContext,
19311931
result: &mut Vec<P<ast::Item>>) {
19321932
let prefix = ctx.trait_prefix();
1933+
1934+
// TODO(emilio): The fmt::Debug impl could be way nicer with
1935+
// std::intrinsics::type_name, but...
19331936
let union_field_decl = quote_item!(ctx.ext_cx(),
1934-
#[derive(Debug)]
19351937
#[repr(C)]
19361938
pub struct __BindgenUnionField<T>(
19371939
::$prefix::marker::PhantomData<T>);
@@ -1983,11 +1985,22 @@ mod utils {
19831985
)
19841986
.unwrap();
19851987

1988+
let union_field_debug_impl = quote_item!(ctx.ext_cx(),
1989+
impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
1990+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter)
1991+
-> ::std::fmt::Result {
1992+
fmt.write_str("__BindgenUnionField")
1993+
}
1994+
}
1995+
)
1996+
.unwrap();
1997+
19861998
let items = vec![
19871999
union_field_decl, union_field_impl,
19882000
union_field_default_impl,
19892001
union_field_clone_impl,
19902002
union_field_copy_impl,
2003+
union_field_debug_impl,
19912004
];
19922005

19932006
let old_items = mem::replace(result, items);

tests/expectations/tests/anon_union.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy, Clone)]
2933
pub struct TErrorResult<T> {

tests/expectations/tests/class.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
pub struct C {
2933
pub a: ::std::os::raw::c_int,

tests/expectations/tests/class_with_inner_struct.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct A {

tests/expectations/tests/jsval_layout_opaque.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47;
2832
pub const JSVAL_PAYLOAD_MASK: ::std::os::raw::c_ulonglong = 140737488355327;
2933
pub const JSVAL_TAG_MASK: ::std::os::raw::c_longlong = -140737488355328;

tests/expectations/tests/struct_with_anon_union.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct foo {

tests/expectations/tests/struct_with_anon_unnamed_union.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct foo {

tests/expectations/tests/struct_with_nesting.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct foo {

tests/expectations/tests/typeref.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct nsFoo {

tests/expectations/tests/union_dtor.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug)]
2933
pub struct UnionWithDtor {

tests/expectations/tests/union_fields.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct _bindgen_ty_1 {

tests/expectations/tests/union_template.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy, Clone)]
2933
pub struct NastyStruct<T> {

tests/expectations/tests/union_with_anon_struct.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct foo {

tests/expectations/tests/union_with_anon_struct_bitfield.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct foo {

tests/expectations/tests/union_with_anon_union.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct foo {

tests/expectations/tests/union_with_anon_unnamed_struct.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct pixel {

tests/expectations/tests/union_with_anon_unnamed_union.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Debug, Copy)]
2933
pub struct foo {

tests/expectations/tests/union_with_big_member.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(non_snake_case)]
55

66

7-
#[derive(Debug)]
87
#[repr(C)]
98
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
109
impl <T> __BindgenUnionField<T> {
@@ -24,6 +23,11 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2423
fn clone(&self) -> Self { Self::new() }
2524
}
2625
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
2731
#[repr(C)]
2832
#[derive(Copy)]
2933
pub struct WithBigArray {
@@ -40,6 +44,21 @@ impl Clone for WithBigArray {
4044
fn clone(&self) -> Self { *self }
4145
}
4246
#[repr(C)]
47+
#[derive(Debug, Copy)]
48+
pub struct WithBigArray2 {
49+
pub a: __BindgenUnionField<::std::os::raw::c_int>,
50+
pub b: __BindgenUnionField<[::std::os::raw::c_char; 33usize]>,
51+
pub bindgen_union_field: [u32; 9usize],
52+
}
53+
#[test]
54+
fn bindgen_test_layout_WithBigArray2() {
55+
assert_eq!(::std::mem::size_of::<WithBigArray2>() , 36usize);
56+
assert_eq!(::std::mem::align_of::<WithBigArray2>() , 4usize);
57+
}
58+
impl Clone for WithBigArray2 {
59+
fn clone(&self) -> Self { *self }
60+
}
61+
#[repr(C)]
4362
#[derive(Copy)]
4463
pub struct WithBigMember {
4564
pub a: __BindgenUnionField<::std::os::raw::c_int>,

0 commit comments

Comments
 (0)