about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_errors/emitter.rs9
-rw-r--r--src/librustc_errors/lib.rs4
-rw-r--r--src/libsyntax/codemap.rs16
-rw-r--r--src/libsyntax_pos/lib.rs35
4 files changed, 28 insertions, 36 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 2099725c48a..b4b14328b3d 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -177,8 +177,6 @@ impl EmitterWriter {
                     continue;
                 }
 
-                cm.load_source_for_filemap(cm.span_to_filename(span_label.span));
-
                 let lo = cm.lookup_char_pos(span_label.span.lo);
                 let mut hi = cm.lookup_char_pos(span_label.span.hi);
 
@@ -891,10 +889,10 @@ impl EmitterWriter {
         let mut annotated_files = self.preprocess_annotations(msp);
 
         // Make sure our primary file comes first
-        let primary_lo = if let (Some(ref cm), Some(ref primary_span)) =
+        let (primary_lo, cm) = if let (Some(cm), Some(ref primary_span)) =
             (self.cm.as_ref(), msp.primary_span().as_ref()) {
             if primary_span != &&DUMMY_SP {
-                cm.lookup_char_pos(primary_span.lo)
+                (cm.lookup_char_pos(primary_span.lo), cm)
             } else {
                 emit_to_destination(&buffer.render(), level, &mut self.dst)?;
                 return Ok(());
@@ -912,8 +910,7 @@ impl EmitterWriter {
         // Print out the annotate source lines that correspond with the error
         for annotated_file in annotated_files {
             // we can't annotate anything if the source is unavailable.
-            if annotated_file.file.src.is_none()
-                    && annotated_file.file.external_src.borrow().is_absent() {
+            if !cm.ensure_filemap_source_present(annotated_file.file.clone()) {
                 continue;
             }
 
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index 26ecbe724f8..975b720276e 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -50,7 +50,7 @@ pub mod registry;
 pub mod styled_buffer;
 mod lock;
 
-use syntax_pos::{BytePos, Loc, FileLinesResult, FileName, MultiSpan, Span, NO_EXPANSION};
+use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION};
 
 #[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
 pub enum RenderSpan {
@@ -104,7 +104,7 @@ pub trait CodeMapper {
     fn span_to_filename(&self, sp: Span) -> FileName;
     fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
     fn call_span_if_macro(&self, sp: Span) -> Span;
-    fn load_source_for_filemap(&self, file: FileName) -> bool;
+    fn ensure_filemap_source_present(&self, file_map: Rc<FileMap>) -> bool;
 }
 
 impl CodeSuggestion {
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 7267f510a49..5b10139cd19 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -559,19 +559,9 @@ impl CodeMapper for CodeMap {
         }
         sp
     }
-    fn load_source_for_filemap(&self, filename: FileName) -> bool {
-        let file_map = if let Some(fm) = self.get_filemap(&filename) {
-            fm
-        } else {
-            return false;
-        };
-
-        if *file_map.external_src.borrow() == ExternalSource::AbsentOk {
-            let src = self.file_loader.read_file(Path::new(&filename)).ok();
-            return file_map.add_external_src(src);
-        }
-
-        false
+    fn ensure_filemap_source_present(&self, file_map: Rc<FileMap>) -> bool {
+        let src = self.file_loader.read_file(Path::new(&file_map.name)).ok();
+        return file_map.add_external_src(src)
     }
 }
 
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index 719c25e2410..94656b3aea7 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -604,28 +604,33 @@ impl FileMap {
         lines.push(pos);
     }
 
-    /// add externally loaded source.
-    /// if the hash of the input doesn't match or no input is supplied via None,
+    /// Add externally loaded source.
+    /// If the hash of the input doesn't match or no input is supplied via None,
     /// it is interpreted as an error and the corresponding enum variant is set.
+    /// The return value signifies whether some kind of source is present.
     pub fn add_external_src(&self, src: Option<String>) -> bool {
-        let mut external_src = self.external_src.borrow_mut();
-        if let Some(src) = src {
-            let mut hasher: StableHasher<u128> = StableHasher::new();
-            hasher.write(src.as_bytes());
-
-            if hasher.finish() == self.src_hash {
-                *external_src = ExternalSource::Present(src);
-                return true;
+        if *self.external_src.borrow() == ExternalSource::AbsentOk {
+            let mut external_src = self.external_src.borrow_mut();
+            if let Some(src) = src {
+                let mut hasher: StableHasher<u128> = StableHasher::new();
+                hasher.write(src.as_bytes());
+
+                if hasher.finish() == self.src_hash {
+                    *external_src = ExternalSource::Present(src);
+                    return true;
+                }
+            } else {
+                *external_src = ExternalSource::AbsentErr;
             }
+
+            false
         } else {
-            *external_src = ExternalSource::AbsentErr;
+            self.src.is_some() || self.external_src.borrow().get_source().is_some()
         }
-
-        false
     }
 
-    /// get a line from the list of pre-computed line-beginnings.
-    /// line-number here is 0-based.
+    /// Get a line from the list of pre-computed line-beginnings.
+    /// The line number here is 0-based.
     pub fn get_line(&self, line_number: usize) -> Option<Cow<str>> {
         fn get_until_newline(src: &str, begin: usize) -> &str {
             // We can't use `lines.get(line_number+1)` because we might