diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index f820ea4c5e1..fc4d39ac482 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -131,7 +131,7 @@ impl EmitterWriter { } } - fn preprocess_annotations(&self, msp: &MultiSpan) -> Vec { + fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec { fn add_annotation_to_file(file_vec: &mut Vec, file: Rc, line_index: usize, @@ -175,6 +175,9 @@ impl EmitterWriter { 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); diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 545a485732e..a2a20424d6b 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -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; 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 { diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 9779a678845..fb78b18b898 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -559,7 +559,7 @@ impl CodeMapper for CodeMap { } 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 { diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index d6adf45e68a..9e545b81390 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -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 @@ impl FileMap { } 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 {