about summary refs log tree commit diff
path: root/src/librustc_span/source_map.rs
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-23 19:04:51 +0100
committerGitHub <noreply@github.com>2020-03-23 19:04:51 +0100
commit560eae31c549238b0a501c9800ffefebaf5e0b5a (patch)
treea0dc0ab6abbec8ee617b7e1c1157c0dd1e8c469e /src/librustc_span/source_map.rs
parentad6d30314b1af00d6d95edd5fa83aa5baa41da77 (diff)
parent763121d68b7600c96430067cf1bcfa73b32429c0 (diff)
Rollup merge of #70199 - pnkfelix:issue-68808-dont-turn-dummy-spans-into-invalid-lines, r=estebank
Revised span-to-lines conversion to produce an empty vec on DUMMY_SP.

This required revising some of the client code to stop relying on the returned set of lines being non-empty.

Fix #68808
Diffstat (limited to 'src/librustc_span/source_map.rs')
-rw-r--r--src/librustc_span/source_map.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/librustc_span/source_map.rs b/src/librustc_span/source_map.rs
index 8f806909f00..fa5baffbe48 100644
--- a/src/librustc_span/source_map.rs
+++ b/src/librustc_span/source_map.rs
@@ -535,6 +535,10 @@ impl SourceMap {
         let (lo, hi) = self.is_valid_span(sp)?;
         assert!(hi.line >= lo.line);
 
+        if sp.is_dummy() {
+            return Ok(FileLines { file: lo.file, lines: Vec::new() });
+        }
+
         let mut lines = Vec::with_capacity(hi.line - lo.line + 1);
 
         // The span starts partway through the first line,
@@ -545,6 +549,9 @@ 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.
+        //
+        // FIXME: now that we handle DUMMY_SP up above, we should consider
+        // asserting that the line numbers here are all indeed 1-based.
         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);