Skip to content

Commit 896e47a

Browse files
committed
swap offset assert and place expect value on right
1 parent ca3949f commit 896e47a

File tree

83 files changed

+873
-820
lines changed

Some content is hidden

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

83 files changed

+873
-820
lines changed

src/codegen/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,10 +1359,9 @@ impl CodeGenerator for CompInfo {
13591359
// FIXME when [issue #465](https://github.com/servo/rust-bindgen/issues/465) ready
13601360
let too_many_base_vtables = self.base_members()
13611361
.iter()
1362-
.filter(|base| {
1363-
ctx.resolve_type(base.ty).has_vtable(ctx)
1364-
})
1365-
.count() > 1;
1362+
.filter(|base| ctx.resolve_type(base.ty).has_vtable(ctx))
1363+
.count() >
1364+
1;
13661365

13671366
let should_skip_field_offset_checks = item.is_opaque(ctx) ||
13681367
too_many_base_vtables;
@@ -1382,7 +1381,7 @@ impl CodeGenerator for CompInfo {
13821381
let field_name = ctx.rust_ident(name);
13831382

13841383
quote_item!(ctx.ext_cx(),
1385-
assert_eq!($field_offset, unsafe { &(*(0 as *const $type_name)).$field_name as *const _ as usize });
1384+
assert_eq!(unsafe { &(*(0 as *const $type_name)).$field_name as *const _ as usize }, $field_offset);
13861385
)
13871386
})
13881387
})

tests/expectations/tests/16-byte-alignment.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
5454
, 4usize);
5555
assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>()
5656
, 2usize);
57-
assert_eq! (0usize , unsafe {
57+
assert_eq! (unsafe {
5858
& (
5959
* ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 )
60-
) . dport as * const _ as usize });
61-
assert_eq! (2usize , unsafe {
60+
) . dport as * const _ as usize } , 0usize);
61+
assert_eq! (unsafe {
6262
& (
6363
* ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 )
64-
) . sport as * const _ as usize });
64+
) . sport as * const _ as usize } , 2usize);
6565
}
6666
impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 {
6767
fn clone(&self) -> Self { *self }
@@ -72,9 +72,9 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() {
7272
4usize);
7373
assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1>() ,
7474
4usize);
75-
assert_eq! (0usize , unsafe {
75+
assert_eq! (unsafe {
7676
& ( * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1 ) ) .
77-
sctp_tag as * const _ as usize });
77+
sctp_tag as * const _ as usize } , 0usize);
7878
}
7979
impl Clone for rte_ipv4_tuple__bindgen_ty_1 {
8080
fn clone(&self) -> Self { *self }
@@ -83,12 +83,12 @@ impl Clone for rte_ipv4_tuple__bindgen_ty_1 {
8383
fn bindgen_test_layout_rte_ipv4_tuple() {
8484
assert_eq!(::std::mem::size_of::<rte_ipv4_tuple>() , 12usize);
8585
assert_eq! (::std::mem::align_of::<rte_ipv4_tuple>() , 4usize);
86-
assert_eq! (0usize , unsafe {
86+
assert_eq! (unsafe {
8787
& ( * ( 0 as * const rte_ipv4_tuple ) ) . src_addr as * const
88-
_ as usize });
89-
assert_eq! (4usize , unsafe {
88+
_ as usize } , 0usize);
89+
assert_eq! (unsafe {
9090
& ( * ( 0 as * const rte_ipv4_tuple ) ) . dst_addr as * const
91-
_ as usize });
91+
_ as usize } , 4usize);
9292
}
9393
impl Clone for rte_ipv4_tuple {
9494
fn clone(&self) -> Self { *self }
@@ -119,14 +119,14 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
119119
, 4usize);
120120
assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>()
121121
, 2usize);
122-
assert_eq! (0usize , unsafe {
122+
assert_eq! (unsafe {
123123
& (
124124
* ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 )
125-
) . dport as * const _ as usize });
126-
assert_eq! (2usize , unsafe {
125+
) . dport as * const _ as usize } , 0usize);
126+
assert_eq! (unsafe {
127127
& (
128128
* ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 )
129-
) . sport as * const _ as usize });
129+
) . sport as * const _ as usize } , 2usize);
130130
}
131131
impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 {
132132
fn clone(&self) -> Self { *self }
@@ -137,9 +137,9 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() {
137137
4usize);
138138
assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1>() ,
139139
4usize);
140-
assert_eq! (0usize , unsafe {
140+
assert_eq! (unsafe {
141141
& ( * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1 ) ) .
142-
sctp_tag as * const _ as usize });
142+
sctp_tag as * const _ as usize } , 0usize);
143143
}
144144
impl Clone for rte_ipv6_tuple__bindgen_ty_1 {
145145
fn clone(&self) -> Self { *self }
@@ -148,12 +148,12 @@ impl Clone for rte_ipv6_tuple__bindgen_ty_1 {
148148
fn bindgen_test_layout_rte_ipv6_tuple() {
149149
assert_eq!(::std::mem::size_of::<rte_ipv6_tuple>() , 36usize);
150150
assert_eq! (::std::mem::align_of::<rte_ipv6_tuple>() , 4usize);
151-
assert_eq! (0usize , unsafe {
151+
assert_eq! (unsafe {
152152
& ( * ( 0 as * const rte_ipv6_tuple ) ) . src_addr as * const
153-
_ as usize });
154-
assert_eq! (16usize , unsafe {
153+
_ as usize } , 0usize);
154+
assert_eq! (unsafe {
155155
& ( * ( 0 as * const rte_ipv6_tuple ) ) . dst_addr as * const
156-
_ as usize });
156+
_ as usize } , 16usize);
157157
}
158158
impl Clone for rte_ipv6_tuple {
159159
fn clone(&self) -> Self { *self }
@@ -168,12 +168,12 @@ pub struct rte_thash_tuple {
168168
#[test]
169169
fn bindgen_test_layout_rte_thash_tuple() {
170170
assert_eq!(::std::mem::size_of::<rte_thash_tuple>() , 48usize);
171-
assert_eq! (0usize , unsafe {
171+
assert_eq! (unsafe {
172172
& ( * ( 0 as * const rte_thash_tuple ) ) . v4 as * const _ as
173-
usize });
174-
assert_eq! (0usize , unsafe {
173+
usize } , 0usize);
174+
assert_eq! (unsafe {
175175
& ( * ( 0 as * const rte_thash_tuple ) ) . v6 as * const _ as
176-
usize });
176+
usize } , 0usize);
177177
}
178178
impl Clone for rte_thash_tuple {
179179
fn clone(&self) -> Self { *self }

tests/expectations/tests/accessors.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ pub struct SomeAccessors {
1919
fn bindgen_test_layout_SomeAccessors() {
2020
assert_eq!(::std::mem::size_of::<SomeAccessors>() , 16usize);
2121
assert_eq! (::std::mem::align_of::<SomeAccessors>() , 4usize);
22-
assert_eq! (0usize , unsafe {
22+
assert_eq! (unsafe {
2323
& ( * ( 0 as * const SomeAccessors ) ) . mNoAccessor as *
24-
const _ as usize });
25-
assert_eq! (4usize , unsafe {
24+
const _ as usize } , 0usize);
25+
assert_eq! (unsafe {
2626
& ( * ( 0 as * const SomeAccessors ) ) . mBothAccessors as *
27-
const _ as usize });
28-
assert_eq! (8usize , unsafe {
27+
const _ as usize } , 4usize);
28+
assert_eq! (unsafe {
2929
& ( * ( 0 as * const SomeAccessors ) ) . mUnsafeAccessors as *
30-
const _ as usize });
31-
assert_eq! (12usize , unsafe {
30+
const _ as usize } , 8usize);
31+
assert_eq! (unsafe {
3232
& ( * ( 0 as * const SomeAccessors ) ) . mImmutableAccessor as
33-
* const _ as usize });
33+
* const _ as usize } , 12usize);
3434
}
3535
impl Clone for SomeAccessors {
3636
fn clone(&self) -> Self { *self }
@@ -69,12 +69,12 @@ pub struct AllAccessors {
6969
fn bindgen_test_layout_AllAccessors() {
7070
assert_eq!(::std::mem::size_of::<AllAccessors>() , 8usize);
7171
assert_eq! (::std::mem::align_of::<AllAccessors>() , 4usize);
72-
assert_eq! (0usize , unsafe {
72+
assert_eq! (unsafe {
7373
& ( * ( 0 as * const AllAccessors ) ) . mBothAccessors as *
74-
const _ as usize });
75-
assert_eq! (4usize , unsafe {
74+
const _ as usize } , 0usize);
75+
assert_eq! (unsafe {
7676
& ( * ( 0 as * const AllAccessors ) ) . mAlsoBothAccessors as
77-
* const _ as usize });
77+
* const _ as usize } , 4usize);
7878
}
7979
impl Clone for AllAccessors {
8080
fn clone(&self) -> Self { *self }
@@ -109,12 +109,12 @@ pub struct AllUnsafeAccessors {
109109
fn bindgen_test_layout_AllUnsafeAccessors() {
110110
assert_eq!(::std::mem::size_of::<AllUnsafeAccessors>() , 8usize);
111111
assert_eq! (::std::mem::align_of::<AllUnsafeAccessors>() , 4usize);
112-
assert_eq! (0usize , unsafe {
112+
assert_eq! (unsafe {
113113
& ( * ( 0 as * const AllUnsafeAccessors ) ) . mBothAccessors
114-
as * const _ as usize });
115-
assert_eq! (4usize , unsafe {
114+
as * const _ as usize } , 0usize);
115+
assert_eq! (unsafe {
116116
& ( * ( 0 as * const AllUnsafeAccessors ) ) .
117-
mAlsoBothAccessors as * const _ as usize });
117+
mAlsoBothAccessors as * const _ as usize } , 4usize);
118118
}
119119
impl Clone for AllUnsafeAccessors {
120120
fn clone(&self) -> Self { *self }
@@ -155,18 +155,18 @@ pub struct ContradictAccessors {
155155
fn bindgen_test_layout_ContradictAccessors() {
156156
assert_eq!(::std::mem::size_of::<ContradictAccessors>() , 16usize);
157157
assert_eq! (::std::mem::align_of::<ContradictAccessors>() , 4usize);
158-
assert_eq! (0usize , unsafe {
158+
assert_eq! (unsafe {
159159
& ( * ( 0 as * const ContradictAccessors ) ) . mBothAccessors
160-
as * const _ as usize });
161-
assert_eq! (4usize , unsafe {
160+
as * const _ as usize } , 0usize);
161+
assert_eq! (unsafe {
162162
& ( * ( 0 as * const ContradictAccessors ) ) . mNoAccessors as
163-
* const _ as usize });
164-
assert_eq! (8usize , unsafe {
163+
* const _ as usize } , 4usize);
164+
assert_eq! (unsafe {
165165
& ( * ( 0 as * const ContradictAccessors ) ) .
166-
mUnsafeAccessors as * const _ as usize });
167-
assert_eq! (12usize , unsafe {
166+
mUnsafeAccessors as * const _ as usize } , 8usize);
167+
assert_eq! (unsafe {
168168
& ( * ( 0 as * const ContradictAccessors ) ) .
169-
mImmutableAccessor as * const _ as usize });
169+
mImmutableAccessor as * const _ as usize } , 12usize);
170170
}
171171
impl Clone for ContradictAccessors {
172172
fn clone(&self) -> Self { *self }
@@ -204,9 +204,9 @@ pub struct Replaced {
204204
fn bindgen_test_layout_Replaced() {
205205
assert_eq!(::std::mem::size_of::<Replaced>() , 4usize);
206206
assert_eq! (::std::mem::align_of::<Replaced>() , 4usize);
207-
assert_eq! (0usize , unsafe {
207+
assert_eq! (unsafe {
208208
& ( * ( 0 as * const Replaced ) ) . mAccessor as * const _ as
209-
usize });
209+
usize } , 0usize);
210210
}
211211
impl Clone for Replaced {
212212
fn clone(&self) -> Self { *self }
@@ -229,9 +229,9 @@ pub struct Wrapper {
229229
fn bindgen_test_layout_Wrapper() {
230230
assert_eq!(::std::mem::size_of::<Wrapper>() , 4usize);
231231
assert_eq! (::std::mem::align_of::<Wrapper>() , 4usize);
232-
assert_eq! (0usize , unsafe {
232+
assert_eq! (unsafe {
233233
& ( * ( 0 as * const Wrapper ) ) . mReplaced as * const _ as
234-
usize });
234+
usize } , 0usize);
235235
}
236236
impl Clone for Wrapper {
237237
fn clone(&self) -> Self { *self }

tests/expectations/tests/annotation_hide.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ pub struct NotAnnotated {
2929
fn bindgen_test_layout_NotAnnotated() {
3030
assert_eq!(::std::mem::size_of::<NotAnnotated>() , 4usize);
3131
assert_eq! (::std::mem::align_of::<NotAnnotated>() , 4usize);
32-
assert_eq! (0usize , unsafe {
32+
assert_eq! (unsafe {
3333
& ( * ( 0 as * const NotAnnotated ) ) . f as * const _ as
34-
usize });
34+
usize } , 0usize);
3535
}
3636
impl Clone for NotAnnotated {
3737
fn clone(&self) -> Self { *self }

tests/expectations/tests/anon_enum.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ pub enum Test__bindgen_ty_1 { T_NONE = 0, }
1818
fn bindgen_test_layout_Test() {
1919
assert_eq!(::std::mem::size_of::<Test>() , 8usize);
2020
assert_eq! (::std::mem::align_of::<Test>() , 4usize);
21-
assert_eq! (0usize , unsafe {
22-
& ( * ( 0 as * const Test ) ) . foo as * const _ as usize });
23-
assert_eq! (4usize , unsafe {
24-
& ( * ( 0 as * const Test ) ) . bar as * const _ as usize });
21+
assert_eq! (unsafe {
22+
& ( * ( 0 as * const Test ) ) . foo as * const _ as usize } ,
23+
0usize);
24+
assert_eq! (unsafe {
25+
& ( * ( 0 as * const Test ) ) . bar as * const _ as usize } ,
26+
4usize);
2527
}
2628
impl Clone for Test {
2729
fn clone(&self) -> Self { *self }

tests/expectations/tests/class.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ pub struct C {
6969
fn bindgen_test_layout_C() {
7070
assert_eq!(::std::mem::size_of::<C>() , 40usize);
7171
assert_eq! (::std::mem::align_of::<C>() , 4usize);
72-
assert_eq! (0usize , unsafe {
73-
& ( * ( 0 as * const C ) ) . a as * const _ as usize });
74-
assert_eq! (4usize , unsafe {
75-
& ( * ( 0 as * const C ) ) . big_array as * const _ as usize
76-
});
72+
assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . a as * const _ as usize
73+
} , 0usize);
74+
assert_eq! (unsafe {
75+
& ( * ( 0 as * const C ) ) . big_array as * const _ as usize }
76+
, 4usize);
7777
}
7878
#[repr(C)]
7979
pub struct C_with_zero_length_array {
@@ -85,15 +85,15 @@ pub struct C_with_zero_length_array {
8585
fn bindgen_test_layout_C_with_zero_length_array() {
8686
assert_eq!(::std::mem::size_of::<C_with_zero_length_array>() , 40usize);
8787
assert_eq! (::std::mem::align_of::<C_with_zero_length_array>() , 4usize);
88-
assert_eq! (0usize , unsafe {
88+
assert_eq! (unsafe {
8989
& ( * ( 0 as * const C_with_zero_length_array ) ) . a as *
90-
const _ as usize });
91-
assert_eq! (4usize , unsafe {
90+
const _ as usize } , 0usize);
91+
assert_eq! (unsafe {
9292
& ( * ( 0 as * const C_with_zero_length_array ) ) . big_array
93-
as * const _ as usize });
94-
assert_eq! (37usize , unsafe {
93+
as * const _ as usize } , 4usize);
94+
assert_eq! (unsafe {
9595
& ( * ( 0 as * const C_with_zero_length_array ) ) .
96-
zero_length_array as * const _ as usize });
96+
zero_length_array as * const _ as usize } , 37usize);
9797
}
9898
#[repr(C)]
9999
pub struct C_with_incomplete_array {
@@ -129,9 +129,9 @@ pub struct WithDtor {
129129
fn bindgen_test_layout_WithDtor() {
130130
assert_eq!(::std::mem::size_of::<WithDtor>() , 4usize);
131131
assert_eq! (::std::mem::align_of::<WithDtor>() , 4usize);
132-
assert_eq! (0usize , unsafe {
133-
& ( * ( 0 as * const WithDtor ) ) . b as * const _ as usize
134-
});
132+
assert_eq! (unsafe {
133+
& ( * ( 0 as * const WithDtor ) ) . b as * const _ as usize }
134+
, 0usize);
135135
}
136136
#[repr(C)]
137137
pub struct IncompleteArrayNonCopiable {
@@ -155,10 +155,12 @@ pub struct Union {
155155
fn bindgen_test_layout_Union() {
156156
assert_eq!(::std::mem::size_of::<Union>() , 4usize);
157157
assert_eq! (::std::mem::align_of::<Union>() , 4usize);
158-
assert_eq! (0usize , unsafe {
159-
& ( * ( 0 as * const Union ) ) . d as * const _ as usize });
160-
assert_eq! (0usize , unsafe {
161-
& ( * ( 0 as * const Union ) ) . i as * const _ as usize });
158+
assert_eq! (unsafe {
159+
& ( * ( 0 as * const Union ) ) . d as * const _ as usize } ,
160+
0usize);
161+
assert_eq! (unsafe {
162+
& ( * ( 0 as * const Union ) ) . i as * const _ as usize } ,
163+
0usize);
162164
}
163165
impl Clone for Union {
164166
fn clone(&self) -> Self { *self }
@@ -172,9 +174,9 @@ pub struct WithUnion {
172174
fn bindgen_test_layout_WithUnion() {
173175
assert_eq!(::std::mem::size_of::<WithUnion>() , 4usize);
174176
assert_eq! (::std::mem::align_of::<WithUnion>() , 4usize);
175-
assert_eq! (0usize , unsafe {
177+
assert_eq! (unsafe {
176178
& ( * ( 0 as * const WithUnion ) ) . data as * const _ as
177-
usize });
179+
usize } , 0usize);
178180
}
179181
impl Clone for WithUnion {
180182
fn clone(&self) -> Self { *self }

tests/expectations/tests/class_nested.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ pub struct A_B {
1818
fn bindgen_test_layout_A_B() {
1919
assert_eq!(::std::mem::size_of::<A_B>() , 4usize);
2020
assert_eq! (::std::mem::align_of::<A_B>() , 4usize);
21-
assert_eq! (0usize , unsafe {
21+
assert_eq! (unsafe {
2222
& ( * ( 0 as * const A_B ) ) . member_b as * const _ as usize
23-
});
23+
} , 0usize);
2424
}
2525
impl Clone for A_B {
2626
fn clone(&self) -> Self { *self }
@@ -29,9 +29,9 @@ impl Clone for A_B {
2929
fn bindgen_test_layout_A() {
3030
assert_eq!(::std::mem::size_of::<A>() , 4usize);
3131
assert_eq! (::std::mem::align_of::<A>() , 4usize);
32-
assert_eq! (0usize , unsafe {
33-
& ( * ( 0 as * const A ) ) . member_a as * const _ as usize
34-
});
32+
assert_eq! (unsafe {
33+
& ( * ( 0 as * const A ) ) . member_a as * const _ as usize }
34+
, 0usize);
3535
}
3636
impl Clone for A {
3737
fn clone(&self) -> Self { *self }
@@ -49,8 +49,9 @@ pub struct D {
4949
fn bindgen_test_layout_D() {
5050
assert_eq!(::std::mem::size_of::<D>() , 4usize);
5151
assert_eq! (::std::mem::align_of::<D>() , 4usize);
52-
assert_eq! (0usize , unsafe {
53-
& ( * ( 0 as * const D ) ) . member as * const _ as usize });
52+
assert_eq! (unsafe {
53+
& ( * ( 0 as * const D ) ) . member as * const _ as usize } ,
54+
0usize);
5455
}
5556
impl Clone for D {
5657
fn clone(&self) -> Self { *self }

0 commit comments

Comments
 (0)