about summary refs log tree commit diff
path: root/src/libsyntax/codemap.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-05 20:07:59 -0700
committerbors <bors@rust-lang.org>2013-08-05 20:07:59 -0700
commit6f88f4dea559157c690688721cff6761172db6c3 (patch)
tree71201a7b0f442ebec6be0987f75f5414d803cc1c /src/libsyntax/codemap.rs
parentbbda3fa9383dba653b20bd064102caceef91897a (diff)
parent118158729ec694e6d21d94b5a51a7cbb57d9a37a (diff)
downloadrust-6f88f4dea559157c690688721cff6761172db6c3.tar.gz
rust-6f88f4dea559157c690688721cff6761172db6c3.zip
auto merge of #8278 : cmr/rust/workaround, r=brson
Diffstat (limited to 'src/libsyntax/codemap.rs')
-rw-r--r--src/libsyntax/codemap.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 0da424ce54c..8c70f128d9a 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 {