Skip to content

Commit 58fa309

Browse files
committed
Fix SourceMap::start_point for empty spans
When the span is empty, it doesn't really have a first character. Even worse, when it's empty at the end of the file, adding a byte offset will make it be out of bounds. So we just return the empty span in these cases.
1 parent 3706da4 commit 58fa309

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

compiler/rustc_span/src/source_map.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,12 @@ impl SourceMap {
897897
}
898898

899899
/// Returns a new span representing just the first character of the given span.
900+
/// When the span is empty, the same empty span is returned.
900901
pub fn start_point(&self, sp: Span) -> Span {
902+
if sp.is_empty() {
903+
return sp;
904+
}
905+
901906
let width = {
902907
let sp = sp.data();
903908
let local_begin = self.lookup_byte_offset(sp.lo);

0 commit comments

Comments
 (0)