about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2013-08-03 22:14:01 -0400
committerCorey Richardson <corey@octayn.net>2013-08-03 22:36:48 -0400
commit118158729ec694e6d21d94b5a51a7cbb57d9a37a (patch)
tree4492b9c3fa166d1f9f24d9ec4496d3bf6b5ea955
parent8ce953347c2bbe00fb843e04b7e60d86e79213e3 (diff)
downloadrust-118158729ec694e6d21d94b5a51a7cbb57d9a37a.tar.gz
rust-118158729ec694e6d21d94b5a51a7cbb57d9a37a.zip
Work around #8256, do not fail the task, just return None
-rw-r--r--src/librustc/middle/resolve.rs2
-rw-r--r--src/libsyntax/codemap.rs15
2 files changed, 12 insertions, 5 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index 5a70f251aca..cb2da855c22 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -3097,7 +3097,7 @@ impl Resolver {
         let imports: &mut ~[@ImportDirective] = &mut *module_.imports;
         let import_count = imports.len();
         if index != import_count {
-            let sn = self.session.codemap.span_to_snippet(imports[index].span);
+            let sn = self.session.codemap.span_to_snippet(imports[index].span).unwrap();
             if sn.contains("::") {
                 self.session.span_err(imports[index].span, "unresolved import");
             } else {
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 04b9fdce666..203341790ff 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -369,12 +369,19 @@ impl CodeMap {
         return @FileLines {file: lo.file, lines: lines};
     }
 
-    pub fn span_to_snippet(&self, sp: span) -> ~str {
+    pub fn span_to_snippet(&self, sp: span) -> Option<~str> {
         let begin = self.lookup_byte_offset(sp.lo);
         let end = self.lookup_byte_offset(sp.hi);
-        assert_eq!(begin.fm.start_pos, end.fm.start_pos);
-        return begin.fm.src.slice(
-                          begin.pos.to_uint(), end.pos.to_uint()).to_owned();
+
+        // FIXME #8256: this used to be an assert but whatever precondition
+        // it's testing isn't true for all spans in the AST, so to allow the
+        // caller to not have to fail (and it can't catch it since the CodeMap
+        // isn't sendable), return None
+        if begin.fm.start_pos != end.fm.start_pos {
+            None
+        } else {
+            Some(begin.fm.src.slice( begin.pos.to_uint(), end.pos.to_uint()).to_owned())
+        }
     }
 
     pub fn get_filemap(&self, filename: &str) -> @FileMap {