From 3bef085ea8da749c234fb4afc749810a5b9c6c16 Mon Sep 17 00:00:00 2001 From: Kamal Marhubi Date: Tue, 24 May 2016 16:08:01 +0200 Subject: [PATCH] syntax: Make codemap::get_filemap() return an Option This is more idiomatic, putting the caller in charge of whether or not to panic. --- src/librustc_driver/pretty.rs | 1 + src/libsyntax/codemap.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 8c84e561e31..0a093887c50 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -757,6 +757,7 @@ fn get_source(input: &Input, sess: &Session) -> (Vec, String) { let src_name = driver::source_name(input); let src = sess.codemap() .get_filemap(&src_name) + .unwrap() .src .as_ref() .unwrap() diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index ca8708fdc83..3b13bf2fc50 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -1191,13 +1191,13 @@ impl CodeMap { } } - pub fn get_filemap(&self, filename: &str) -> Rc { + pub fn get_filemap(&self, filename: &str) -> Option> { 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