@@ -1419,23 +1419,6 @@ impl CodeGenerator for CompInfo {
1419
1419
let layout = ty. layout ( ctx) ;
1420
1420
let mut packed = self . is_packed ( ctx, & layout) ;
1421
1421
1422
- // generate tuple struct if struct or union is a forward declaration,
1423
- // skip for now if template parameters are needed.
1424
- //
1425
- // NB: We generate a proper struct to avoid struct/function name
1426
- // collisions.
1427
- if self . is_forward_declaration ( ) && used_template_params. is_none ( ) {
1428
- let struct_name = item. canonical_name ( ctx) ;
1429
- let struct_name = ctx. rust_ident_raw ( struct_name) ;
1430
- let tuple_struct = quote ! {
1431
- #[ repr( C ) ]
1432
- #[ derive( Debug , Copy , Clone ) ]
1433
- pub struct #struct_name { _unused: [ u8 ; 0 ] }
1434
- } ;
1435
- result. push ( tuple_struct) ;
1436
- return ;
1437
- }
1438
-
1439
1422
let canonical_name = item. canonical_name ( ctx) ;
1440
1423
let canonical_ident = ctx. rust_ident ( & canonical_name) ;
1441
1424
@@ -1491,14 +1474,6 @@ impl CodeGenerator for CompInfo {
1491
1474
}
1492
1475
}
1493
1476
1494
- let is_union = self . kind ( ) == CompKind :: Union ;
1495
- if is_union {
1496
- result. saw_union ( ) ;
1497
- if !self . can_be_rust_union ( ctx) {
1498
- result. saw_bindgen_union ( ) ;
1499
- }
1500
- }
1501
-
1502
1477
let mut methods = vec ! [ ] ;
1503
1478
if !is_opaque {
1504
1479
let codegen_depth = item. codegen_depth ( ctx) ;
@@ -1523,8 +1498,14 @@ impl CodeGenerator for CompInfo {
1523
1498
}
1524
1499
}
1525
1500
1501
+ let is_union = self . kind ( ) == CompKind :: Union ;
1526
1502
let layout = item. kind ( ) . expect_type ( ) . layout ( ctx) ;
1527
- if is_union && !is_opaque {
1503
+ if is_union && !is_opaque && !self . is_forward_declaration ( ) {
1504
+ result. saw_union ( ) ;
1505
+ if !self . can_be_rust_union ( ctx) {
1506
+ result. saw_bindgen_union ( ) ;
1507
+ }
1508
+
1528
1509
let layout = layout. expect ( "Unable to get layout information?" ) ;
1529
1510
let ty = helpers:: blob ( layout) ;
1530
1511
@@ -1588,7 +1569,11 @@ impl CodeGenerator for CompInfo {
1588
1569
//
1589
1570
// NOTE: This check is conveniently here to avoid the dummy fields we
1590
1571
// may add for unused template parameters.
1591
- if item. is_zero_sized ( ctx) {
1572
+ if self . is_forward_declaration ( ) {
1573
+ fields. push ( quote ! {
1574
+ _unused: [ u8 ; 0 ] ,
1575
+ } ) ;
1576
+ } else if item. is_zero_sized ( ctx) {
1592
1577
let has_address = if is_opaque {
1593
1578
// Generate the address field if it's an opaque type and
1594
1579
// couldn't determine the layout of the blob.
@@ -1658,12 +1643,11 @@ impl CodeGenerator for CompInfo {
1658
1643
if item. can_derive_default ( ctx) {
1659
1644
derives. push ( "Default" ) ;
1660
1645
} else {
1661
- needs_default_impl = ctx. options ( ) . derive_default ;
1646
+ needs_default_impl =
1647
+ ctx. options ( ) . derive_default && !self . is_forward_declaration ( ) ;
1662
1648
}
1663
1649
1664
- if item. can_derive_copy ( ctx) && !item. annotations ( ) . disallow_copy ( ) &&
1665
- ctx. options ( ) . derive_copy
1666
- {
1650
+ if item. can_derive_copy ( ctx) && !item. annotations ( ) . disallow_copy ( ) {
1667
1651
derives. push ( "Copy" ) ;
1668
1652
1669
1653
if ctx. options ( ) . rust_features ( ) . builtin_clone_impls ( ) ||
@@ -1756,7 +1740,7 @@ impl CodeGenerator for CompInfo {
1756
1740
}
1757
1741
}
1758
1742
1759
- if ctx. options ( ) . layout_tests {
1743
+ if ctx. options ( ) . layout_tests && ! self . is_forward_declaration ( ) {
1760
1744
if let Some ( layout) = layout {
1761
1745
let fn_name =
1762
1746
format ! ( "bindgen_test_layout_{}" , canonical_ident. as_str( ) ) ;
0 commit comments