Skip to content

Commit 20ebb80

Browse files
committedJan 8, 2020
span_to_lines: account for DUMMY_SP
1 parent 2c3e5d3 commit 20ebb80

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎src/librustc_span/source_map.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,15 @@ impl SourceMap {
499499
// and to the end of the line. Be careful because the line
500500
// numbers in Loc are 1-based, so we subtract 1 to get 0-based
501501
// lines.
502-
for line_index in lo.line - 1..hi.line - 1 {
502+
let hi_line = hi.line.saturating_sub(1);
503+
for line_index in lo.line.saturating_sub(1)..hi_line {
503504
let line_len = lo.file.get_line(line_index).map(|s| s.chars().count()).unwrap_or(0);
504505
lines.push(LineInfo { line_index, start_col, end_col: CharPos::from_usize(line_len) });
505506
start_col = CharPos::from_usize(0);
506507
}
507508

508509
// For the last line, it extends from `start_col` to `hi.col`:
509-
lines.push(LineInfo { line_index: hi.line - 1, start_col, end_col: hi.col });
510+
lines.push(LineInfo { line_index: hi_line, start_col, end_col: hi.col });
510511

511512
Ok(FileLines { file: lo.file, lines })
512513
}

0 commit comments

Comments
 (0)
Please sign in to comment.