]> git.lizzy.rs Git - rust.git/commitdiff
Work around #8256, do not fail the task, just return None
authorCorey Richardson <corey@octayn.net>
Sun, 4 Aug 2013 02:14:01 +0000 (22:14 -0400)
committerCorey Richardson <corey@octayn.net>
Sun, 4 Aug 2013 02:36:48 +0000 (22:36 -0400)
src/librustc/middle/resolve.rs
src/libsyntax/codemap.rs

index 5a70f251aca461aa8726fac7193ab9463cf92ef8..cb2da855c22b7aa59a190a97024201df9577fd62 100644 (file)
@@ -3097,7 +3097,7 @@ pub fn report_unresolved_imports(@mut self, module_: @mut Module) {
         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 {
index 04b9fdce666e81a0bb8ec0e69a93ec80bef0d206..203341790ff91e460f62ea33c65bfaaf63bbfc9f 100644 (file)
@@ -369,12 +369,19 @@ pub fn span_to_lines(&self, sp: span) -> @FileLines {
         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 {