about summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2020-03-13 17:01:35 -0400
committerFelix S. Klock II <pnkfelix@pnkfx.org>2020-03-20 14:11:16 -0400
commitebf27fac8185ea7a779f4d21ea506377b157fc61 (patch)
treee788a408afe34724f4af9d36407ebd4e362a1b45 /src/librustc_errors
parentf4c675c476c18b1a11041193f2f59d695b126bc8 (diff)
downloadrust-ebf27fac8185ea7a779f4d21ea506377b157fc61.tar.gz
rust-ebf27fac8185ea7a779f4d21ea506377b157fc61.zip
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.
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/emitter.rs2
-rw-r--r--src/librustc_errors/lib.rs6
2 files changed, 4 insertions, 4 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 26f1fa267f9..94053b98cd7 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -1574,7 +1574,7 @@ impl EmitterWriter {
                 .span_to_lines(parts[0].span)
                 .expect("span_to_lines failed when emitting suggestion");
 
-            assert!(!lines.lines.is_empty());
+            assert!(!lines.lines.is_empty() || parts[0].span.is_dummy());
 
             let line_start = sm.lookup_char_pos(parts[0].span.lo()).line;
             draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1);
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index bed26c3736b..a21314afb1e 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -194,7 +194,7 @@ impl CodeSuggestion {
                 let bounding_span = Span::with_root_ctxt(lo, hi);
                 // The different spans might belong to different contexts, if so ignore suggestion.
                 let lines = sm.span_to_lines(bounding_span).ok()?;
-                assert!(!lines.lines.is_empty());
+                assert!(!lines.lines.is_empty() || bounding_span.is_dummy());
 
                 // We can't splice anything if the source is unavailable.
                 if !sm.ensure_source_file_source_present(lines.file.clone()) {
@@ -213,8 +213,8 @@ impl CodeSuggestion {
                 let sf = &lines.file;
                 let mut prev_hi = sm.lookup_char_pos(bounding_span.lo());
                 prev_hi.col = CharPos::from_usize(0);
-
-                let mut prev_line = sf.get_line(lines.lines[0].line_index);
+                let mut prev_line =
+                    lines.lines.get(0).and_then(|line0| sf.get_line(line0.line_index));
                 let mut buf = String::new();
 
                 for part in &substitution.parts {