summaryrefslogtreecommitdiff
path: root/src/syntax/source.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-21 12:55:39 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-21 12:55:39 +0100
commitc913271b2965027953c71a0b8f85a8c7cb802444 (patch)
tree5b126c4c594a722941d1a690b689cd439d388aa2 /src/syntax/source.rs
parent69136b74dc0026bcac09997569a172ba0a5083b5 (diff)
Fix crash for jump to outdated span
Diffstat (limited to 'src/syntax/source.rs')
-rw-r--r--src/syntax/source.rs12
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.