]> git.lizzy.rs Git - rust.git/commitdiff
Work around invalid spans in imported FileMaps
authorMichael Woerister <michaelwoerister@posteo>
Wed, 18 Mar 2015 16:02:34 +0000 (17:02 +0100)
committerMichael Woerister <michaelwoerister@posteo>
Wed, 18 Mar 2015 21:05:01 +0000 (22:05 +0100)
src/librustc/middle/astencode.rs

index f7210728bb480099731fad7eb7c999007705179f..8b2a94025f337441a3fa44b86d7e9d4dd549b228 100644 (file)
@@ -235,12 +235,27 @@ pub fn tr_intern_def_id(&self, did: ast::DefId) -> ast::DefId {
     pub fn tr_span(&self, span: Span) -> Span {
         let imported_filemaps = &self.cdata.codemap_import_info[..];
 
+        let span = if span.lo > span.hi {
+            // Currently macro expansion sometimes produces invalid Span values
+            // where lo > hi. In order not to crash the compiler when trying to
+            // translate these values, let's transform them into something we
+            // can handle (and which will produce useful debug locations at
+            // least some of the time).
+            // This workaround is only necessary as long as macro expansion is
+            // not fixed. FIXME(#23480)
+            codemap::mk_sp(span.lo, span.lo)
+        } else {
+            span
+        };
+
         let filemap_index = {
             // Optimize for the case that most spans within a translated item
             // originate from the same filemap.
             let last_filemap_index = self.last_filemap_index.get();
 
             if span.lo >= imported_filemaps[last_filemap_index].original_start_pos &&
+               span.lo <= imported_filemaps[last_filemap_index].original_end_pos &&
+               span.hi >= imported_filemaps[last_filemap_index].original_start_pos &&
                span.hi <= imported_filemaps[last_filemap_index].original_end_pos {
                 last_filemap_index
             } else {