]> git.lizzy.rs Git - rust.git/commitdiff
Improved lazy external source loading and inserted calls.
authorInokentiy Babushkin <twk@twki.de>
Sun, 11 Jun 2017 08:19:46 +0000 (10:19 +0200)
committerInokentiy Babushkin <twk@twki.de>
Sun, 11 Jun 2017 09:47:00 +0000 (11:47 +0200)
src/librustc_errors/emitter.rs
src/librustc_errors/lib.rs
src/libsyntax/codemap.rs
src/libsyntax_pos/lib.rs

index f820ea4c5e17827e9da683548844bd845d8009ec..fc4d39ac482d9637cb08b98d964de12f3f683590 100644 (file)
@@ -131,7 +131,7 @@ pub fn new(dst: Box<Write + Send>, code_map: Option<Rc<CodeMapper>>) -> EmitterW
         }
     }
 
-    fn preprocess_annotations(&self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
+    fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
         fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
                                   file: Rc<FileMap>,
                                   line_index: usize,
@@ -175,6 +175,9 @@ fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
                 if span_label.span == DUMMY_SP {
                     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);
 
index 545a485732e075698b0b19ac19fe0becb59039be..a2a20424d6b4dece0e58ed4999bba553b8d83349 100644 (file)
@@ -103,7 +103,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(&mut self, file: FileName) -> bool;
+    fn load_source_for_filemap(&self, file: FileName) -> bool;
 }
 
 impl CodeSuggestion {
index 9779a6788453d1c95876862c5bb89f7e9a2506f0..fb78b18b89819c791845884118ff85d183250e7b 100644 (file)
@@ -559,7 +559,7 @@ fn call_span_if_macro(&self, sp: Span) -> Span {
         }
         sp
     }
-    fn load_source_for_filemap(&mut self, filename: FileName) -> bool {
+    fn load_source_for_filemap(&self, filename: FileName) -> bool {
         let file_map = if let Some(fm) = self.get_filemap(&filename) {
             fm
         } else {
index d6adf45e68a2f8465ef112d19f2c359e5c6acfc8..9e545b81390591acee6d0b7368929e304275dea9 100644 (file)
@@ -374,14 +374,35 @@ pub struct MultiByteChar {
     pub bytes: usize,
 }
 
+/// The state of the lazy external source loading mechanism of a FileMap.
 #[derive(PartialEq, Eq, Clone)]
 pub enum ExternalSource {
+    /// The external source has been loaded already.
     Present(String),
+    /// No attempt has been made to load the external source.
     AbsentOk,
+    /// A failed attempt has been made to load the external source.
     AbsentErr,
+    /// No external source has to be loaded, since the FileMap represents a local crate.
     Unneeded,
 }
 
+impl ExternalSource {
+    pub fn is_absent(&self) -> bool {
+        match *self {
+            ExternalSource::Present(_) => false,
+            _ => true,
+        }
+    }
+
+    pub fn get_source(&self) -> Option<&str> {
+        match *self {
+            ExternalSource::Present(ref src) => Some(src),
+            _ => None,
+        }
+    }
+}
+
 /// A single source in the CodeMap.
 #[derive(Clone)]
 pub struct FileMap {
@@ -620,7 +641,7 @@ pub fn is_real_file(&self) -> bool {
     }
 
     pub fn is_imported(&self) -> bool {
-        self.src.is_none()
+        self.src.is_none() // TODO: change to something more sensible
     }
 
     pub fn byte_length(&self) -> u32 {