Skip to content

Commit

Permalink
Work around invalid spans in imported FileMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Mar 18, 2015
1 parent f9a7bc5 commit 5f77a47
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/librustc/middle/astencode.rs
Expand Up @@ -235,12 +235,27 @@ impl<'a, 'b, 'tcx> DecodeContext<'a, 'b, 'tcx> {
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 {
Expand Down

0 comments on commit 5f77a47

Please sign in to comment.