@@ -1425,23 +1425,6 @@ impl CodeGenerator for CompInfo {
1425
1425
let layout = ty. layout ( ctx) ;
1426
1426
let mut packed = self . is_packed ( ctx, & layout) ;
1427
1427
1428
- // generate tuple struct if struct or union is a forward declaration,
1429
- // skip for now if template parameters are needed.
1430
- //
1431
- // NB: We generate a proper struct to avoid struct/function name
1432
- // collisions.
1433
- if self . is_forward_declaration ( ) && used_template_params. is_none ( ) {
1434
- let struct_name = item. canonical_name ( ctx) ;
1435
- let struct_name = ctx. rust_ident_raw ( struct_name) ;
1436
- let tuple_struct = quote ! {
1437
- #[ repr( C ) ]
1438
- #[ derive( Debug , Copy , Clone ) ]
1439
- pub struct #struct_name { _unused: [ u8 ; 0 ] }
1440
- } ;
1441
- result. push ( tuple_struct) ;
1442
- return ;
1443
- }
1444
-
1445
1428
let canonical_name = item. canonical_name ( ctx) ;
1446
1429
let canonical_ident = ctx. rust_ident ( & canonical_name) ;
1447
1430
@@ -1497,14 +1480,6 @@ impl CodeGenerator for CompInfo {
1497
1480
}
1498
1481
}
1499
1482
1500
- let is_union = self . kind ( ) == CompKind :: Union ;
1501
- if is_union {
1502
- result. saw_union ( ) ;
1503
- if !self . can_be_rust_union ( ctx) {
1504
- result. saw_bindgen_union ( ) ;
1505
- }
1506
- }
1507
-
1508
1483
let mut methods = vec ! [ ] ;
1509
1484
if !is_opaque {
1510
1485
let codegen_depth = item. codegen_depth ( ctx) ;
@@ -1529,8 +1504,14 @@ impl CodeGenerator for CompInfo {
1529
1504
}
1530
1505
}
1531
1506
1507
+ let is_union = self . kind ( ) == CompKind :: Union ;
1532
1508
let layout = item. kind ( ) . expect_type ( ) . layout ( ctx) ;
1533
- if is_union && !is_opaque {
1509
+ if is_union && !is_opaque && !self . is_forward_declaration ( ) {
1510
+ result. saw_union ( ) ;
1511
+ if !self . can_be_rust_union ( ctx) {
1512
+ result. saw_bindgen_union ( ) ;
1513
+ }
1514
+
1534
1515
let layout = layout. expect ( "Unable to get layout information?" ) ;
1535
1516
let ty = helpers:: blob ( layout) ;
1536
1517
@@ -1594,7 +1575,11 @@ impl CodeGenerator for CompInfo {
1594
1575
//
1595
1576
// NOTE: This check is conveniently here to avoid the dummy fields we
1596
1577
// may add for unused template parameters.
1597
- if item. is_zero_sized ( ctx) {
1578
+ if self . is_forward_declaration ( ) {
1579
+ fields. push ( quote ! {
1580
+ _unused: [ u8 ; 0 ] ,
1581
+ } ) ;
1582
+ } else if item. is_zero_sized ( ctx) {
1598
1583
let has_address = if is_opaque {
1599
1584
// Generate the address field if it's an opaque type and
1600
1585
// couldn't determine the layout of the blob.
@@ -1664,12 +1649,11 @@ impl CodeGenerator for CompInfo {
1664
1649
if item. can_derive_default ( ctx) {
1665
1650
derives. push ( "Default" ) ;
1666
1651
} else {
1667
- needs_default_impl = ctx. options ( ) . derive_default ;
1652
+ needs_default_impl =
1653
+ ctx. options ( ) . derive_default && !self . is_forward_declaration ( ) ;
1668
1654
}
1669
1655
1670
- if item. can_derive_copy ( ctx) && !item. annotations ( ) . disallow_copy ( ) &&
1671
- ctx. options ( ) . derive_copy
1672
- {
1656
+ if item. can_derive_copy ( ctx) && !item. annotations ( ) . disallow_copy ( ) {
1673
1657
derives. push ( "Copy" ) ;
1674
1658
1675
1659
if ctx. options ( ) . rust_features ( ) . builtin_clone_impls ( ) ||
@@ -1762,7 +1746,7 @@ impl CodeGenerator for CompInfo {
1762
1746
}
1763
1747
}
1764
1748
1765
- if ctx. options ( ) . layout_tests {
1749
+ if ctx. options ( ) . layout_tests && ! self . is_forward_declaration ( ) {
1766
1750
if let Some ( layout) = layout {
1767
1751
let fn_name =
1768
1752
format ! ( "bindgen_test_layout_{}" , canonical_ident. as_str( ) ) ;
0 commit comments