From c913271b2965027953c71a0b8f85a8c7cb802444 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 21 Mar 2023 12:55:39 +0100 Subject: Fix crash for jump to outdated span --- src/syntax/source.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/syntax/source.rs') diff --git a/src/syntax/source.rs b/src/syntax/source.rs index 052e841a..53cc6de9 100644 --- a/src/syntax/source.rs +++ b/src/syntax/source.rs @@ -152,18 +152,18 @@ impl Source { /// Find the node with the given span. /// - /// Panics if the span does not point into this source file. - pub fn find(&self, span: Span) -> LinkedNode<'_> { - LinkedNode::new(&self.root) - .find(span) - .expect("span does not point into this source file") + /// Returns `None` if the span does not point into this source file. + pub fn find(&self, span: Span) -> Option> { + LinkedNode::new(&self.root).find(span) } /// Map a span that points into this source file to a byte range. /// /// Panics if the span does not point into this source file. pub fn range(&self, span: Span) -> Range { - self.find(span).range() + self.find(span) + .expect("span does not point into this source file") + .range() } /// Return the index of the UTF-16 code unit at the byte index. -- cgit v1.2.3