@@ -384,6 +384,10 @@ fn impl_abstract_structure_type(
384
384
. map ( |field| AbstractField :: from_field ( field, & name, pointer_width) )
385
385
. collect :: < Result < Vec < _ > > > ( ) ?;
386
386
387
+ if abstract_fields. is_empty ( ) {
388
+ return Err ( name. span ( ) . error ( "expected at least one named field" ) ) ;
389
+ }
390
+
387
391
// Generate the arguments to `StructureBuilder::insert`. Luckily `mem::offset_of!` was stabilized in
388
392
// Rust 1.77 or otherwise this would be a lot more complicated.
389
393
let layout_name = format_ident ! ( "__{name}_layout" ) ;
@@ -434,15 +438,7 @@ fn impl_abstract_structure_type(
434
438
Some ( n) => quote ! { #[ repr( packed( #n) ) ] } ,
435
439
None => quote ! { #[ repr( packed) ] } ,
436
440
} ) ;
437
- let ( align, set_alignment) = repr
438
- . align
439
- . map ( |n| {
440
- (
441
- quote ! { #[ repr( align( #n) ) ] } ,
442
- quote ! { . set_alignment( Self :: LAYOUT . align( ) ) } ,
443
- )
444
- } )
445
- . unzip ( ) ;
441
+ let align = repr. align . map ( |n| quote ! { #[ repr( align( #n) ) ] } ) ;
446
442
447
443
// Distinguish between structs and unions
448
444
let ( kind, set_union) = match kind {
@@ -478,11 +474,11 @@ fn impl_abstract_structure_type(
478
474
fn resolve_type( ) -> :: binaryninja:: rc:: Ref <:: binaryninja:: types:: Type > {
479
475
:: binaryninja:: types:: Type :: structure(
480
476
& :: binaryninja:: types:: Structure :: builder( )
481
- #( . insert( #args) ) *
482
- . set_width( Self :: LAYOUT . size( ) as u64 )
483
477
. set_packed( #is_packed)
484
- #set_alignment
478
+ . set_width( Self :: LAYOUT . size( ) as u64 )
479
+ . set_alignment( Self :: LAYOUT . align( ) )
485
480
#set_union
481
+ #( . insert( #args) ) *
486
482
. finalize( )
487
483
)
488
484
}
0 commit comments