Skip to content

Commit fbc0bb5

Browse files
committed
Address stylistic code review comments from @Emilgardis
1 parent e1f96a4 commit fbc0bb5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/generate/peripheral.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct FieldRegions {
181181
impl FieldRegions {
182182
/// Track a field. If the field overlaps with 1 or more existing
183183
/// entries, they will be merged together.
184-
fn add(&mut self, field: &RegisterBlockField) {
184+
fn add(&mut self, field: &RegisterBlockField) -> Result<()> {
185185

186186
// When merging, this holds the indices in self.regions
187187
// that the input `field` will be merging with.
@@ -236,11 +236,17 @@ impl FieldRegions {
236236
let idx = self.regions.binary_search_by_key(&new_region.offset, |r| r.offset);
237237
match idx {
238238
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{:#?}",
240240
idx, new_region, self.regions);
241241
}
242242
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
244250
}
245251
}
246252

@@ -258,10 +264,10 @@ fn register_or_cluster_block(
258264
let mut regions = FieldRegions::default();
259265

260266
for reg_block_field in &ercs_expanded {
261-
regions.add(reg_block_field);
267+
regions.add(reg_block_field)?;
262268
}
263269

264-
let block_is_union = regions.regions.len() == 1 && regions.regions[0].fields.len() > 1;
270+
let block_is_union = regions.is_union();
265271

266272
// The end of the region from the prior iteration of the loop
267273
let mut last_end = None;

0 commit comments

Comments
 (0)