Skip to content

Commit b8dd5c9

Browse files
committed
code review
1 parent 451ba0d commit b8dd5c9

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

src/codegen/mod.rs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -986,40 +986,41 @@ impl CodeGenerator for TemplateInstantiation {
986986
// Although uses of instantiations don't need code generation, and are
987987
// just converted to rust types in fields, vars, etc, we take this
988988
// opportunity to generate tests for their layout here.
989+
if !ctx.options().layout_tests {
990+
return
991+
}
989992

990-
if ctx.options().layout_tests {
991-
let layout = item.kind().expect_type().layout(ctx);
993+
let layout = item.kind().expect_type().layout(ctx);
992994

993-
if let Some(layout) = layout {
994-
let size = layout.size;
995-
let align = layout.align;
995+
if let Some(layout) = layout {
996+
let size = layout.size;
997+
let align = layout.align;
996998

997-
let name = item.canonical_name(ctx);
998-
let fn_name = format!("__bindgen_test_layout_{}_instantiation_{}",
999-
name,
1000-
item.id().as_usize());
1001-
let fn_name = ctx.rust_ident_raw(&fn_name);
999+
let name = item.canonical_name(ctx);
1000+
let fn_name = format!("__bindgen_test_layout_{}_instantiation_{}",
1001+
name,
1002+
item.id().as_usize());
1003+
let fn_name = ctx.rust_ident_raw(&fn_name);
10021004

1003-
let prefix = ctx.trait_prefix();
1004-
let ident = item.to_rust_ty_or_opaque(ctx, &());
1005-
let size_of_expr = quote_expr!(ctx.ext_cx(),
1006-
::$prefix::mem::size_of::<$ident>());
1007-
let align_of_expr = quote_expr!(ctx.ext_cx(),
1008-
::$prefix::mem::align_of::<$ident>());
1009-
1010-
let item = quote_item!(
1011-
ctx.ext_cx(),
1012-
#[test]
1013-
fn $fn_name() {
1014-
assert_eq!($size_of_expr, $size,
1015-
concat!("Size of template specialization: ", stringify!($ident)));
1016-
assert_eq!($align_of_expr, $align,
1017-
concat!("Alignment of template specialization: ", stringify!($ident)));
1018-
})
1019-
.unwrap();
1005+
let prefix = ctx.trait_prefix();
1006+
let ident = item.to_rust_ty_or_opaque(ctx, &());
1007+
let size_of_expr = quote_expr!(ctx.ext_cx(),
1008+
::$prefix::mem::size_of::<$ident>());
1009+
let align_of_expr = quote_expr!(ctx.ext_cx(),
1010+
::$prefix::mem::align_of::<$ident>());
1011+
1012+
let item = quote_item!(
1013+
ctx.ext_cx(),
1014+
#[test]
1015+
fn $fn_name() {
1016+
assert_eq!($size_of_expr, $size,
1017+
concat!("Size of template specialization: ", stringify!($ident)));
1018+
assert_eq!($align_of_expr, $align,
1019+
concat!("Alignment of template specialization: ", stringify!($ident)));
1020+
})
1021+
.unwrap();
10201022

1021-
result.push(item);
1022-
}
1023+
result.push(item);
10231024
}
10241025
}
10251026
}

0 commit comments

Comments
 (0)