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:
parent
dd6e8d45e1
commit
3bef085ea8
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user