Skip to content

Commit e184610

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 323c2df commit e184610

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
@@ -881,7 +881,12 @@ impl SourceMap {
881881
}
882882

883883
/// Returns a new span representing just the first character of the given span.
884+
/// When the span is empty, the same empty span is returned.
884885
pub fn start_point(&self, sp: Span) -> Span {
886+
if sp.is_empty() {
887+
return sp;
888+
}
889+
885890
let width = {
886891
let sp = sp.data();
887892
let local_begin = self.lookup_byte_offset(sp.lo);

0 commit comments

Comments
 (0)