Skip to content

Commit 5004cb9

Browse files
committed
verbose assertions in SourceFileItems
1 parent 19f6cdc commit 5004cb9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

crates/ra_hir/src/lib.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,21 @@ impl SourceFileItems {
139139
self.id_of_unchecked(item)
140140
}
141141
fn id_of_unchecked(&self, item: SyntaxNodeRef) -> SourceFileItemId {
142-
let (id, _item) = self
143-
.arena
144-
.iter()
145-
.find(|(_id, i)| i.borrowed() == item)
146-
.unwrap();
147-
id
142+
if let Some((id, _)) = self.arena.iter().find(|(_id, i)| i.borrowed() == item) {
143+
return id;
144+
}
145+
// This should not happen. Let's try to give a sensible diagnostics.
146+
if let Some((_, i)) = self.arena.iter().find(|(_id, i)| i.range() == item.range()) {
147+
panic!(
148+
"unequal syntax nodes with the same range:\n{:?}\n{:?}",
149+
item, i
150+
)
151+
}
152+
panic!(
153+
"Can't find {:?} in SourceFileItems:\n{:?}",
154+
item,
155+
self.arena.iter().map(|(_id, i)| i).collect::<Vec<_>>(),
156+
);
148157
}
149158
pub fn id_of_source_file(&self) -> SourceFileItemId {
150159
let (id, _syntax) = self.arena.iter().next().unwrap();

0 commit comments

Comments
 (0)