From dedd999b8f923641dce512c21db5528d32356cc6 Mon Sep 17 00:00:00 2001
From: Ben Bridle <bridle.benjamin@gmail.com>
Date: Mon, 10 Feb 2025 12:34:56 +1300
Subject: 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.
---
 src/errors/merge_error.rs | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

(limited to 'src/errors')

diff --git a/src/errors/merge_error.rs b/src/errors/merge_error.rs
index a694b71..3ff60d2 100644
--- a/src/errors/merge_error.rs
+++ b/src/errors/merge_error.rs
@@ -14,27 +14,25 @@ impl MergeError<'_> {
     pub fn report(&self) {
         error!("A cyclic dependency was found between the following libraries:");
         for id in &self.cyclic_unit_ids {
-            if let Some(unit) = self.resolver.source_units.get(*id) {
-                let path = &unit.source_unit.path();
-                match unit.source_unit.name() {
-                    Some(name) =>
-                        eprintln!("{name}{NORMAL}{DIM} ({path}){NORMAL}"),
+            let unit = &self.resolver.source_units[*id];
+            let path = &unit.source_unit.path();
+            match unit.source_unit.name() {
+                Some(name) =>
+                    eprintln!("{name}{NORMAL}{DIM} ({path}){NORMAL}"),
+                None =>
+                    eprintln!("{path}"),
+            };
+            // Print each parent involved in the dependency cycle.
+            for parent_id in &unit.parent_ids {
+                if !self.cyclic_unit_ids.contains(parent_id) { continue; }
+                let parent_unit = &self.resolver.source_units[*parent_id];
+                let parent_path = &parent_unit.source_unit.path();
+                match parent_unit.source_unit.name() {
+                    Some(parent_name) =>
+                        eprintln!("  => {parent_name} {DIM}({parent_path}){NORMAL}"),
                     None =>
-                        eprintln!("{path}"),
+                        eprintln!("  => {parent_path}"),
                 };
-                // Print each parent involved in the dependency cycle.
-                for parent_id in &unit.parent_ids {
-                    if !self.cyclic_unit_ids.contains(parent_id) { continue; }
-                    if let Some(parent_unit) = self.resolver.source_units.get(*parent_id) {
-                        let parent_path = &parent_unit.source_unit.path();
-                        match parent_unit.source_unit.name() {
-                            Some(parent_name) =>
-                                eprintln!("  => {parent_name} {DIM}({parent_path}){NORMAL}"),
-                            None =>
-                                eprintln!("  => {parent_path}"),
-                        };
-                    }
-                }
             }
         }
     }
-- 
cgit v1.2.3-70-g09d2