summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-01-26 15:33:05 +0000
committervarkor <github@varkor.com>2018-01-26 15:33:05 +0000
commit0ac465924e6ae4380b25c38cbc14f425796fa2af (patch)
tree35390718704319a4b6e9dc7a66c5eb47ee9de0d3 /src/librustc_errors
parenta0dcecff90c45ad5d4eb60859e22bb3f1b03842a (diff)
downloadrust-0ac465924e6ae4380b25c38cbc14f425796fa2af.tar.gz
rust-0ac465924e6ae4380b25c38cbc14f425796fa2af.zip
Add line numbers and columns to error messages spanning multiple files
If an error message is emitted that spans several files, only the
primary file currently has line and column data attached. This is
useful information, even in files other than the one in which the error
occurs. We can often work out which line and column the error
corresponds to in other files — in this case it is helpful to add them
(in the case of ambiguity, the first relevant line/column is picked,
which is still helpful than none).
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/emitter.rs13
-rw-r--r--src/librustc_errors/snippet.rs3
2 files changed, 14 insertions, 2 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 58f851aea38..a9f228ca729 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -1013,8 +1013,19 @@ impl EmitterWriter {
 
                 // Then, the secondary file indicator
                 buffer.prepend(buffer_msg_line_offset + 1, "::: ", Style::LineNumber);
+                let loc = if let Some(first_line) = annotated_file.lines.first() {
+                    let col = if let Some(first_annotation) = first_line.annotations.first() {
+                        format!(":{}", first_annotation.start_col + 1)
+                    } else { "".to_string() };
+                    format!("{}:{}{}",
+                            annotated_file.file.name,
+                            cm.doctest_offset_line(first_line.line_index),
+                            col)
+                } else {
+                    annotated_file.file.name.to_string()
+                };
                 buffer.append(buffer_msg_line_offset + 1,
-                              &annotated_file.file.name.to_string(),
+                              &loc,
                               Style::LineAndColumn);
                 for _ in 0..max_line_num_len {
                     buffer.prepend(buffer_msg_line_offset + 1, " ", Style::NoStyle);
diff --git a/src/librustc_errors/snippet.rs b/src/librustc_errors/snippet.rs
index c2f4701999e..6035f33c822 100644
--- a/src/librustc_errors/snippet.rs
+++ b/src/librustc_errors/snippet.rs
@@ -27,7 +27,8 @@ pub struct FileInfo {
 
     /// The "primary file", if any, gets a `-->` marker instead of
     /// `>>>`, and has a line-number/column printed and not just a
-    /// filename.  It appears first in the listing. It is known to
+    /// filename (other files are not guaranteed to have line numbers
+    /// or columns). It appears first in the listing. It is known to
     /// contain at least one primary span, though primary spans (which
     /// are designated with `^^^`) may also occur in other files.
     primary_span: Option<Span>,