diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-21 12:55:39 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-21 12:55:39 +0100 |
| commit | c913271b2965027953c71a0b8f85a8c7cb802444 (patch) | |
| tree | 5b126c4c594a722941d1a690b689cd439d388aa2 /src/syntax | |
| parent | 69136b74dc0026bcac09997569a172ba0a5083b5 (diff) | |
Fix crash for jump to outdated span
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/source.rs | 12 |
1 files changed, 6 insertions, 6 deletions
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<'_>> { + 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<usize> { - 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. |
