Skip to content

Commit 16cc5bf

Browse files
author
bors-servo
authored
Auto merge of #487 - emilio:assertion-messages, r=fitzgen
codegen: Improve the assertion message of failing layout tests. r? @fitzgen cc @flier
2 parents f5394b3 + 193a103 commit 16cc5bf

File tree

117 files changed

+2526
-975
lines changed

Some content is hidden

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

117 files changed

+2526
-975
lines changed

src/codegen/mod.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,10 @@ impl CodeGenerator for CompInfo {
866866
let item = quote_item!(ctx.ext_cx(),
867867
#[test]
868868
fn $fn_name() {
869-
assert_eq!($size_of_expr, $size);
870-
assert_eq!($align_of_expr, $align);
869+
assert_eq!($size_of_expr, $size,
870+
concat!("Size of template specialization: ", stringify!($ident)));
871+
assert_eq!($align_of_expr, $align,
872+
concat!("Alignment of template specialization: ", stringify!($ident)));
871873
})
872874
.unwrap();
873875
result.push(item);
@@ -1339,12 +1341,12 @@ impl CodeGenerator for CompInfo {
13391341
if let Some(layout) = layout {
13401342
let fn_name = format!("bindgen_test_layout_{}", canonical_name);
13411343
let fn_name = ctx.rust_ident_raw(&fn_name);
1342-
let ident = ctx.rust_ident_raw(&canonical_name);
1344+
let type_name = ctx.rust_ident_raw(&canonical_name);
13431345
let prefix = ctx.trait_prefix();
13441346
let size_of_expr = quote_expr!(ctx.ext_cx(),
1345-
::$prefix::mem::size_of::<$ident>());
1347+
::$prefix::mem::size_of::<$type_name>());
13461348
let align_of_expr = quote_expr!(ctx.ext_cx(),
1347-
::$prefix::mem::align_of::<$ident>());
1349+
::$prefix::mem::align_of::<$type_name>());
13481350
let size = layout.size;
13491351
let align = layout.align;
13501352

@@ -1353,7 +1355,9 @@ impl CodeGenerator for CompInfo {
13531355
None
13541356
} else {
13551357
quote_item!(ctx.ext_cx(),
1356-
assert_eq!($align_of_expr, $align);
1358+
assert_eq!($align_of_expr,
1359+
$align,
1360+
concat!("Alignment of ", stringify!($type_name)));
13571361
)
13581362
};
13591363

@@ -1370,8 +1374,6 @@ impl CodeGenerator for CompInfo {
13701374
let check_field_offset = if should_skip_field_offset_checks {
13711375
None
13721376
} else {
1373-
let type_name = ctx.rust_ident(&canonical_name);
1374-
13751377
let asserts = self.fields()
13761378
.iter()
13771379
.filter(|field| field.bitfield().is_none())
@@ -1382,7 +1384,9 @@ impl CodeGenerator for CompInfo {
13821384
let field_name = ctx.rust_ident(name);
13831385

13841386
quote_item!(ctx.ext_cx(),
1385-
assert_eq!(unsafe { &(*(0 as *const $type_name)).$field_name as *const _ as usize }, $field_offset);
1387+
assert_eq!(unsafe { &(*(0 as *const $type_name)).$field_name as *const _ as usize },
1388+
$field_offset,
1389+
concat!("Alignment of field: ", stringify!($type_name), "::", stringify!($field_name)));
13861390
)
13871391
})
13881392
})
@@ -1394,7 +1398,9 @@ impl CodeGenerator for CompInfo {
13941398
let item = quote_item!(ctx.ext_cx(),
13951399
#[test]
13961400
fn $fn_name() {
1397-
assert_eq!($size_of_expr, $size);
1401+
assert_eq!($size_of_expr,
1402+
$size,
1403+
concat!("Size of: ", stringify!($type_name)));
13981404

13991405
$check_struct_align
14001406
$check_field_offset
@@ -2137,7 +2143,7 @@ impl ToRustTy for Type {
21372143
.map(|arg| arg.to_rust_ty(ctx))
21382144
.collect::<Vec<_>>();
21392145

2140-
path.segments.last_mut().unwrap().parameters = if
2146+
path.segments.last_mut().unwrap().parameters = if
21412147
template_args.is_empty() {
21422148
None
21432149
} else {
@@ -2458,12 +2464,12 @@ mod utils {
24582464
use aster;
24592465
use ir::context::{BindgenContext, ItemId};
24602466
use ir::item::{Item, ItemCanonicalPath};
2467+
use ir::function::FunctionSig;
24612468
use ir::ty::TypeKind;
24622469
use std::mem;
24632470
use syntax::ast;
24642471
use syntax::ptr::P;
24652472

2466-
24672473
pub fn prepend_objc_header(ctx: &BindgenContext,
24682474
result: &mut Vec<P<ast::Item>>) {
24692475
let use_objc = if ctx.options().objc_extern_crate {
@@ -2745,7 +2751,7 @@ mod utils {
27452751
}
27462752

27472753
pub fn fnsig_return_ty(ctx: &BindgenContext,
2748-
sig: &super::FunctionSig)
2754+
sig: &FunctionSig)
27492755
-> ast::FunctionRetTy {
27502756
let return_item = ctx.resolve_item(sig.return_type());
27512757
if let TypeKind::Void = *return_item.kind().expect_type().kind() {
@@ -2756,7 +2762,7 @@ mod utils {
27562762
}
27572763

27582764
pub fn fnsig_arguments(ctx: &BindgenContext,
2759-
sig: &super::FunctionSig)
2765+
sig: &FunctionSig)
27602766
-> Vec<ast::Arg> {
27612767
use super::ToPtr;
27622768
let mut unnamed_arguments = 0;

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

+76-27
Original file line numberDiff line numberDiff line change
@@ -51,44 +51,66 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 {
5151
#[test]
5252
fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
5353
assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>()
54-
, 4usize);
54+
, 4usize , concat ! (
55+
"Size of: " , stringify ! (
56+
rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
5557
assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>()
56-
, 2usize);
58+
, 2usize , concat ! (
59+
"Alignment of " , stringify ! (
60+
rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
5761
assert_eq! (unsafe {
5862
& (
5963
* ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 )
60-
) . dport as * const _ as usize } , 0usize);
64+
) . dport as * const _ as usize } , 0usize , concat ! (
65+
"Alignment of field: " , stringify ! (
66+
rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
67+
stringify ! ( dport ) ));
6168
assert_eq! (unsafe {
6269
& (
6370
* ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 )
64-
) . sport as * const _ as usize } , 2usize);
71+
) . sport as * const _ as usize } , 2usize , concat ! (
72+
"Alignment of field: " , stringify ! (
73+
rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
74+
stringify ! ( sport ) ));
6575
}
6676
impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 {
6777
fn clone(&self) -> Self { *self }
6878
}
6979
#[test]
7080
fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() {
71-
assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1>() ,
72-
4usize);
81+
assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1>() , 4usize
82+
, concat ! (
83+
"Size of: " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 ) ));
7384
assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1>() ,
74-
4usize);
85+
4usize , concat ! (
86+
"Alignment of " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 )
87+
));
7588
assert_eq! (unsafe {
7689
& ( * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1 ) ) .
77-
sctp_tag as * const _ as usize } , 0usize);
90+
sctp_tag as * const _ as usize } , 0usize , concat ! (
91+
"Alignment of field: " , stringify ! (
92+
rte_ipv4_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag
93+
) ));
7894
}
7995
impl Clone for rte_ipv4_tuple__bindgen_ty_1 {
8096
fn clone(&self) -> Self { *self }
8197
}
8298
#[test]
8399
fn bindgen_test_layout_rte_ipv4_tuple() {
84-
assert_eq!(::std::mem::size_of::<rte_ipv4_tuple>() , 12usize);
85-
assert_eq! (::std::mem::align_of::<rte_ipv4_tuple>() , 4usize);
100+
assert_eq!(::std::mem::size_of::<rte_ipv4_tuple>() , 12usize , concat ! (
101+
"Size of: " , stringify ! ( rte_ipv4_tuple ) ));
102+
assert_eq! (::std::mem::align_of::<rte_ipv4_tuple>() , 4usize , concat ! (
103+
"Alignment of " , stringify ! ( rte_ipv4_tuple ) ));
86104
assert_eq! (unsafe {
87105
& ( * ( 0 as * const rte_ipv4_tuple ) ) . src_addr as * const
88-
_ as usize } , 0usize);
106+
_ as usize } , 0usize , concat ! (
107+
"Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::"
108+
, stringify ! ( src_addr ) ));
89109
assert_eq! (unsafe {
90110
& ( * ( 0 as * const rte_ipv4_tuple ) ) . dst_addr as * const
91-
_ as usize } , 4usize);
111+
_ as usize } , 4usize , concat ! (
112+
"Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::"
113+
, stringify ! ( dst_addr ) ));
92114
}
93115
impl Clone for rte_ipv4_tuple {
94116
fn clone(&self) -> Self { *self }
@@ -116,44 +138,66 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 {
116138
#[test]
117139
fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
118140
assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>()
119-
, 4usize);
141+
, 4usize , concat ! (
142+
"Size of: " , stringify ! (
143+
rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
120144
assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>()
121-
, 2usize);
145+
, 2usize , concat ! (
146+
"Alignment of " , stringify ! (
147+
rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
122148
assert_eq! (unsafe {
123149
& (
124150
* ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 )
125-
) . dport as * const _ as usize } , 0usize);
151+
) . dport as * const _ as usize } , 0usize , concat ! (
152+
"Alignment of field: " , stringify ! (
153+
rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
154+
stringify ! ( dport ) ));
126155
assert_eq! (unsafe {
127156
& (
128157
* ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 )
129-
) . sport as * const _ as usize } , 2usize);
158+
) . sport as * const _ as usize } , 2usize , concat ! (
159+
"Alignment of field: " , stringify ! (
160+
rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
161+
stringify ! ( sport ) ));
130162
}
131163
impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 {
132164
fn clone(&self) -> Self { *self }
133165
}
134166
#[test]
135167
fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() {
136-
assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1>() ,
137-
4usize);
168+
assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1>() , 4usize
169+
, concat ! (
170+
"Size of: " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 ) ));
138171
assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1>() ,
139-
4usize);
172+
4usize , concat ! (
173+
"Alignment of " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 )
174+
));
140175
assert_eq! (unsafe {
141176
& ( * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1 ) ) .
142-
sctp_tag as * const _ as usize } , 0usize);
177+
sctp_tag as * const _ as usize } , 0usize , concat ! (
178+
"Alignment of field: " , stringify ! (
179+
rte_ipv6_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag
180+
) ));
143181
}
144182
impl Clone for rte_ipv6_tuple__bindgen_ty_1 {
145183
fn clone(&self) -> Self { *self }
146184
}
147185
#[test]
148186
fn bindgen_test_layout_rte_ipv6_tuple() {
149-
assert_eq!(::std::mem::size_of::<rte_ipv6_tuple>() , 36usize);
150-
assert_eq! (::std::mem::align_of::<rte_ipv6_tuple>() , 4usize);
187+
assert_eq!(::std::mem::size_of::<rte_ipv6_tuple>() , 36usize , concat ! (
188+
"Size of: " , stringify ! ( rte_ipv6_tuple ) ));
189+
assert_eq! (::std::mem::align_of::<rte_ipv6_tuple>() , 4usize , concat ! (
190+
"Alignment of " , stringify ! ( rte_ipv6_tuple ) ));
151191
assert_eq! (unsafe {
152192
& ( * ( 0 as * const rte_ipv6_tuple ) ) . src_addr as * const
153-
_ as usize } , 0usize);
193+
_ as usize } , 0usize , concat ! (
194+
"Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::"
195+
, stringify ! ( src_addr ) ));
154196
assert_eq! (unsafe {
155197
& ( * ( 0 as * const rte_ipv6_tuple ) ) . dst_addr as * const
156-
_ as usize } , 16usize);
198+
_ as usize } , 16usize , concat ! (
199+
"Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::"
200+
, stringify ! ( dst_addr ) ));
157201
}
158202
impl Clone for rte_ipv6_tuple {
159203
fn clone(&self) -> Self { *self }
@@ -167,13 +211,18 @@ pub struct rte_thash_tuple {
167211
}
168212
#[test]
169213
fn bindgen_test_layout_rte_thash_tuple() {
170-
assert_eq!(::std::mem::size_of::<rte_thash_tuple>() , 48usize);
214+
assert_eq!(::std::mem::size_of::<rte_thash_tuple>() , 48usize , concat ! (
215+
"Size of: " , stringify ! ( rte_thash_tuple ) ));
171216
assert_eq! (unsafe {
172217
& ( * ( 0 as * const rte_thash_tuple ) ) . v4 as * const _ as
173-
usize } , 0usize);
218+
usize } , 0usize , concat ! (
219+
"Alignment of field: " , stringify ! ( rte_thash_tuple ) ,
220+
"::" , stringify ! ( v4 ) ));
174221
assert_eq! (unsafe {
175222
& ( * ( 0 as * const rte_thash_tuple ) ) . v6 as * const _ as
176-
usize } , 0usize);
223+
usize } , 0usize , concat ! (
224+
"Alignment of field: " , stringify ! ( rte_thash_tuple ) ,
225+
"::" , stringify ! ( v6 ) ));
177226
}
178227
impl Clone for rte_thash_tuple {
179228
fn clone(&self) -> Self { *self }

0 commit comments

Comments
 (0)