Skip to content

Commit 696da7b

Browse files
committed
peek the iterator to see if we have another item
1 parent a2b5b0a commit 696da7b

File tree

1 file changed

+11
-4
lines changed
  • crates/noirc_frontend/src/graph

1 file changed

+11
-4
lines changed

crates/noirc_frontend/src/graph/mod.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,18 @@ impl CrateGraph {
149149
}
150150

151151
pub fn add_crate(&mut self, file_id: FileId) -> CrateId {
152-
// Should this also be asserted that it only has exactly one match?
153-
let mut roots_with_file_id =
154-
self.arena.iter().filter(|(_, crate_data)| crate_data.root_file_id == file_id);
152+
let mut crates_with_file_id = self
153+
.arena
154+
.iter()
155+
.filter(|(_, crate_data)| crate_data.root_file_id == file_id)
156+
.peekable();
157+
158+
let matching_id = crates_with_file_id.next();
159+
if crates_with_file_id.peek().is_some() {
160+
panic!("ICE: Found multiple crates with the same FileId");
161+
}
155162

156-
match roots_with_file_id.next() {
163+
match matching_id {
157164
Some((crate_id @ CrateId::Crate(_), _)) => *crate_id,
158165
Some((CrateId::Root(_), _)) => {
159166
panic!("ICE: Tried to re-add the root crate as a regular crate")

0 commit comments

Comments
 (0)