summaryrefslogtreecommitdiff
path: root/src/reports
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2025-02-10 12:34:56 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2025-02-10 12:34:56 +1300
commitdedd999b8f923641dce512c21db5528d32356cc6 (patch)
tree01685bf44171bd110ebc4afc014ffc3d64b58687 /src/reports
parentfd6b4471955dac64b7d40b7c31992c15d52b2460 (diff)
downloadassembler-dedd999b8f923641dce512c21db5528d32356cc6.zip
Simplify infallible indexing operations in resolver
Indexing into a resolver with a pointer from the same resolver should never fail, and if it does we don't want to silently squash the error.
Diffstat (limited to 'src/reports')
-rw-r--r--src/reports/source_hierarchy.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/reports/source_hierarchy.rs b/src/reports/source_hierarchy.rs
index 9478c56..39550ab 100644
--- a/src/reports/source_hierarchy.rs
+++ b/src/reports/source_hierarchy.rs
@@ -30,29 +30,26 @@ impl<'a> SourceHierarchy<'a> {
false => eprint!("├── "),
true => eprint!("└── "),
}
- if let Some(unit) = self.resolver.source_units.get(id) {
- let path_str = &unit.source_unit.main.path.as_os_str().to_string_lossy();
- if let Some(name_str) = unit.source_unit.name() {
- eprint!("{name_str}{BLUE}");
- if unit.source_unit.head.is_some() { eprint!(" +head") }
- if unit.source_unit.tail.is_some() { eprint!(" +tail") }
- let mut unresolved = 0;
- for symbol in &self.resolver.unresolved {
- if symbol.source_id == id { unresolved += 1; }
- }
- if unresolved > 0 { eprint!("{RED} ({unresolved})"); }
- eprintln!("{NORMAL} {DIM}({path_str}){NORMAL}");
- } else {
- eprintln!("{path_str}");
- }
- levels.push(end);
- let len = unit.child_ids.len();
- for (i, id) in unit.child_ids.iter().enumerate() {
- let end = i + 1 == len;
- self.report_leaf(*id, levels.clone(), end);
+ let unit = &self.resolver.source_units[id];
+ let path_str = &unit.source_unit.main.path.as_os_str().to_string_lossy();
+ if let Some(name_str) = unit.source_unit.name() {
+ eprint!("{name_str}{BLUE}");
+ if unit.source_unit.head.is_some() { eprint!(" +head") }
+ if unit.source_unit.tail.is_some() { eprint!(" +tail") }
+ let mut unresolved = 0;
+ for symbol in &self.resolver.unresolved {
+ if symbol.source_id == id { unresolved += 1; }
}
+ if unresolved > 0 { eprint!("{RED} ({unresolved})"); }
+ eprintln!("{NORMAL} {DIM}({path_str}){NORMAL}");
} else {
- eprintln!("<error loading source unit details>");
+ eprintln!("{path_str}");
+ }
+ levels.push(end);
+ let len = unit.child_ids.len();
+ for (i, id) in unit.child_ids.iter().enumerate() {
+ let end = i + 1 == len;
+ self.report_leaf(*id, levels.clone(), end);
}
}
}