syntax: Make codemap::get_filemap() return an Option

This is more idiomatic, putting the caller in charge of whether or not
to panic.
This commit is contained in:
Kamal Marhubi 2016-05-24 16:08:01 +02:00
parent dd6e8d45e1
commit 3bef085ea8
2 changed files with 4 additions and 3 deletions

View File

@ -757,6 +757,7 @@ fn get_source(input: &Input, sess: &Session) -> (Vec<u8>, String) {
let src_name = driver::source_name(input);
let src = sess.codemap()
.get_filemap(&src_name)
.unwrap()
.src
.as_ref()
.unwrap()

View File

@ -1191,13 +1191,13 @@ pub fn span_to_snippet(&self, sp: Span) -> Result<String, SpanSnippetError> {
}
}
pub fn get_filemap(&self, filename: &str) -> Rc<FileMap> {
pub fn get_filemap(&self, filename: &str) -> Option<Rc<FileMap>> {
for fm in self.files.borrow().iter() {
if filename == fm.name {
return fm.clone();
return Some(fm.clone());
}
}
panic!("asking for {} which we don't know about", filename);
None
}
/// For a global BytePos compute the local offset within the containing FileMap