Skip to content

Commit 5f77a47

Browse files
Work around invalid spans in imported FileMaps
1 parent f9a7bc5 commit 5f77a47

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/librustc/middle/astencode.rs

+15
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,27 @@ impl<'a, 'b, 'tcx> DecodeContext<'a, 'b, 'tcx> {
235235
pub fn tr_span(&self, span: Span) -> Span {
236236
let imported_filemaps = &self.cdata.codemap_import_info[..];
237237

238+
let span = if span.lo > span.hi {
239+
// Currently macro expansion sometimes produces invalid Span values
240+
// where lo > hi. In order not to crash the compiler when trying to
241+
// translate these values, let's transform them into something we
242+
// can handle (and which will produce useful debug locations at
243+
// least some of the time).
244+
// This workaround is only necessary as long as macro expansion is
245+
// not fixed. FIXME(#23480)
246+
codemap::mk_sp(span.lo, span.lo)
247+
} else {
248+
span
249+
};
250+
238251
let filemap_index = {
239252
// Optimize for the case that most spans within a translated item
240253
// originate from the same filemap.
241254
let last_filemap_index = self.last_filemap_index.get();
242255

243256
if span.lo >= imported_filemaps[last_filemap_index].original_start_pos &&
257+
span.lo <= imported_filemaps[last_filemap_index].original_end_pos &&
258+
span.hi >= imported_filemaps[last_filemap_index].original_start_pos &&
244259
span.hi <= imported_filemaps[last_filemap_index].original_end_pos {
245260
last_filemap_index
246261
} else {

0 commit comments

Comments
 (0)