@@ -466,7 +466,7 @@ impl FieldMethods for RawField {
466
466
fn raw_fields_to_fields_and_bitfield_units < I > (
467
467
ctx : & BindgenContext ,
468
468
raw_fields : I ,
469
- ) -> Vec < Field >
469
+ ) -> Result < Vec < Field > , ( ) >
470
470
where
471
471
I : IntoIterator < Item = RawField > ,
472
472
{
@@ -503,15 +503,15 @@ where
503
503
& mut bitfield_unit_count,
504
504
& mut fields,
505
505
bitfields,
506
- ) ;
506
+ ) ? ;
507
507
}
508
508
509
509
assert ! (
510
510
raw_fields. next( ) . is_none( ) ,
511
511
"The above loop should consume all items in `raw_fields`"
512
512
) ;
513
513
514
- fields
514
+ Ok ( fields)
515
515
}
516
516
517
517
/// Given a set of contiguous raw bitfields, group and allocate them into
@@ -521,7 +521,8 @@ fn bitfields_to_allocation_units<E, I>(
521
521
bitfield_unit_count : & mut usize ,
522
522
fields : & mut E ,
523
523
raw_bitfields : I ,
524
- ) where
524
+ ) -> Result < ( ) , ( ) >
525
+ where
525
526
E : Extend < Field > ,
526
527
I : IntoIterator < Item = RawField > ,
527
528
{
@@ -572,7 +573,7 @@ fn bitfields_to_allocation_units<E, I>(
572
573
let bitfield_width = bitfield. bitfield_width ( ) . unwrap ( ) as usize ;
573
574
let bitfield_layout = ctx. resolve_type ( bitfield. ty ( ) )
574
575
. layout ( ctx)
575
- . expect ( "Bitfield without layout? Gah!" ) ;
576
+ . ok_or ( ( ) ) ? ;
576
577
let bitfield_size = bitfield_layout. size ;
577
578
let bitfield_align = bitfield_layout. align ;
578
579
@@ -649,6 +650,8 @@ fn bitfields_to_allocation_units<E, I>(
649
650
bitfields_in_unit,
650
651
) ;
651
652
}
653
+
654
+ Ok ( ( ) )
652
655
}
653
656
654
657
/// A compound structure's fields are initially raw, and have bitfields that
@@ -662,6 +665,7 @@ fn bitfields_to_allocation_units<E, I>(
662
665
enum CompFields {
663
666
BeforeComputingBitfieldUnits ( Vec < RawField > ) ,
664
667
AfterComputingBitfieldUnits ( Vec < Field > ) ,
668
+ ErrorComputingBitfieldUnits ,
665
669
}
666
670
667
671
impl Default for CompFields {
@@ -676,7 +680,7 @@ impl CompFields {
676
680
CompFields :: BeforeComputingBitfieldUnits ( ref mut raws) => {
677
681
raws. push ( raw) ;
678
682
}
679
- CompFields :: AfterComputingBitfieldUnits ( _ ) => {
683
+ _ => {
680
684
panic ! (
681
685
"Must not append new fields after computing bitfield allocation units"
682
686
) ;
@@ -689,22 +693,36 @@ impl CompFields {
689
693
CompFields :: BeforeComputingBitfieldUnits ( ref mut raws) => {
690
694
mem:: replace ( raws, vec ! [ ] )
691
695
}
692
- CompFields :: AfterComputingBitfieldUnits ( _ ) => {
696
+ _ => {
693
697
panic ! ( "Already computed bitfield units" ) ;
694
698
}
695
699
} ;
696
700
697
- let fields_and_units =
701
+ let result =
698
702
raw_fields_to_fields_and_bitfield_units ( ctx, raws) ;
699
- mem:: replace (
700
- self ,
701
- CompFields :: AfterComputingBitfieldUnits ( fields_and_units) ,
702
- ) ;
703
+
704
+ match result {
705
+ Ok ( fields_and_units) => {
706
+ mem:: replace (
707
+ self ,
708
+ CompFields :: AfterComputingBitfieldUnits ( fields_and_units) ) ;
709
+ }
710
+ Err ( ( ) ) => {
711
+ mem:: replace (
712
+ self ,
713
+ CompFields :: ErrorComputingBitfieldUnits
714
+ ) ;
715
+ }
716
+ }
703
717
}
704
718
705
719
fn deanonymize_fields ( & mut self , ctx : & BindgenContext , methods : & [ Method ] ) {
706
720
let fields = match * self {
707
721
CompFields :: AfterComputingBitfieldUnits ( ref mut fields) => fields,
722
+ CompFields :: ErrorComputingBitfieldUnits => {
723
+ // Nothing to do here.
724
+ return ;
725
+ }
708
726
CompFields :: BeforeComputingBitfieldUnits ( _) => {
709
727
panic ! ( "Not yet computed bitfield units." ) ;
710
728
}
@@ -787,6 +805,7 @@ impl Trace for CompFields {
787
805
T : Tracer ,
788
806
{
789
807
match * self {
808
+ CompFields :: ErrorComputingBitfieldUnits => { }
790
809
CompFields :: BeforeComputingBitfieldUnits ( ref fields) => {
791
810
for f in fields {
792
811
tracer. visit_kind ( f. ty ( ) . into ( ) , EdgeKind :: Field ) ;
@@ -1046,6 +1065,7 @@ impl CompInfo {
1046
1065
/// Get this type's set of fields.
1047
1066
pub fn fields ( & self ) -> & [ Field ] {
1048
1067
match self . fields {
1068
+ CompFields :: ErrorComputingBitfieldUnits => & [ ] [ ..] ,
1049
1069
CompFields :: AfterComputingBitfieldUnits ( ref fields) => fields,
1050
1070
CompFields :: BeforeComputingBitfieldUnits ( _) => {
1051
1071
panic ! ( "Should always have computed bitfield units first" ) ;
@@ -1558,6 +1578,10 @@ impl IsOpaque for CompInfo {
1558
1578
return true
1559
1579
}
1560
1580
1581
+ if let CompFields :: ErrorComputingBitfieldUnits = self . fields {
1582
+ return true ;
1583
+ }
1584
+
1561
1585
// Bitfields with a width that is larger than their unit's width have
1562
1586
// some strange things going on, and the best we can do is make the
1563
1587
// whole struct opaque.
0 commit comments