summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-01-30 17:10:54 +0800
committerGitHub <noreply@github.com>2018-01-30 17:10:54 +0800
commit44b964147e8bed485ff5993e86f8e32a5c915489 (patch)
treef098d25452fff0b58de440222c7e3d9a006733dd /src/librustc_errors
parent4dbfc8ddbfd091aefa4b0af674b6625378ce34fe (diff)
parenta21b7b3b162932011b83f4703fb87030c216e962 (diff)
downloadrust-44b964147e8bed485ff5993e86f8e32a5c915489.tar.gz
rust-44b964147e8bed485ff5993e86f8e32a5c915489.zip
Rollup merge of #47780 - varkor:cross-file-errors-line-col, r=estebank
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.rs15
-rw-r--r--src/librustc_errors/snippet.rs3
2 files changed, 16 insertions, 2 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 8a4fd24a29b..ffb5efd93ed 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -1014,8 +1014,21 @@ 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>,