@@ -181,7 +181,7 @@ struct FieldRegions {
181
181
impl FieldRegions {
182
182
/// Track a field. If the field overlaps with 1 or more existing
183
183
/// entries, they will be merged together.
184
- fn add ( & mut self , field : & RegisterBlockField ) {
184
+ fn add ( & mut self , field : & RegisterBlockField ) -> Result < ( ) > {
185
185
186
186
// When merging, this holds the indices in self.regions
187
187
// that the input `field` will be merging with.
@@ -236,11 +236,17 @@ impl FieldRegions {
236
236
let idx = self . regions . binary_search_by_key ( & new_region. offset , |r| r. offset ) ;
237
237
match idx {
238
238
Ok ( idx) => {
239
- panic ! ( "we shouldn't exist in the vec, but are at idx {} {:#?}\n {:#?}" ,
239
+ bail ! ( "we shouldn't exist in the vec, but are at idx {} {:#?}\n {:#?}" ,
240
240
idx, new_region, self . regions) ;
241
241
}
242
242
Err ( idx) => self . regions . insert ( idx, new_region)
243
- }
243
+ } ;
244
+
245
+ Ok ( ( ) )
246
+ }
247
+
248
+ pub fn is_union ( & self ) -> bool {
249
+ self . regions . len ( ) == 1 && self . regions [ 0 ] . fields . len ( ) > 1
244
250
}
245
251
}
246
252
@@ -258,10 +264,10 @@ fn register_or_cluster_block(
258
264
let mut regions = FieldRegions :: default ( ) ;
259
265
260
266
for reg_block_field in & ercs_expanded {
261
- regions. add ( reg_block_field) ;
267
+ regions. add ( reg_block_field) ? ;
262
268
}
263
269
264
- let block_is_union = regions. regions . len ( ) == 1 && regions . regions [ 0 ] . fields . len ( ) > 1 ;
270
+ let block_is_union = regions. is_union ( ) ;
265
271
266
272
// The end of the region from the prior iteration of the loop
267
273
let mut last_end = None ;
0 commit comments