diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-02-07 16:51:51 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-02-07 16:53:23 +0100 |
commit | 193a103bf5333082bba69b7f541b51ba1f723443 (patch) | |
tree | 0add85279519b83be96b123cbecc466fce108882 /src | |
parent | 1c6985175d14dd3a596ac079340dbb19ff56f9bd (diff) |
codegen: Improve the assertion message of the failing layout tests.
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen/mod.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index f19331f4..0fdfaad0 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -866,8 +866,10 @@ impl CodeGenerator for CompInfo { let item = quote_item!(ctx.ext_cx(), #[test] fn $fn_name() { - assert_eq!($size_of_expr, $size); - assert_eq!($align_of_expr, $align); + assert_eq!($size_of_expr, $size, + concat!("Size of template specialization: ", stringify!($ident))); + assert_eq!($align_of_expr, $align, + concat!("Alignment of template specialization: ", stringify!($ident))); }) .unwrap(); result.push(item); @@ -1339,12 +1341,12 @@ impl CodeGenerator for CompInfo { if let Some(layout) = layout { let fn_name = format!("bindgen_test_layout_{}", canonical_name); let fn_name = ctx.rust_ident_raw(&fn_name); - let ident = ctx.rust_ident_raw(&canonical_name); + let type_name = ctx.rust_ident_raw(&canonical_name); let prefix = ctx.trait_prefix(); let size_of_expr = quote_expr!(ctx.ext_cx(), - ::$prefix::mem::size_of::<$ident>()); + ::$prefix::mem::size_of::<$type_name>()); let align_of_expr = quote_expr!(ctx.ext_cx(), - ::$prefix::mem::align_of::<$ident>()); + ::$prefix::mem::align_of::<$type_name>()); let size = layout.size; let align = layout.align; @@ -1353,7 +1355,9 @@ impl CodeGenerator for CompInfo { None } else { quote_item!(ctx.ext_cx(), - assert_eq!($align_of_expr, $align); + assert_eq!($align_of_expr, + $align, + concat!("Alignment of ", stringify!($type_name))); ) }; @@ -1370,8 +1374,6 @@ impl CodeGenerator for CompInfo { let check_field_offset = if should_skip_field_offset_checks { None } else { - let type_name = ctx.rust_ident(&canonical_name); - let asserts = self.fields() .iter() .filter(|field| field.bitfield().is_none()) @@ -1382,7 +1384,9 @@ impl CodeGenerator for CompInfo { let field_name = ctx.rust_ident(name); quote_item!(ctx.ext_cx(), - assert_eq!(unsafe { &(*(0 as *const $type_name)).$field_name as *const _ as usize }, $field_offset); + assert_eq!(unsafe { &(*(0 as *const $type_name)).$field_name as *const _ as usize }, + $field_offset, + concat!("Alignment of field: ", stringify!($type_name), "::", stringify!($field_name))); ) }) }) @@ -1394,7 +1398,9 @@ impl CodeGenerator for CompInfo { let item = quote_item!(ctx.ext_cx(), #[test] fn $fn_name() { - assert_eq!($size_of_expr, $size); + assert_eq!($size_of_expr, + $size, + concat!("Size of: ", stringify!($type_name))); $check_struct_align $check_field_offset @@ -2137,7 +2143,7 @@ impl ToRustTy for Type { .map(|arg| arg.to_rust_ty(ctx)) .collect::<Vec<_>>(); - path.segments.last_mut().unwrap().parameters = if + path.segments.last_mut().unwrap().parameters = if template_args.is_empty() { None } else { |