Skip to content

Commit c04aa4e

Browse files
committed
Improved lazy external source loading and inserted calls.
1 parent c2c31b2 commit c04aa4e

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/librustc_errors/emitter.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl EmitterWriter {
131131
}
132132
}
133133

134-
fn preprocess_annotations(&self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
134+
fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
135135
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
136136
file: Rc<FileMap>,
137137
line_index: usize,
@@ -175,6 +175,9 @@ impl EmitterWriter {
175175
if span_label.span == DUMMY_SP {
176176
continue;
177177
}
178+
179+
cm.load_source_for_filemap(cm.span_to_filename(span_label.span));
180+
178181
let lo = cm.lookup_char_pos(span_label.span.lo);
179182
let mut hi = cm.lookup_char_pos(span_label.span.hi);
180183

src/librustc_errors/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub trait CodeMapper {
103103
fn span_to_filename(&self, sp: Span) -> FileName;
104104
fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
105105
fn call_span_if_macro(&self, sp: Span) -> Span;
106-
fn load_source_for_filemap(&mut self, file: FileName) -> bool;
106+
fn load_source_for_filemap(&self, file: FileName) -> bool;
107107
}
108108

109109
impl CodeSuggestion {

src/libsyntax/codemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl CodeMapper for CodeMap {
559559
}
560560
sp
561561
}
562-
fn load_source_for_filemap(&mut self, filename: FileName) -> bool {
562+
fn load_source_for_filemap(&self, filename: FileName) -> bool {
563563
let file_map = if let Some(fm) = self.get_filemap(&filename) {
564564
fm
565565
} else {

src/libsyntax_pos/lib.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,35 @@ pub struct MultiByteChar {
374374
pub bytes: usize,
375375
}
376376

377+
/// The state of the lazy external source loading mechanism of a FileMap.
377378
#[derive(PartialEq, Eq, Clone)]
378379
pub enum ExternalSource {
380+
/// The external source has been loaded already.
379381
Present(String),
382+
/// No attempt has been made to load the external source.
380383
AbsentOk,
384+
/// A failed attempt has been made to load the external source.
381385
AbsentErr,
386+
/// No external source has to be loaded, since the FileMap represents a local crate.
382387
Unneeded,
383388
}
384389

390+
impl ExternalSource {
391+
pub fn is_absent(&self) -> bool {
392+
match *self {
393+
ExternalSource::Present(_) => false,
394+
_ => true,
395+
}
396+
}
397+
398+
pub fn get_source(&self) -> Option<&str> {
399+
match *self {
400+
ExternalSource::Present(ref src) => Some(src),
401+
_ => None,
402+
}
403+
}
404+
}
405+
385406
/// A single source in the CodeMap.
386407
#[derive(Clone)]
387408
pub struct FileMap {
@@ -620,7 +641,7 @@ impl FileMap {
620641
}
621642

622643
pub fn is_imported(&self) -> bool {
623-
self.src.is_none()
644+
self.src.is_none() // TODO: change to something more sensible
624645
}
625646

626647
pub fn byte_length(&self) -> u32 {

0 commit comments

Comments
 (0)