@@ -986,40 +986,41 @@ impl CodeGenerator for TemplateInstantiation {
986
986
// Although uses of instantiations don't need code generation, and are
987
987
// just converted to rust types in fields, vars, etc, we take this
988
988
// opportunity to generate tests for their layout here.
989
+ if !ctx. options ( ) . layout_tests {
990
+ return
991
+ }
989
992
990
- if ctx. options ( ) . layout_tests {
991
- let layout = item. kind ( ) . expect_type ( ) . layout ( ctx) ;
993
+ let layout = item. kind ( ) . expect_type ( ) . layout ( ctx) ;
992
994
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 ;
996
998
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) ;
1002
1004
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 ( ) ;
1020
1022
1021
- result. push ( item) ;
1022
- }
1023
+ result. push ( item) ;
1023
1024
}
1024
1025
}
1025
1026
}
0 commit comments