Skip to content

Commit b8e865d

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 72cfa0a commit b8e865d

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
@@ -824,7 +824,12 @@ impl SourceMap {
824824
}
825825

826826
/// Returns a new span representing just the first character of the given span.
827+
/// When the span is empty, the same empty span is returned.
827828
pub fn start_point(&self, sp: Span) -> Span {
829+
if sp.is_empty() {
830+
return sp;
831+
}
832+
828833
let width = {
829834
let sp = sp.data();
830835
let local_begin = self.lookup_byte_offset(sp.lo);

0 commit comments

Comments
 (0)