about summary refs log tree commit diff
path: root/src/librustc_span
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-01-06 11:46:30 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-01-08 04:25:33 +0100
commit20ebb807d523947f5fac710c4ae95ac9730ad995 (patch)
treecbe04e1e29584c071134189fc358115b95cf2a82 /src/librustc_span
parent2c3e5d3de023c0bfbf4a4c4d3b0d7a9844e96ffe (diff)
downloadrust-20ebb807d523947f5fac710c4ae95ac9730ad995.tar.gz
rust-20ebb807d523947f5fac710c4ae95ac9730ad995.zip
span_to_lines: account for DUMMY_SP
Diffstat (limited to 'src/librustc_span')
-rw-r--r--src/librustc_span/source_map.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/librustc_span/source_map.rs b/src/librustc_span/source_map.rs
index 0b9b9fe7887..ec1f9f3a7bd 100644
--- a/src/librustc_span/source_map.rs
+++ b/src/librustc_span/source_map.rs
@@ -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 })
     }