From 5004cb928b2c430a6d7fba59d89f7829982d8baa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Dec 2018 14:21:54 +0300 Subject: verbose assertions in SourceFileItems --- crates/ra_hir/src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 578fde259..760524f6b 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -139,12 +139,21 @@ impl SourceFileItems { self.id_of_unchecked(item) } fn id_of_unchecked(&self, item: SyntaxNodeRef) -> SourceFileItemId { - let (id, _item) = self - .arena - .iter() - .find(|(_id, i)| i.borrowed() == item) - .unwrap(); - id + if let Some((id, _)) = self.arena.iter().find(|(_id, i)| i.borrowed() == item) { + return id; + } + // This should not happen. Let's try to give a sensible diagnostics. + if let Some((_, i)) = self.arena.iter().find(|(_id, i)| i.range() == item.range()) { + panic!( + "unequal syntax nodes with the same range:\n{:?}\n{:?}", + item, i + ) + } + panic!( + "Can't find {:?} in SourceFileItems:\n{:?}", + item, + self.arena.iter().map(|(_id, i)| i).collect::>(), + ); } pub fn id_of_source_file(&self) -> SourceFileItemId { let (id, _syntax) = self.arena.iter().next().unwrap(); -- cgit v1.2.3