Added external crates' sources to FileMap.

They are now handled in their own member to prevent mutating access to
the `src` member. This way, we can safely load external sources, while
keeping the mutation of local source strings off-limits.
This commit is contained in:
Inokentiy Babushkin
2017-06-10 21:08:32 +02:00
parent dd8f7cd126
commit c2c31b2db3
4 changed files with 35 additions and 0 deletions

View File

@@ -219,6 +219,7 @@ impl CodeMap {
crate_of_origin: crate_of_origin,
src: None,
src_hash: src_hash,
external_src: RefCell::new(ExternalSource::AbsentOk),
start_pos: start_pos,
end_pos: end_pos,
lines: RefCell::new(file_local_lines),
@@ -558,6 +559,25 @@ impl CodeMapper for CodeMap {
}
sp
}
fn load_source_for_filemap(&mut 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 mut external_src = file_map.external_src.borrow_mut();
if let Ok(src) = self.file_loader.read_file(Path::new(&filename)) {
*external_src = ExternalSource::Present(src);
return true;
} else {
*external_src = ExternalSource::AbsentErr;
}
}
false
}
}
#[derive(Clone)]