Skip to content

Commit

Permalink
span_to_lines: account for DUMMY_SP
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jan 8, 2020
1 parent 2c3e5d3 commit 20ebb80
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/librustc_span/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,15 @@ impl SourceMap {
// and to the end of the line. Be careful because the line
// numbers in Loc are 1-based, so we subtract 1 to get 0-based
// lines.
for line_index in lo.line - 1..hi.line - 1 {
let hi_line = hi.line.saturating_sub(1);
for line_index in lo.line.saturating_sub(1)..hi_line {
let line_len = lo.file.get_line(line_index).map(|s| s.chars().count()).unwrap_or(0);
lines.push(LineInfo { line_index, start_col, end_col: CharPos::from_usize(line_len) });
start_col = CharPos::from_usize(0);
}

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

Ok(FileLines { file: lo.file, lines })
}
Expand Down

0 comments on commit 20ebb80

Please sign in to comment.