Skip to content

Commit 4e3ffc8

Browse files
Fixed logic error in codegen/mod.rs and updated tests
1 parent f6bb89e commit 4e3ffc8

File tree

65 files changed

+2249
-651
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2249
-651
lines changed

src/codegen/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ impl CodeGenerator for CompInfo {
14491449
ctx.options().derive_copy
14501450
{
14511451
derives.push("Copy");
1452-
if used_template_params.is_empty() {
1452+
if !used_template_params.is_empty() {
14531453
// FIXME: This requires extra logic if you have a big array in a
14541454
// templated struct. The reason for this is that the magic:
14551455
// fn clone(&self) -> Self { *self }

tests/expectations/tests/381-decltype-alias.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55

66

77
#[repr(C)]
8-
#[derive(Debug, Default, Copy, Clone)]
8+
#[derive(Debug, Default, Copy)]
99
pub struct std_allocator_traits {
1010
pub _address: u8,
1111
}
1212
pub type std_allocator_traits___size_type<_Alloc> = _Alloc;
13+
impl Clone for std_allocator_traits {
14+
fn clone(&self) -> Self {
15+
*self
16+
}
17+
}

tests/expectations/tests/anon_enum_trait.rs

+30-18
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,29 @@
55

66

77
#[repr(C)]
8-
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
8+
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
99
pub struct DataType {
1010
pub _address: u8,
1111
}
1212
pub type DataType_value_type<_Tp> = _Tp;
1313
pub type DataType_work_type<_Tp> = DataType_value_type<_Tp>;
1414
pub type DataType_channel_type<_Tp> = DataType_value_type<_Tp>;
1515
pub type DataType_vec_type<_Tp> = DataType_value_type<_Tp>;
16-
pub const DataType_generic_type: DataType__bindgen_ty_1 =
17-
DataType__bindgen_ty_1::generic_type;
18-
pub const DataType_depth: DataType__bindgen_ty_1 =
19-
DataType__bindgen_ty_1::generic_type;
20-
pub const DataType_channels: DataType__bindgen_ty_1 =
21-
DataType__bindgen_ty_1::generic_type;
22-
pub const DataType_fmt: DataType__bindgen_ty_1 =
23-
DataType__bindgen_ty_1::generic_type;
24-
pub const DataType_type_: DataType__bindgen_ty_1 =
25-
DataType__bindgen_ty_1::generic_type;
16+
pub const DataType_generic_type: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
17+
pub const DataType_depth: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
18+
pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
19+
pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
20+
pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
2621
#[repr(i32)]
2722
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
28-
pub enum DataType__bindgen_ty_1 { generic_type = 0, }
23+
pub enum DataType__bindgen_ty_1 {
24+
generic_type = 0,
25+
}
26+
impl Clone for DataType {
27+
fn clone(&self) -> Self {
28+
*self
29+
}
30+
}
2931
#[repr(C)]
3032
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
3133
pub struct Foo {
@@ -35,14 +37,24 @@ pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar;
3537
pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar;
3638
#[repr(u32)]
3739
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
38-
pub enum Foo__bindgen_ty_1 { Bar = 0, }
40+
pub enum Foo__bindgen_ty_1 {
41+
Bar = 0,
42+
}
3943
#[test]
4044
fn bindgen_test_layout_Foo() {
41-
assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
42-
"Size of: " , stringify ! ( Foo ) ));
43-
assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
44-
"Alignment of " , stringify ! ( Foo ) ));
45+
assert_eq!(
46+
::std::mem::size_of::<Foo>(),
47+
1usize,
48+
concat!("Size of: ", stringify!(Foo))
49+
);
50+
assert_eq!(
51+
::std::mem::align_of::<Foo>(),
52+
1usize,
53+
concat!("Alignment of ", stringify!(Foo))
54+
);
4555
}
4656
impl Clone for Foo {
47-
fn clone(&self) -> Self { *self }
57+
fn clone(&self) -> Self {
58+
*self
59+
}
4860
}

tests/expectations/tests/anon_union.rs

+73-18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
#[repr(C)]
8+
#[derive(Copy)]
89
pub struct TErrorResult {
910
pub mResult: ::std::os::raw::c_int,
1011
pub __bindgen_anon_1: TErrorResult__bindgen_ty_1,
@@ -15,49 +16,103 @@ pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState =
1516
TErrorResult_UnionState::HasMessage;
1617
#[repr(i32)]
1718
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
18-
pub enum TErrorResult_UnionState { HasMessage = 0, }
19+
pub enum TErrorResult_UnionState {
20+
HasMessage = 0,
21+
}
1922
#[repr(C)]
20-
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
23+
#[derive(Debug, Copy, Clone)]
2124
pub struct TErrorResult_Message {
22-
pub _address: u8,
25+
_unused: [u8; 0],
2326
}
2427
#[repr(C)]
25-
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
28+
#[derive(Debug, Copy, Clone)]
2629
pub struct TErrorResult_DOMExceptionInfo {
27-
pub _address: u8,
30+
_unused: [u8; 0],
2831
}
2932
#[repr(C)]
33+
#[derive(Copy)]
3034
pub union TErrorResult__bindgen_ty_1 {
3135
pub mMessage: *mut TErrorResult_Message,
3236
pub mDOMExceptionInfo: *mut TErrorResult_DOMExceptionInfo,
3337
_bindgen_union_align: u64,
3438
}
39+
#[test]
40+
fn bindgen_test_layout_TErrorResult__bindgen_ty_1() {
41+
assert_eq!(
42+
::std::mem::size_of::<TErrorResult__bindgen_ty_1>(),
43+
8usize,
44+
concat!("Size of: ", stringify!(TErrorResult__bindgen_ty_1))
45+
);
46+
assert_eq!(
47+
::std::mem::align_of::<TErrorResult__bindgen_ty_1>(),
48+
8usize,
49+
concat!("Alignment of ", stringify!(TErrorResult__bindgen_ty_1))
50+
);
51+
}
52+
impl Clone for TErrorResult__bindgen_ty_1 {
53+
fn clone(&self) -> Self {
54+
*self
55+
}
56+
}
3557
impl Default for TErrorResult__bindgen_ty_1 {
36-
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
58+
fn default() -> Self {
59+
unsafe { ::std::mem::zeroed() }
60+
}
61+
}
62+
impl Clone for TErrorResult {
63+
fn clone(&self) -> Self {
64+
*self
65+
}
3766
}
3867
impl Default for TErrorResult {
39-
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
68+
fn default() -> Self {
69+
unsafe { ::std::mem::zeroed() }
70+
}
4071
}
4172
#[repr(C)]
73+
#[derive(Copy)]
4274
pub struct ErrorResult {
4375
pub _base: TErrorResult,
4476
}
4577
#[test]
4678
fn bindgen_test_layout_ErrorResult() {
47-
assert_eq!(::std::mem::size_of::<ErrorResult>() , 24usize , concat ! (
48-
"Size of: " , stringify ! ( ErrorResult ) ));
49-
assert_eq! (::std::mem::align_of::<ErrorResult>() , 8usize , concat ! (
50-
"Alignment of " , stringify ! ( ErrorResult ) ));
79+
assert_eq!(
80+
::std::mem::size_of::<ErrorResult>(),
81+
24usize,
82+
concat!("Size of: ", stringify!(ErrorResult))
83+
);
84+
assert_eq!(
85+
::std::mem::align_of::<ErrorResult>(),
86+
8usize,
87+
concat!("Alignment of ", stringify!(ErrorResult))
88+
);
89+
}
90+
impl Clone for ErrorResult {
91+
fn clone(&self) -> Self {
92+
*self
93+
}
5194
}
5295
impl Default for ErrorResult {
53-
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
96+
fn default() -> Self {
97+
unsafe { ::std::mem::zeroed() }
98+
}
5499
}
55100
#[test]
56101
fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() {
57-
assert_eq!(::std::mem::size_of::<TErrorResult>() , 24usize , concat ! (
58-
"Size of template specialization: " , stringify ! (
59-
TErrorResult ) ));
60-
assert_eq!(::std::mem::align_of::<TErrorResult>() , 8usize , concat ! (
61-
"Alignment of template specialization: " , stringify ! (
62-
TErrorResult ) ));
102+
assert_eq!(
103+
::std::mem::size_of::<TErrorResult>(),
104+
24usize,
105+
concat!(
106+
"Size of template specialization: ",
107+
stringify!(TErrorResult)
108+
)
109+
);
110+
assert_eq!(
111+
::std::mem::align_of::<TErrorResult>(),
112+
8usize,
113+
concat!(
114+
"Alignment of template specialization: ",
115+
stringify!(TErrorResult)
116+
)
117+
);
63118
}

0 commit comments

Comments
 (0)